How To Increase Root Partition Size on Ubuntu

I have an Ubuntu VM that is running low on root partition lately. And here is what I did to increase it without reinstalling the system.

First, expand the virtual disk to get more space ready for the system.

Once the system boots up, turn off swap.

sudo swapoff /dev/sda5

Fire up cfdisk, then

  • Use Delete to remove the logical partition (/dev/sda5) and the extended partition (/dev/sda2)
  • Use Delete to remove the primary partition (/dev/sda1) – don’t worry, the change hasn’t been written to the disk until you choose to later on.
  • Use New to create a new primary partition (/dev/sda1). Make sure the start cylinder is exactly the same as the old /dev/sda1 and the new end cylinder to include expanded space minus space you need for the swap.
  • Use to toggle the bootable flag on the new primary partition (/dev/sda1).
  • Use W to write the new partition table to the disk after reviewing the change.

Reboot (sudo reboot).

Once booted, there will be a smaller system living inside a larger partition. Use the following magic command to make the file system to take all available space.

sudo resize2fs /dev/sda1

That’s it. Hope it helps.

Leave a Reply

Your email address will not be published. Required fields are marked *