Wednesday, January 10, 2007

Changing the Size of a VMware disk

I recently set up a VMware virtual machine using a raw image file of a production windows desktop. (Whew! That's a lot of jargon!) If you don't want to read the previous post, it was simply booting linux, running dd vs. the disk used by windows to create the image file. Then I created a blank vmware instance and edited the .vmdk file to point to my image file and to reflect the correct disk geometry.

It was very cool. But the windows disk was huge - 40 gigs, in two partitions. Most of the stuff on the second partition was data, stuff I'd want from either the linux or windows side. So I copied it to a network directory. Now I had a ~36 gig partition, mostly empty.

After running for a couple of weeks, I was confident I didn't need the original disk any more. So I dd'd it. dd if=/winderz.dd of=/dev/hdb overwrote the original with my amended copy.

Next, I used ntfsresize to shrink partition2 to 4 gigs, leaving me plenty of room to install other apps and windows-centric stuff. Ntfsresize is awesome, and easy to use, even if you go command line like I did.

./ntfsresize --info /dev/hdb5
./ntfsresize --no-action --size 4000M /dev/hdb5
./ntfsresize --size 4000M /dev/hdb5
fdisk /dev/hdb
fdisk -lu /dev/hdb


The tricky part for me was getting a new image file with the smaller partition. I used fdisk to get the info about starting and ending blocks for each partition. Then I used fdisk to delete the partition info for the logical partition where the data was, and the extended partition where the logical partition used to be. I then created a smaller extended partition, just enough for the smaller logical partition I wanted. Then I created the logical partition. The thing to remember is that fdisk doesn't delete data when it deletes partitions, just information about how the disk is set up. So the bytes were still all layed out where I left them.

Then I could dd if=/dev/hdb of=/hdb.image.dd count=<(size of desired disk/ 512) +1> bs=512

dd if=/dev/hdb of=/home/myname/winbox.dd count=16209585 bs=512

One thing that threw me for a long time was the fact that I expected fdisk to work on the image file the same way it does on a real one. Fdisk will whiine about needing to set up cylinders on hdb.image.dd - don't bother. I never managed it, and the vmware disk file will define that anyway.

I set up a new vmware machine, using custom, windows 2000 pro, ide, and defined a 0.1 size disk. Once I created the machine, I deleted the flat file and edited the vmdk file. I plugged in the cylinders, heads, etc. and the size of the disk in 512 byte blocks:

RW 16209585 FLAT "/home/myname/winbox.dd" 0

The windows VM booted, and after an ntfscheck (caused by ntfsresize) I was back in business with a reasonably sized vm.

0 Comments:

Post a Comment

<< Home