To use a whole physical (USB-) disk as VMDK (
virtual machine disk) for VWware Fusion, allowing me to install an OS (OpenSolaris) from within VWware Fusion, plug the disk as device into a new computer and boot from there.
I want to upgrade my Xen dom0 from Centos to OpenSolaris. My server provides important services (Internet gateway, mp3-repository, this site, …) to me and my family, so I want to keep the downtime as low as possible. Installing and configuring the replacement system in a VMware-vm seems like a natural thing to do.
If you just want to use a single partition of the physical disk in Fusion you can stop with “Here be Dragons”.
It seems that VMware GSX Server and VMware Workstation for Windows are able to use raw disks. “Unfortunately” I do not have Windows installed, so I’ll have to stick with Fusion.
Although it is possible to use a file based VMDK and
dd it to the target hd, that seems a bit complicated to me. The new boot device will be a 32GB
SSD attached via
SATA. Whatever my new SSD is: blazingly fast is not an attribute I would assign to it. Another reason to keep the number of 32GB-copies down.
“Disclaimer”: Playing with raw devices can ruin your whole day, so take care and use backups (but who am I telling …)
Installing Windows on my MacBook is a no-go. Also I do not want to install another virtualisation solution as I am quite happy with Fusion.
Up front: The result
It didn’t work the way I wanted it to. I am able to install an OS (Centos or OpenSolaris) but as soon as I update the partition of my HD from within the VM Fusion refuses to use the disk on the next reboot. This error pops up non-deterministic: sometimes it works, but mostly it doesn’t and if it starts “not working”, it stays that way.
On the positive side I can confirm that attaching single partitions (mostly) works. It is just not, what I need.
First we’ll do a bit of preparation for MacOS and find out how our to-be raw disk is named.
Disk Utility an open the preferences page (
cmd + ,).
There disable automounting of disks. This will reduce the number of read attempts MacOS issues to read the disk.
Plug in your USB-disk and
locate the disk in the left pane and open the information window by right-clicking on the disk. The important bit is the Disk Identifier (In my case
disk1). Unmount the volume (here:
Partition the HD
We create the partitions for the installation from MacOS and not from within the vm. Experiments to do otherwise were .. unsuccessful, to say the least.
fdisk to create the partitions.
Disk Utility doesn’t.
Partitions with fdisk
We will create a partition schema on our raw device. The schema must be exact the same schema as you will use for installation and that includes the partition types.
Print the partition. Verify partition
1 (no page-device for this experiment):
You should be able to create the partitions with
Disk Utility. Just make sure, that you chose to create an
MBR partition table. A disadvantage of
Disk Utility is that you have to format the partitions. Thats triggers MacOS to mount the partition and that prevents you from accessing the raw device. You have been warned.
Create the VMDK
We will create the initial VMDK-files in
Still in the shell, navigate to
/Library/Application Support/VMware Fusion and create the VMDK descriptor files. The command will create a raw device from partition
52236 bytes large, that is exactly
63 x 512 bytes.
512 is the sector size and
63 is the offset of the first partition. Open
source.vmdk in your favorite editor:
If we examine the
Extent description we can guess that
source-pt.vmdk really contains the first 63 sectors of the disk. The second section (
FLAT) seems to be our partition: The size matches the partition size from the
/dev/disk1s1 is a clear hint anyway.
The way I interpret the
RW sections VMware prepends a “virtual” bootsector and partition table to the raw partition. This auto-magically makes the first partition in the VM start with the partition assigned to it. Neat trick.
We can verify this by analyzing
Attach the device
Start Fusion and create a virtual machine. Right-click on the new VM and choose
Show in Finder. Move your
source-pt.vmdk files here.
Go back to Fusion and remove any unwanted disks. Add a new disk by
choosing an existing disk. Do not copy or move the disk! This will try to copy your raw device to your hard-drive.
Start the VM and install the OS of your choice. DO NOT partition the disk inside your VM!. If you do this, read the next section :-(
Here be Dragons
So far everything (more or less) worked. The following sections show my less fortunate attempts to create more than a proof of concept.
“This should work”-warning: I believe that the following attempts should work, but they did not work for me.
Updating the physical device
Currently the freshly installed OS will only boot inside VMware. The reason is, that VMware redirected all writes to the first 63 sectors into
source-pt.vmdk. This includes the bootsector and the partition table. To sync virtual and physical disk copy the content of
source-pt.vmdk onto the physical disk:
Verify that you can still boot the disk in Fusion, eject the disk in the
Device Utility, unplug it and attach it as new boot device for your physical computer.
With the knowledge we gained by examining the
vmdk-file we can now try to modify it to suit our needs.
- Remove the line
RW 63 FLAT "source-pt.vmdk" 0
- Modify the second line: Increase the size by 63 sectors and use the whole disk, not just a slice as source:
After you have installed the new OS on the disk and shut down the VM, you won’t be able to boot it up again. Fusion will show you an error Cannot open the disk … /source.vmdk … The partition table on the physical disk has changed since the disk was created.
This happens if you (or your installer) modify the partition table.
The partition created by OpenSolaris:
If I re-create the VMDK file …
I get a newly generated VMDK-file:
Whatever I did to it – I was unable to boot up the VM with it. Bad luck. Any ideas out there?
I used a MacBook with Mac-OS X 10.5.6 and VMware Fusion Version 2.0.1 (Build 128865). I was able to install OpenSolaris 2008.11 onto my 32GB USB attached SSD. I was unable to do what I intended to do: Installing an operating system on an external raw device and use that device as boot device for my server. So the experiment succeeded only partly.
By the way: I plugged the disk into my server, rebooted from it and (probably) ran into OpenSolaris bug #4755.
I learned a few things on how VMware implements their
VMDKs and how to use Gimp to create the nice looking smoke-glass codeblock lang:ers. I also found out that OpenSolaris and booting from ZFS is still not as mature as I expect a server-OS to be.
-  VWware Fusion: http://www.vmware.com/products/fusion/
-  A Beginner’s Guide to VMware Fusion: http://communities.vmware.com/docs/DOC-1110
links that might be usefull but weren’t to me
- VMware Virtual Disk Development Kit: http://www.vmware.com/download/sdk/virtualdisk.html
- Virtual to Physical Documentation and Sample Configurations: http://www.vmware.com/support/v2p/