Extending a Hard Drive Partition on Ubuntu Linux Virtual Machine

I needed to add some storage on a shell only Ubuntu Linux VM and due to having more experience with RedHat and via GUIs along with there being little information out there I thought it would be worth putting up a post for posterity.

So first step lets shut down and increase the VMDK

First Step Shut Down Guest OS

Now lets edit the VM settings

In the settings lets increase Hard Disk 1 on this VM

Lets go ahead and turn on the VM again and then we can SSH into the VM once it is back online.

(you could also take a snapshot at this point just in case)

Now onto the in-guest re partitioning bit.

First lets resize sda2 to use the extra space. On Ubuntu this is done using the command

sudo cfdisk

in here we select sda2 and then select [ Resize ] and enter the new desired size. By default it will suggest using all available space

Once this is done you will see the new size, and from here you need to [ Write ] the change and type “yes”

Now you can go ahead and [ Quit ] cfdisk

Here is another difference with RedHat, we must now run

sudo resize2fs /dev/sda2

If you run df -h you will see that /dev/sda2 is now using the increased size

And we are done. If you took a snapshot don’t forget to go ahead and remove it.