Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

EDIT : 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...

share|improve this question
    
This type of question has been asked and answered a number of times that I am aware of. Have you consulted the archives here? –  mdpc May 22 '13 at 2:00
add comment

4 Answers

up vote 4 down vote accepted

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!

share|improve this answer
    
The resize2fs man page says: If the filesystem is mounted, it can be used to expand the size of the mounted filesystem, assuming the kernel supports on-line resizing. (As of this writing, the Linux 2.6 kernel supports on-line resize for filesystems mounted using ext3 and ext4.). However, resizing a mounted filesystem is a more dangerous operation, since the kernel could easily freeze or crash while running rarely exercised code, leaving your filesystem in a bad state. –  200_success May 21 '13 at 15:12
    
True -- but you don't want to be messing around with your partition table with the filesystem mounted. That's why I started with the fs unmounted. –  Flup May 21 '13 at 15:15
add comment

parted can resize partitions and their filesystems.

share|improve this answer
    
Thanks, I was using the graphical one and it doesn't support partition resizing. I've seen the option on the cli program, but could you tell me how to use it surely without loosing data? In resize NUMBER START END, are START and END the sector numbers? How would I know that? –  mimipc May 21 '13 at 8:00
    
It is always recommended to back up your data before doing any risky operation like resizing a partition. parted supports a choice of units — for example, use the s suffix for sectors, B or GB for bytes, % for percentage of device size, and cyl for cylinders. –  200_success May 21 '13 at 8:06
add comment

You can use fdisk or cfdisk to modify (or re-create) the partition (just be sure you won't change its start boundary), then reboot and resize2fs. But in general it's preferable to use LVM-2 instead of MBR/GPT due it it allows you to bring in those changes w/o kernel rebooting.

share|improve this answer
add comment

Yes, you can grow EXT4 fs online if you have partition already sorted. Have you got partition sorted? Have you got LVM?

sudo resize2fs /dev/drive_to_grow

fdisk will resize your partition, true, but if this a root partition (or if fact any mounted partition) it will have to be unmounted first. So offline most likely!

As with anything related to disk/fs operations I strongly recommend to have backup, and tested, well understood, recovery process.

Hope that helps.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.