Monday, October 15, 2007


For many Linux users, VMware has become an indispensable tool. While excellent emulation solutions, such as Wine and CrossOver Office can run selected mainstream Windows applications directly on top of Linux without virtualization or actual Windows code, only virtualization can provide perfect Windows compatibility. VMware makes the desktop computing experience complete.

However, virtual machine images of full operating system installs take up considerable hard drive space and consume more memory than emulation. And what's hardest to swallow is having to re-install Windows (or the virtualized operating system of choice) and supplemental applications in the virtual machine. If you've been using a particular operating system instance for any length of time, chances are you have a legion of files, preferences, and software you want to keep. Moreover, you may not have your original install media, or you may prefer to retain a specific version of an application rather than upgrade. You may even want to dual-boot to your existing Windows install because it has games or other packages that donÕt work as well when virtualized.

Well, little did I know that the free, end-user VMware products — VMware Player and VMware Server — can run your existing, on-the-metal Windows configuration virtualized within Linux using a technology that's really only known to users of VMware's enterprise product, ESX Server, a part of their Virtual Infrastructure 3 suite. The technology, known as RAW Device Mapping (RDM), is a virtualized SCSI device compatibility mode that enables a virtual machine to boot from a physical disk (or partition) rather than a virtual disk file. This capability has been around for a long time, but VMware has never really advertised it, and hasn't provided any wizard-like capability in VMware Player or Server to easily take advantage of it.

Here, I'm going to show you how to use it.

Creating a New Hardware Profile in Windows

Before you can virtualize your Windows XP system, add a new hardware profile so that when your existing Windows install boots up within VMware Player, its hardware profile isnÕt overwritten or corrupted by the newer, paravirtualized drivers. This way, you'll still be able to use your existing Windows configuration on the metal if you have to.

To create a new hardware profile, boot your Windows XP system, open the Control Panel (Start Button > Settings > Control Panel), double click on System, and click on the Hardware tab. Next, click on Hardware Profiles, as depicted in Figure One. Copy the default profile to a new name, such as VMware.

FIGURE ONE: The System Properties Hardware Profile screen in the Windows XP Control Panel

Optionally, set the "Hardware Profiles Selection" to a timeout value you're comfortable with (perhaps 30 seconds), or set it to "Wait until I select a hardware profile." This setting controls the Hardware Profile selection screen when Windows XP first boots. By default, screen this doesn't come up on most PCs, but since you're adding a new hardware profile to the system, you're going to get one from now on.

Remember, you never want to boot into your default profile during a virtualized session. Make sure you have enough time to select the VMware profile you just added.

Making Room On Your Disk for Linux

Presumably, you've got a PC that already dual-boots Linux and Windows, so if you do, you can skip this section entirely. If youÕve got a PC that runs Windows but doesnÕt have Linux installed, youÕre going to need to install Linux.

The easiest way to to proceed is buy a secondary hard disk, install it in your PC, and then install Linux on that new disk along with the GRUB boot loader to provide dual-boot capability. However, if you own a laptop, or have a huge hard drive with a lot of free space left, you might not be able to add a second hard disk or feel thereÕs no need to do so. In those instances, you must teclaim that unused hard drive space back to install Linux.

In the May 2007 "On The Desktop" column, I wrote about the System Rescue CD, a bootable, free CD distro designed specifically for system rescue and repair scenarios. Among the many tools you can use on that CD is ntfsresize, which enables you to reclaim unused disk sectors from a Windows NTFS filesystem and use it as free space in order to create a new partition.

Before you actually perform the resize, gather some important information. Boot with the System Rescue CD, and from the Linux bash prompt, issue the following command:

root@sysresccd /root% parted

You should get the following prompt:

GNU Parted 1.7.1
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.

At the prompt, issue this command:

(parted) print free

Disk /dev/sda: 100GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

You should then get output similar to the following:

Number Start End Size Type File system Flags
32.3kB 32.9MB 32.9MB Free Space
2 32.9MB 52.9GB 52.8GB primary ntfs boot
3 52.9GB 100GB 47.1GB Free Space
Type "p" and then Enter to print out the partition table.

In this example, my NTFS partition, which is homed on a SATA drive, is enumerated as partition 2 (sda2 in Linux device parlance, or hda2 if it was an IDE disk) is 52.9 GB, residing on a 100 GB drive; the rest of my system is allocated as free space. On your system, youÕll have different results, depending on your drive size and the size of your partition.

If your machine is a Windows-only box, and the whole drive is allocated for NTFS, you'll likely have a single sda1 partition taking up the entire disk, which looks something like this:

Number Start End Size Type File system Flags
1 32.3kB 100GB 100GB primary ntfs boot

Take note of this information, and then type q and Enter to exit parted.

Next, determine how much free space is left on that NTFS partition. Issue the following command from the SysRescCD prompt:

root@sysresccd /root% df -k /dev/sda2

Here, /dev/sda2 refers to the name of your NTFS partition Ñ it could just be /dev/sda1 or /dev/hda1 if your drive is all NTFS. On certain machines, such as Dell PCs and laptops, the first partition is used as a "utility" partition, in which case /dev/sda2 is the first operating system partition, as in the examples above. I've reclaimed my "utility" partition to minimize the number of primary partitions on the system, as you can only have four.)

You should get output similar to the following:

Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda2 51608808 33021912 18586896 64% /media/sda2

In this example, my 53 GB disk is 64 percent utilized (33 GB in use) with 19 GB remaining.

To reclaim some of the unused space on NTFS as free space by re-sizing the partition, I would issue the following command:

root@sysresccd /root% ntfsresize /dev/sda2 -s 40G

In this example, I've specified the size of the new partition to be 40 GB. You can see ntfsresize in action in Figure Two. Make sure you leave enough free space left on the NTFS partition for Windows program data and swap . (It's advantageous to boot into Windows before executing this command to offload some of your near-term storage to long term storage, such as burning your photos and MP3's and other multimedia to DVDs and cleaning them off the drive.)

FIGURE TWO: ntfsresize in action on the SystemRescueCD

After performing a resize on your NTFS drive (or skipping it entirely if you've got enough free space on a local drive to install Linux), launch parted again at the console prompt and issue the following commands:

(parted) unit s                                                         
(parted) print

You should get output similar to the following:

Disk /dev/sda: 195371567s
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number Start End Size Type File system Flags
2 64260s 103281884s 103217625s primary ntfs boot
1 103281885s 195366464s 92084580s extended
5 103281948s 107282069s 4000122s logical linux-swap
6 107282133s 107539109s 256977s logical ext3
7 107539173s 195366464s 87827292s logical ext3

Make a of the bolded value for total sectors on the disk. Write this number down, subtract 63, and write down the result. Next, issue the following two commands in parted:

(parted) unit cyl
(parted) print

You should get output similar to the following:

Disk /dev/sda: 12161cyl
Sector size (logical/physical): 512B/512B
BIOS cylinder,head,sector geometry: 12161,255,63. Each cylinder is
Partition Table: msdos

Number Start End Size Type File system Flags
2 4cyl 6428cyl 6425cyl primary ntfs boot
1 6429cyl 12160cyl 5732cyl extended
5 6429cyl 6677cyl 248cyl logical linux-swap
6 6678cyl 6693cyl 15cyl logical ext3
7 6694cyl 12160cyl 5466cyl logical ext3

Make a note of the values for cylinder, head, and sector geometry, respectively. Type a q at the parted prompt to exit.

Once you've re-sized your NTFS drive, reclaimed some disk space, and recorded your drive geometry values, go ahead and install your favorite Linux distribution on the free space.

Create and Customize the Virtual Machine Files

After installing Linux on your system, open a browser and download the vmdk and vmx files to your home directory. You can also download the files from and

Next, read in your hard disk's master boot record (MBR) and export it to a file in your home directory. Issue the following command from a terminal prompt:

root@ubuntu-laptop:~# dd if=/dev/sda \
of=$HOME/windowsxp.mbr \
bs=512 count=63

You should get output like the following, as well as a file named windowsxp.mbr.

63+0 records in
63+0 records out
32256 bytes (32 kB) copied, 0.000809041 seconds, 39.9 MB/s

Next, open windows.vmdk file with a text editor and find this part of the file:

# Extent description
RW 63 FLAT "windowsxp.mbr" 0
RW 195371504 FLAT "/dev/sda" 63

# The Disk Data Base

ddb.toolsVersion = "6530"
ddb.adapterType = "ide"
ddb.virtualHWVersion = "4"
ddb.geometry.sectors = "63"
ddb.geometry.heads = "255"
ddb.geometry.cylinders = "12161"

Edit the second RW line and the lines with sectors, heads, and cylinders, replacing the values in the file with the values you determined from the gparted session earlier. Save the file and exit.

Now you're ready to run the windows.vmx file in VMware Player, VMware Server, or VMware Workstation. Choose "Windows" from the GRUB prompt, and then choose "VMware" from the Windows hardware profile menu. Figure Three shows Windows XP running virtualized from an RDM.

No comments: