Error: I'm afraid this is the first I've heard of a "trackback" flavoured Blosxom. Try dropping the "/+trackback" bit from the end of the URL.

Sat, 16 Aug 2008

GParted LiveDisc and vmware-vdiskmanager

I used VMWare Workstation on the old laptop, sophia, but I want VMWare Server on the new one, ykchaua, so I'm not going to migrate the license. Server allows functionality I need (like multiple guests running at the same time) but it doesn't support some features of Workstation, in particular multiple snapshots.

The XP guest image that I migrated over from sophia had some old snapshots, so it was taking up 37 Gigs of space to provide 10 Gigs of usable disk. And 10 Gigs had gotten a bit tight. (My first ever hard drive held 20 Megabytes.)

Rather than push everything back to sophia and clean out the backups, then pull everything back to ykchaua, I googled and found some tricks that let me do the cleanup at drive speeds rather than network speeds. And I was able to expand the virtual disk, too.

  1. Back up all the guest files to another directory.
  2. Verify the guest can be booted in vmware from the new location.
  3. Identify the .vmdk file that is the head of the latest snapshot. It's visible but grayed out in the settings for the guest in the vmware console.
  4. Run as root
    vmware-vdiskmanager -r snapshothead.vmdk -t3 newname.vmdk
    Use quotation marks around the names if they have spaces in them.
  5. Go into the vmware console, bring up the settings for this guest and remove the existing 'hard disk'. Note any settings like "IDE 0/0" before you do the remove.
  6. Create a new hard disk using the newname.vmdk file and the same settings as the previous disk.
  7. Verify that the guest is bootable with the new 'drive'.
  8. Delete all of the local copies of the old vmdk files and files with Snapshot in their names. Also remove the *.vmsd file, since there is no longer a snapshot chain.
  9. Verify that the guest is bootable.
  10. Delete the copy of the old guest configuration from the backup location.

This brought the disk usage from 37 Gigs down to 10 by way of a process where maximum disk usage was 84 gigs. Obviously some planning (and possibly an external drive) is needed when doing this.

Increasing the size of the virtual disk was comparatively straightforward, but it required an additinal (and very neat) tool.

I downloaded the GParted Live Disk from its site. This is a tiny iso image that will fit on a credit-card sized cdrom, or a regular cdrom. There are optional versions for usb drives available too. Vmware has a handy feature of being able to treat an iso file as a virtual cdrom, so I didn't need to burn a disk.

This Live CD is not configured as an operating system, it comes up as a partition manager tool. And because it does not boot from your usual system drive, it is easy for it to resize a system partition. To increase the size of my virtual disk I used the following steps.

  1. Copy the vmdk files to the backup space
  2. Run the following command.
    vmware-vdiskmanager -x <new>GB myDisk.vmdk
    where <new> is the new total size for the virtual disk. Use quotation marks around the vmdk name if it has spaces in it.
  3. Verify that the guest boots with the modified disk file.
  4. Shutdown the guest.
  5. In the guest settings, swich the CDROM to use the Gparted iso instead of the physical drive.
  6. Restart the guest. As it comes up, very quickly hit the F2 key.
  7. Tab over to Boot, move cdrom higher in the list than the harddisk. Save the changes and quit.
  8. Boot the guest.
  9. Accept all the GParted defaults until it shows you a display of your drive partitions.
  10. Click on the partition you want to grow to highlight it.
  11. Click the Resize/Move button
  12. On the Resize/Move Popup, drag the right handle on the partition image as far tothe right as it will go and click Resize/Move.
  13. Click the Apply button, and select OK in the verification window, and wait a few seconds while the resize is completed.
  14. Close the operations window.
  15. Bring up the guest settings in the vmware console and set the CDROM back to the physical device. It will complain that it can't find the device. Tell it OK, and to scan for the device everytime it boots.
  16. Exit from GParted. The big red Exit button did not seem to work. Right clicking on the desktop and selecting 'Exit/shutdown menu' worked once for me, but there is nothing open on the 'hard drive' so it is also safe to just shutdown the guest. It may complain about not finding the cdrom drive: just click OK.
  17. Restart the guest.
  18. If the guest is a Windows image, it will scan the disk for problems after boot, and after you log in it will say that it needs to reboot to record the new configuration. Let it.
  19. Verify that the new disk size is visible inside the guest.
  20. Delete the obsolete vmdk files from the backup space.
  21. #