51

How To Resize/Grow VMware Linux Disks and Partitions


Posted by Artem Russakovskii on August 10th, 2007 in Linux
Share

Updated: January 18th, 2009

Update 01/16/2008: This method does not work for LVM partitions, as discovered in the comments.

In this article, I will show how to resize a VMware disk if you didn't make it large enough when it was created. Furthermore, I will show how to resize partitions following the disk augmentation using OpenSUSE 10.2 as an example. You will even be able to resize the Linux root partition (/) that is mounted and is normally unmountable.

The story: this is simple – you made a VMware disk without thinking ahead and now it ran out of space. Here you have a few options, the most notable ones being create another disk and mount it or grow the existing disk and resize the existing partitions. The first option is trivial, so let's explore the 2nd one.

1. Backup the existing VMware disk file by copying it somewhere safe.

2. Grow the VMware disk file (note that I'm using Windows in this step because my host system is Windows XP). In order to do this, use the 'vmware-vdiskmanager.exe' utility that comes bundled with VMware and most likely sits in C:\Program Files\VMware\VMware Workstation. If the target size of the new disk is 10GB, issue the following command:

vmware-vdiskmanager.exe -x 10Gb "YOUR_DISK.vmdk"

The disk will crunch for a bit and hopefully happiy finish with Grow: 100% done. Now the maximum disk space has been increased to 10GB. At this point, all partitions remain the same size, with a bunch of unpartitioned free space added at the end of the disk.

3. Now you can boot the guest OS (OpenSUSE 10.2 in my example) and use some magical utility to resize your partitions. In YaST, for instance, you would go to System->Partitioner. You can resize pretty much any partition that can be unmounted (unmount it beforehand and never try to repartition a mounted one). That represents a problem if you, like me, want to grow the root partition /. Still with me? Then let's go to the next step.

4.

a) In order to repartition or resize a root partition, I will use a LiveCD of another OS. Or even better, a LiveCD that lives and breathes resizing things left and right. I'm talking about the GParted Live CD from http://gparted.sourceforge.net/livecd.php. Since a LiveCD is an operating system on its own loaded into RAM, it won't need to mount any of your existing partitions. There's a bug with the latest version 0.3.4-8, which prevents GParted from seeing any partitions in VMware systems at all, but 0.3.4-5 works like a charm. Download the ISO image, right click on the CD/DVD icon in the lower right part of the VMware window and click Edit. Then change the Connection to "Use ISO image" and browse to the freshly downloaded GParted ISO. This will effectively mount the image without having to burn it onto a CD.

b) Reboot the guest OS. Quickly press F2 on the VMware preboot load screen to enter the virtual VMware BIOS. Go to the Boot tab and bring the CD-ROM drive to the top by scrolling to it and clicking + repeatedly. Now save and exit. The next time the OS tries to boot, it will first try to load the LiveCD, which is exactly what we want.

c) GParted should load after a few minutes where everything should be very straightforward. The screenshots here may help understand what I'm talking about. Fiddle with the settings, increase the root partition size, click Apply, and go have a few beers because this may take a while to finish. When it does, so are we, as we now have successfully grown the root partition.

d) Optionally revert the steps in part 4a and 4b.

5. Reboot into the guest OS again. Enjoy all the new extra space.

This concludes the article. Feel free to leave any questions or comments.

● ● ●

Artem Russakovskii is a San Francisco programmer, blogger, and future millionaire (that last part is in the works). Follow Artem on Twitter (@ArtemR) or subscribe to the RSS feed.

In the meantime, if you found this article useful, feel free to buy me a cup of coffee below.



Share
  • pY

    Thanks a lot. Very clear and concise indications on how to procede. Exactly what i was looking for.

  • http://beerpla.net Archon810

    Thank you, pY.

  • Tomslin

    Thanks for the howto.I'll like to know how I can do this with my host being linux,as i see no tool like vdiskmanager on my linux vmware install.

  • http://beerpla.net Artem Russakovskii

    Tomslin, I just installed VMWare Workstation v6.0.3 on my Linux server and the following commands became available:

    vmware vmware-authd vmware-loop vmware-ping vmware-uninstall-vix.pl vmware-vdiskmanager vmware-acetool vmware-config.pl vmware-mount.pl vmware-tray vmware-uninstall.pl

    I needed to install the kernel-source package in order to complete the installation.

    Perhaps you're using the VMWare Player, which may or may not include vmware-vdiskmanager.

  • Steven White

    Hello,

    I attempted what you've described but ran into a problem. When I boot up the LiveCD of gparted, after it boots into where my guest OS should be, gparted doesn't see any available devices.

    Is there a way to force gparted to look to the 'hard disk' that should contain my VM?

    system info…
    host OS: CentOS running VMWare server
    guest OS: Ubuntu 6.06

    My guest OS does boot properly and all apps will run across the network. Of course I didn't set aside a larger enough file system for my mail service. Which is why I'm here now.

    And I've already successfully enlarged the VM from 20GB to 40GB.

    I hope you can help.

    Cheers,
    Steven

  • http://beerpla.net Artem Russakovskii

    Steven, what gparted version are you using?

  • Steven White

    I'm using 0.3.6-7. Any known problems w/this version?

  • http://beerpla.net Artem Russakovskii

    Steven, re-read #4A again, very carefully :P

  • Roman

    Thanks a lot Artem,

    Your solution is brilliant. Worked fine for us and saved us a lot of time.

    Cheers,
    Roman

  • http://beerpla.net Artem Russakovskii

    Glad to be of service, Roman.

  • http://douglasheld.net Douglas Held

    On Mac OS X with VMWare Fusion 1.1.3, the utility is /Applications/VMWare\ Fusion.app/Contents/MacOS/diskTool , and the grow argument is big X, not little x.

    Thanks for the help, Artem.

  • Carpii

    Hi, Im struggling a bit.

    GParted shows I have an ext3 partition (label /boot) of 100 meg, followed an unknown partition.

    The unknown partition should be appearing as etx3 too, its the root partition. But gparted wont recognise it, so I cant resize it :(

    Any ideas please? Im using gparted 0.3.4-5 as instructed

    Thanks

  • http://beerpla.net Artem Russakovskii

    Carpii, I'm afraid this is not something I personally can help you with and the question is better directed at the developers in their forum: http://gparted.sourceforge.net/forum.php.

    Good luck.

  • Amski

    With VMWare Fusion (Mac), you can grow your disk size using the GUI. Select your VM machine, enter properties, select disk and resize. Of course VM machine must be shut down first (and you cannot have a snapshot attached to it).

    Also, for those of us who cannot press the F2 key fast enough during the VM machine's boot sequence to actually get BIOS instead of GRUB screen, you can edit the ".vfx" file and set "bios.bootDelay" property to some larger value. This makes VM machine wait longer at the initial boot screen, giving one more time in which to press F2.

    Artem, thanks for this write up. It was of great help :-)

  • http://beerpla.net Artem Russakovskii

    @Amski
    Thanks for the extra info for you fancy Mac people.

  • M Hahn

    Hi,

    with VMWare 2 does not bring the BIOS (at least not for me). Rather you need to select: show BIOS at boot directly from VMServer

    Cheers,
    Matthias

  • Vim Toutenhoofd

    I run Ubuntu 8.04 in a VMware Workstation virtual machine hosted by Windows XP on a ThinkPad G41. I had no luck with gparted-live-0.3.9-4.iso, which is an image of the current version of that utility. It made me wonder if that bug you referred to has not yet been fixed. I then tried the version which worked for you (gparted-livecd-0.3.4-5.iso), which indeed allowed me to enlarge the partitions on my virtual hard disk. Thanks for your article!

  • Ed

    FFS.. I have followed the instructions.. and tried it with

    gparted-live-0.3.9-4.iso
    and
    gparted-live-0.3.4-5.iso
    and a couple others…

    and neither worked. I always get unrecognized FileSystem X\

    I'm trying to run a CentOS 5.2 VM on a Mac X\

  • Michael

    Thanks for the information. Turns out that the latest version of gparted does not see VM partitions. Use the version you suggested and it works great. Once again, thank you.

  • http://beerpla.net Artem Russakovskii

    No probs, dudes.

  • Keith

    Thanks, great article which helped me fix my problem!!!

  • http://beerpla.net Artem Russakovskii

    @Carpii, Ed, and others having a problem with GParted not seeing the partition (shows unknown)

    I just tried a default CentOS installation and realized I didn't give it enough space. Booting into any version of GParted showed the / partition as "unknown".

    Well, the problem is due to CentOS making it LVM by default. According to GParted, LVM is not supported. I've yet to find a solution. :(

  • Tilman Schmidt

    You don't even need GParted with LVM. Instead, in step 3 you just use fdisk to create a new partition from the added space, pvcreate to make a PV from it, and vgextend to add it to your VG.

  • http://www.lbenitez.com luis benitez

    Sweet!!! Works like a charm.. thanks for the tip!

  • Simon Shaw

    Tilman,
    I did what you said with LVM and I can see that the volume has increased in size from 7.5GB to 11.28GB as shown below, however when I run df -h the partition that I was originally trying to remains 7.2GB. Any ideas?

    lvdisplay
    — Logical volume —
    LV Name /dev/VolGroup00/LogVol00
    VG Name VolGroup00
    LV UUID qti2mM-XkDw-LPC1-ARJv-nLAs-YcTL-4zrCuP
    LV Write Access read/write
    LV Status available
    # open 1
    LV Size 11.28 GB
    Current LE 361
    Segments 2
    Allocation inherit
    Read ahead sectors auto
    – currently set to 256
    Block device 253:0

    df -h
    Filesystem Size Used Avail Use% Mounted on
    /dev/mapper/VolGroup00-LogVol00
    7.2G 6.3G 536M 93% /
    /dev/sda1 99M 18M 77M 19% /boot
    tmpfs 744M 0 744M 0% /dev/shm
    /dev/hdc 278M 278M 0 100% /media/New

  • Taheireem

    hi,
    I followed the steps downloaded the same version of gparted LiveCD,after booting i can see inside the gparted window:
    Partition:Filesystem:Label:Size:Used;
    /dev/sda1:ext3:/boot:101MB:12MB;
    /dev/sda2:ext2:/:3.4GB:3.2GB;
    /dev/sda3:Linux-Swap: :500MB:120MB;
    unallocated:unallocated: : :–:–;

    but i cant resize the "/" partions,even this partition is unmounted.

  • Taheireem

    i think i made it ,it was LINUXSWAP partitions in the middle of /dev/sda2 and unallocated space,anyway thanks for the above procedure.

  • Vzzuv

    Thanks a lot! Great article, very helpful.

  • cmg

    @Simon Shaw (or in fact anyone who is having similar LVM difficulties): I encountered the same problems. I managed to solve the problem eventually as follows (WARNING, there may be errors here. I can't retrace my steps precisely having done everything via liveCD. You should investigate all steps, command usage, etc. yourself. I also recommend backing up your virtual disk before proceeding, it saved me a lot of tears :-) Also, some parameters [e.g. /dev/sda/, VolGroup00] may differ for you):
    1) Change size of VMWare virtual disk through the VMWare interface
    2) Start your VM from a live CD. (Press esc on boot with centOS).
    3) Use fdisk to add a new LVM partition. ('n' to create a new partition, select 'p' for primary, 3 [or whatever] for 3rd primary partition, 't' to modify partition's system id to 8e [LVM]). Not sure if the modification of the partition's system id was necessary… did it anyway just to be safe.
    4) Use pvcreate to intialise this partition for use by LVM
    $ pvcreate /dev/sda3
    5) Use vgextend to add it to your volume group
    $ vgextend VolGroup00 /dev/sda3
    # Thanks is obviously due to Tilman Schmidt for the
    # above few steps
    6) Use lvextend to extend the LV:
    $ lvextend -L20G /dev/mapper/VolGroup00-LogVol00
    # extend to 20GB
    7) Unmount and resize fsg
    $ umount /dev/mapper/VolGroup00-LogVol00
    $ resize2fs /dev/mapper/VolGroup00-LogVol00
    # after trying resize2fs I was prompted to do a filesystem check before proceeding. If this happens, do this, and try again.

    # http://tldp.org/HOWTO/LVM-HOWTO/extendlv.html for last 2 steps

    • Bart McLeod

      You saved my day!

  • Robson

    Hi

    I need to resize a Linux "/" filesystem but to reduce and recover disk space not to increase.
    The recovered disk space is to be used to create othe VMware machines on the same VMware host.
    The guest OS is Red Hat Enterprise Linux AS (v. 4 for 64-bit AMD64/Intel EM64T) the VMWare host is also Linux.
    I have read your article but dont know how to use it to reduce and use freed disk space.
    Thanks for any help

  • Muhammad Ali

    My host operating system is Windows 7, I made a VM ware image of linux os(guest os) which resides in my c drive.

    The size of the vm ware image is about 200 GB I would like to extend it to 220 Gb.

    Shall I need live cd or can I do it through vmware-vdiskmanager.exe utility.

  • Muhammad Ali

    I tried to resize the vmdk file after 24% completion received the following error.

    C:\Program Files (x86)\VMware\VMware Workstation>vmware-vdiskmanager -x 220Gb "c
    :\apps12vm\Red Hat Enterprise Linux 5.vmdk"
    Grow: 24% done.Failed to expand the disk 'c:\apps12vm\Red Hat Enterprise Linux
    5.vmdk': Unknown error (0x45d000900000001).

  • Jacques

    Hello, all seems clear enough but when i try to resize my partition Gparted stops after 1 second saying he is unable to resize (forbidden sign)
    I'm using gparted 0.5.2-9 iso and trying to resize a WS2003 ntfs partition (system). Did i something wrong ?

  • Dan

    Thank you for a good guide.
    Instead of issuing the "vmware-vdiskmanager.exe -x 10Gb "YOUR_DISK.vmdk" command its now possible to change that setting inside wmware.

  • Av8r

    Hi,

    Everything for me went fine, except the last step. After I reboot my Windows VM, in Disk Management it shows the new size for C:\ has grown from 4G to 8GB, but the hard disk C:\ in windows explorer still says 4GB.

    Am I missing something?

    Thanks

    • http://beerpla.net Artem Russakovskii

      Well, the procedure here describes a Linux partition resizing – I'm not familiar with resizing a Windows drive, but my guess would be you need to resize it in Windows as well – open up Administrative Tools in Control Panel and go to Computer Management > Disk Management.

      • Av8r

        Administrative Tools in Control Panel and go to Computer Management > Disk Management shows 8GB, on the disk image but when you right-click on the disk and go to properties, it only sees 4GB.

        The text area which lists Volume, Layout, Type, …. , Overhead is showing 4GB. Wierd??

  • Abhilash Krishnan

    Thanks much for you article. My problem was slightly different. Vmware fusion allocated around 3G for my / and 12G for my /home. I shrunk /home and resized my / to use the freed up space.

  • d ivanov

    Good one mate! Thanks a lot! Cheers!

  • netzgewitter

    Thanks a lot for that information. I was doing the same thing with an ext4 partition with linux running in a VirtualBox VM. Since I ran into a couple troubles with parted in combination with ext4 I made a detailed writeup as well:

    http://www.netzgewitter.com/2011/08/resizing-linux-partition/

  • prabhakar srinivasan

    Thanks so much! I found your explanation so concise and easy to understand. It worked like a charm. I just downloaded the Gparted Live ISO image from sourceforge website and then inside VMware I clicked on the CD icon on bottom right hand corner and selected Settings and pointed to ISO image sitting in C:\ of host Windows. Then I changed boot sequence by hitting F2 (this was tricky with timing the F2 key stroke during bootup) and then selected CD ROM as first in boot sequence. Gparted came up predicatbly with the root partition in unmounted state and I was able to right click and select Resize. Earlier to doing all this I had moved the linux swap to end of the expanded space and made the newly available space as Unallocated. This makes it easy for root partition which has EXT4 file format to expand by adding on the Unallocated space as well. A problem which was nagging me for a week is now solved….i am loving days like today :)
    (BTW..i did not need TUXBOOT which gparted-live mentions in their website as a required step)
    peace!

  • Tim

    I was stumped at part b where you press F2 to enter boot mode. You don't mention that, in VMware Player at least, you have to click inside the window before pressing F2. So 1) power on, 2) quickly click in the window, 3) F2.

  • Mirek

    Thanks! "go have a few beers because this may take a while to finish" – grrrrr, I'm sorry but I'm in work :(

    2Tim: I faced the same problem, then I clicked on the cd/dvd icon on the vmware frame again and i was on GParted starting screen :|

  • Danny

    Thanks matey. My problem was understanding how I could boot an ISO image to extend a root partition on a VMware server without starting that image. I had not realised that a VM has a BIOS available at the boot stage. Your article excellently pointed this out and job done. Awesome. There are some really cool tools out there now, especially for Linux.

  • Mauri

    Thank you, virtual disk resized. Very good guide!

  • b03tz

    Awesome article man, awesome! Used it several times…works flawless.

  • Brad

    Awesome! I have a Centos VM that I didn't think would grow as large as it has. These instructions worked exactly and I've been searching for a good method to accomplish this for weeks.

  • sue sue

    Do you know how to shrink vdisk without losing any data?

  • Pingback: Daunenjacke Kids

  • 韩香

    hi,everyone