Ubuntu: How can I resize an ext root partition at runtime?


How can I increase the size of the root partition of a system at runtime?

I have a partition that is not allocated after the root partition (which is also ext4), how can I add that unallocated space to the space allocated to the root partition without having to shutdown the server?


GUI (Ubuntu 14.04 and later): GParted v0.17 and later provide a nice GUI for this. (Older versions will refuse to resize a mounted partition).

Command line (any Ubuntu version): There are three steps to this.

Step 1. The partition must first be resized. If you're using LVM, it's easy, and you presumably know how to proceed. If you're using classic partitions, it's a bit more complicated, and may require a reboot (though you never have to boot another system or live CD).

This is how I do it: Use fdisk to first delete the partition (the idea is that the data on disk will be preserved), then carefully recreate it with a larger size at the same position.


$ sudo fdisk /dev/sda    Command (m for help): p       Device Boot      Start         End      Blocks   Id  System  /dev/sda1   *        2048     9437183     4717568   83  Linux    Command (m for help): d  Selected partition 1    Command (m for help): p       Device Boot      Start         End      Blocks   Id  System    Command (m for help): n  Command action     e   extended     p   primary partition (1-4)  p  Partition number (1-4, default 1): 1  First sector (2048-10485759, default 2048):  Using default value 2048  Last sector, +sectors or +size{K,M,G} (2048-10485759, default 10485759):  Using default value 10485759    Command (m for help): p       Device Boot      Start         End      Blocks   Id  System  /dev/sda1            2048    10485759     5241856   83  Linux    Command (m for help): w  The partition table has been altered!    Calling ioctl() to re-read partition table.    WARNING: Re-reading the partition table failed with error 16: Device or resource busy.  The kernel still uses the old table. The new table will be used at  the next reboot or after you run partprobe(8) or kpartx(8)  Syncing disks.  

Again, it is critical that the new partition starts at the same block as the old. The Id should also match (83 for Linux systems). Be prepared to lose all your data at the slightest typo.

To be on the safe side, you may also restore the boot flag (which according to Wikipedia is still required on some computers) by pressing a.

See the comment section for what to do if your swap partition is in the way.

By now it should be apparent why people recommend using a live CD. ;-)

Step 2. As fdisk helpfully reminds you, you must reload the partition table before proceeding. The safest way is to simply reboot; but you can also use partprobe or kpartx (more information).

Step 3. Once the partition is resized and the partition table reloaded, it's a simple matter of running resize2fs on the file system, and you can do this even when it's mounted as the root partition.


$ sudo resize2fs /dev/sda1  


It is possible to do a on-line resize of a ext4 filesystem, even if it's your root partition. Use the resize2fs command.

sudo resize2fs /dev/sda1  

EDIT: On-line shrinking is not allowed:

root@brunojcm-htpc:/home# resize2fs /dev/sda5 2654693  resize2fs 1.42 (29-Nov-2011)  Filesystem at /dev/sda5 is mounted on /; on-line resizing required  resize2fs: On-line shrinking not supported  


You could also just make use of GParted - as long as the partition you are resizing is not the one you booted from - else I suggest the live CD option is somewhat easier for newbies.

GParted basically does all of the steps - just based on a GUI fronted.


Just finished resizing an ext4 root partition on a live system while the root was mount.

[root@habib i686]# resize2fs /dev/vg_habib/lv_root  resize2fs 1.42 (29-Nov-2011)  Filesystem at /dev/vg_habib/lv_root is mounted on /; on-line resizing required  old_desc_blocks = 4, new_desc_blocks = 10  Performing an on-line resize of /dev/vg_habib/lv_root to 38427648 (4k) blocks.  The filesystem on /dev/vg_habib/lv_root is now 38427648 blocks long.    [root@habib i686]#   


Yes, you can shrink/move/grow an online root partition without any reboots (nor livecd, nor usbkey): consult this answer. It's very well written and easy to follow, although quite long and a little risky. So if you only want to grow your ext4 partition, you can stick to the conventional working resize2fs solutions.

The general solution I've lnked will work on any type of dedicated or VPS solution for instance.

TLDR; this solution implies to pivot_root to tmpfs so you can umount safely your root partition live and fiddle with it. Once done, you'll pivot_root back on your new root partition.

This allows pretty much any manipulation on the root file system (move it, change filesystem, changing it's physical device...).

No reboot are required in the process, and this allows to bypass limitation of resize2fs not being able to shrink ext4 partitions.

I have personally used this, and it works very well on debian system also, so it should work on Ubuntu. I'm very surprised not to see this in-depth solution a little more linked to the many question in stackexchange web sites that deals with the same issue.

Note: Of course if you want to grow your partition, a simple resize2fs will be enough as stated in numerous places and in other answers here.


As stated before: -exanding live from a root system is possible.(no difficulties, as the boot section ain't to be moved)

-shrinking a live root partition needs to be done from external boot device (boot from live system cd/usb-stick), as if theres any fault, mismatch ..whatever..your system hangs, nedds to be rebooted and will eventualy not be able to boot correctly. Any sort of "but I did it and it works" is pure luck.


only you need bootable or live cd like hiren's bootcd

and this is link http://www.hirensbootcd.org/download/

burn it on cd and restart your computer choose cdrom to boot from it and open cd from menu choose parted magic 6.7
enter image description here


I was trying to resize the root partition i.e. / could not delete and create but resize2fs /dev/sda has allocated remaining free space available to the partition.

so before trying fdisking it try resize2fs , thought of sharing it as it worked for me


As noted previously works fine just need to reset boot flag

run 'parted'

parted /dev/sda  

verify partition number

(parted) print  

reset boot flag on partition number '1' in this case

(parted) set 1 boot on  (parted) quit  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »