Skip to main content

Expanding the Size of Disk Volume on a Hyper-V Linux Guest.

Oh no I've run out of space on my Linux Guest

If you're a Microsoft specialist and you've been setting up Hyper-V servers with Windows Guests then your more than likely come across the scenario of running out of disk space on your virtual guests. Now for Windows guests the task of expanding the virtual guests disk size is pretty easy but if you need help with that see my other hub - How to increase the size of my Hyper-V Windows Guest Disk.

Now you may have decided to run a couple of Linux systems on your Hyper-V host and because they work quite well you've also run out of space on one of those too. So how on earth do we increase the disk space on one of these machines.

Hyper-V Edit Disk Menu


Expanding the Virtual Hard Disk (VHD) File

Our first step is obviously to increase the size of the VHD File for that particular Linux Guest, just like you would if it were a Windows Guest. Make sure you shut down the Linux Guest before you start and I would advise taking a copy of the VHD file before we begin as a backup.

Next open up your Hyper-V manager and click on Edit Disk on the right hand side under Actions. On the Welcome screen just click next then click the Browse button and find your VHD file for your Linux Guest. Click next again and choose Expand from the 3 options and click next. Now you want to enter the new size that you would like to make the hard disk. Click next when you are done and confirm the summary details are correct and click finish.

Now you're going to need to wait while the VHD file is Expanded this can take quite some time depending on how much bigger you have made the disk.

Linux LVM Partitions in CFDISK


Extending the Extended Partition and adding a Logical Partition

Confused yet, well I was until I found this great tool called cfdisk which makes this job a lot easier. So now that you've expanded the VHD file you can boot the Linux Guest again and log in. Next we are going to use a program called cfdisk, now your server may not have this yet so you'll have to install it with either YUM or APT-GET.

Now that CFDISK is installed we simply type
cfdisk /dev/hda
cfdisk /dev/sda
Depending on your Linux Distribution.

You will then be presented with a screen similar to the image above.
You should see the space that you just added to the VHD file as Free Space at the end of your Disk. Now what we want to do is add a new Logical Partition to the HDA/SDA disk. So use the cursor to highlight the Free Space at the bottom of the list and choose New from the bottom menu. Next choose Logical for the partition type and enter the size you would like to make it then press enter. This will create a new logical partition with the File System type of Linux, next we need to change this to a Linux LVM File System Type. So choose Type from the bottom menu, press enter to continue, then enter 8e as the Filesystem Type. Next we just need to write the new Partition Table out, so choose Write from the Menu and confirm.

Linux LVDISPLAY Command Results


Increasing the LVM Logical Volume Size

Now that we have increased the size of our Virtual Hard Disk (VHD), we have created a new Logical Partition to store the data on, our last step is to expand the LVM Volume.

First we need to initialize the new Physical Volume for use with LVM by using this command
pvcreate /dev/hda? (? is whatever number you created using the CFDISK tool) or
pvcreate /dev/sda?

Next we need to run

This will give you an output similar to the picture above. From this we need to get the VG Name of the volume you need to add the space to, i.e. web2 in my case. To add the new partition to the Volume Group simply run the following command

vgextend web2 /dev/hda? (where WEB2 is your VG Name and ? is the Partition you created earlier)

Next we need to add the new partition space to the Logical Volume. Most people will want to add this to the Root LV but you may also have a Home LV. To do this we run the following command

lvresize -l +100%FREE /dev/web2/root (where /dev/web2/root is the LV Name of the volume you want to increase)

Linux DF -H Command


Online Expansion of Linux File System

Well if you've made it to this step congratulations, this final step involves expanding the Linux File System to make use of the new free space we just added. This can be run safely even while the machine is booted. Simply type the following command to perform the online resize.

Scroll to Continue

resize2fs /dev/web2/root (where /dev/web2/root is your LV Name from the previous section)

Lastly you can run a DF -H command to view your new free space (see the image above)

Thanks for reading my post and as always if you have any issues feel free to leave a comment or contact me through my webpage One IT - IT Services and I'll help you out.


Luke on April 07, 2016:

Hi there,

Thank you very much for the guide. Had been going well up until I had to do the lvdisplay. I type the command, but nothing shows - just goes to the next line in the terminal. Do you have any clues as to what I need to do to get the info required to move forward?

I am running ubuntu 15.10.

Thanks very much for your help,


mitch on March 18, 2014:

I'm a Linux noob and this was INCREDIBLY helpful. Thank you very much for your time and effort!

fyrye on October 01, 2013:

Oneit, ty for the write up and pictures.

For the rebooting issues, it depends on the linux distro.


Cuong Tran on July 10, 2013:

Thank u very much. I did it

Manuel on May 02, 2013:

THANK YOU! I was looking everywhere for easy to follow instructions. Your post was the best and easiest to follow!

Cthulhu on July 02, 2012:

It's not working for me: after expanding I get:

Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)

One IT Ltd (author) from Auckland on March 08, 2012:

I can't remember needing to reboot before I was able to run the 'pvcreate /dev/hda' command, next time I need to expand I'll make note of if it is needed.

sotheron on March 08, 2012:

Thanks for the write up. As with Mark I'm also new to the Linux world and needed to expand a disk running on Hyper-V. I tried a few other articles somehow corrupting the disk in the process, (not a huge issue when you have backups!).

Also as Mark says I had to rboot before the 'pvcreate /dev/hda?' command. I'm running ubuntu, (if it makes a difference).

Everything seems to be working okay but I did get messages saying 'Found duplicate PV......' so that's the next thing to learn....

Thanks again.

Nablus on February 23, 2012:

What tool you use to create a VHD for linux. I want to move my existing red hat 6.0 enterprise server to hyper v.

One IT Ltd (author) from Auckland on February 01, 2012:

Hi Mark, glad I was able to help. When you say you had to reboot before you could initialize the physical volume at what stage was this, after increasing the size of the VHD? I don't recall needing to do any initialization.

Mark on February 01, 2012:

Being relatively new to the Linux world this was an outstanding write-up. Except for one thing, I had to reboot before I could initialize the physical volume...not a big deal and truly made my life much easier. I didn't have to build a new server. Thanks.

Related Articles