Saturday, October 31, 2015

centos - How to extend an ext4 partition and filesystem?



I have a 400GB disk with a 320GB ext4 partition.
I would like to grow the ext4 partition to use the left space (80GB of free space).




+--------------------------------+--------+
| ext4 | Free |
+--------------------------------+--------+


How could I do this?



I've seen people using resize2fs but I don't understand if it resizes the partition.



Another solution would be to use fdisk but I don't want to delete my partition and loose data. How could I simply grow the partition without loosing any file?




Note: I'm talking about an un-mounted data partition without LVM and I have backups, but I'd like to avoid spending some time on recovery.


Answer



You must begin with the partition unmounted. If you can't unmount it (e.g. it's your root partition or something else the system needs to run), use something like System Rescue CD instead.




  1. Run parted, or gparted if you prefer a GUI, and resize the partition to use the extra space. I prefer gparted as it gives you a nice graphical representation, very similar to the one you've drawn in your question.


  2. resize2fs /dev/whatever


  3. e2fsck /dev/whatever (just to find out whether you are on the safe side)


  4. Remount your partition.





While I've never seen this fail, do back up your data first!


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...