Mount Flat VMWare Disk Images Under Linux

Cromoteca

I use a VMWare virtual machine to run my favorite software anywhere. It is a very nice solution, nevertheless when I run it at home I feel quite frustrated for not being able to run it on real hardware.

The easiest solution is to mount it as a local drive and access files from a real Linux installation. VMWare server provides a tool to mount vmdk files, but I don't want to install it just to be able to use that command.

Fortunately, I'm using a flat VMWare image, and this makes possibile to mount the image vithout any special tool. After all, the flat vmdk file is just a raw image of the disk, so you just need to use it as a loopback device.

Let's assume that the disk image is located at /diskimage-flat.vmdk (quite unlikely, but it's OK for an example) and that there are no other loopback devices in use (i.e. /dev/loop0 and /dev/loop1 are free). The needed commands would be:

losetup /dev/loop0 /diskimage-flat.vmdk
losetup -o 32256 /dev/loop1 /dev/loop0
mount /dev/loop1 /mnt/diskimage

The offset in the second command might change for a different virtual disk (although I don't tink so if you want to mount the first partition). To check it, run the first command, then use fdisk on the first loopback device:

losetup /dev/loop0 /diskimage-flat.vmdk
fdisk -l /dev/loop0

The offset is the start of the partition per the number of bytes per sector (63*512 in my case).

Comments

Odin
(Jan 21, 2009 1:44 PM)
Interestingly but not surprisingly you can also write the flat disk image (in the example diskimage-flat.vmdk) directly to the disk. I was able to restore a 11GB Windows XP partition (drive C:) by this way.

You only need a Linux live CD for this operation. I recommend Ubuntu 8.10 desktop installation CD that also works as a live CD (find ubuntu-8.10-desktop-i386.iso with md5sum 24ea1163ea6c9f5dae77de8c49ee7c03). Of course you also need some media to hold the virtual disk image.

Run
fdisk -l diskimage-flat.vmdk
and check the partition table. Create a similar partition to the destination hard disk with fdisk. Size and type must be equal. Remember to mark the partition bootable if you need to boot to it.

Say that you want to write the image to physical partition sda1. Just run
dd if=diskimage-flat.vmdk of=/dev/sda1 bs=512 skip=63

Note here how 63*512 equals 32256 which is the offset of the virtual disk image used in the example in the main post.

If you need to restore a Windows MBR, you can find a Linux program named ms-sys very helpful. In our example we could restore a Windows MBR to the sda simply by typing "ms-sys -m /dev/sda". You can find ms-sys suitable for the aforementioned Ubuntu 8.10 live CD here http://packages.debian.org/etch/ms-sys (just download the i386-version and install with dpkg).
Cool Man
(Feb 12, 2009 1:26 AM)
i want to mount iso image from my local hard disk
in vmwear v6. can u help me
please sent sprlemon@yahoo.com
captcha

Languages

Top Level Menu

Section Menu

Latest News

MeshCMS 3.5 Released

(Jul 3, 2009)

MeshCMS 3.5 has been released yesterday under the GPLv3. As usual, check the change l ...