Ubuntu Linux Virtual Machine: How to extend a hard drive partition

< 1 min read
Extending a Hard Drive Partition on Ubuntu Linux Virtual Machine

I needed to add some storage on a shell only Ubuntu Linux Virtual Machine 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.

How to add storage to your Ubuntu Linux Virtual Machine

So first step lets shut down and increase the VMDK

First Step Shut Down Guest OS

Image-Virtual Machine

Now lets edit the Ubtuntu Linux Virtual Machine settings.

Image 2 1

In the settings lets increase Hard Disk 1 on this Virtual Machine.

Image 3 1

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

Image 5

(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
Image 6

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”

Image 7

Now you can go ahead and [ Quit ] cfdisk.

Here is another difference with RedHat, we must now run.

sudo resize2fs /dev/sda2
Image 8

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

Image 9

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

share
Table of Contents
Subscribe to the Xtravirt Newsletter

Receive updates from the Xtravirt team, including information on new technologies and the expert analysis of cloud trends and strategies you should know about, unsubscribe anytime using the link included in every email.

Senior Consultant