Resize a mounted Linux partition

Today I’ve learnt that a Linux partition (which is mounted) can be grown “a la brava” (means “the hard way” in Catalan) directly modifying it through Fdisk and then resizing with resize2fs. That’s it….

With my own conservative way I’d boot the machine into Gparted (A very useful small distro that boots into Gparted directly), resize the partition (unmounted), and then reboot again.

The only condition is that the partition which has to be grown is the last one. If not… things get more complicated (or not, if the last partition is a swap one, which can be erased and recreated without problems). Other condition is that particion can only be grown (not shrink).

The process it’s easy:

  • First grow the disk physically (can be a VM disk, a new bigger disk just cloned, or simply a partition that does’nt fill the entire disk).
  • With Fdisk, remove the partition.
  • Without exiting Fdisk, create a new partition. Carefully note that the first sector match the previous first sector. The last sector can be the end of the disk i.e.
  • Verify/toggle Boot flag, must be activated.
  • Save and exit. Cross your fingers and reboot.
  • Once rebooted, grow the filesystem with resize2fs.