Mount Flat VMWare Disk Images Under Linux
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).
Jan 21, 2009 7:44 AM
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.
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).
Dec 15, 2011 8:16 AM
hi, im trying to mount a vmdk with installed Android-x86 distro.
my goal is to modify system dir.
tried this :
chmod 777 android23.vmdk
losetup -s -f android23.vmdk
kpartx -a dev/loop0 , cause there is a partition
mount /dev/mapper/loop0p1 mydisk
mount was correct, but not access in delete system or any other dir
Apr 1, 2012 2:26 PM
Hello. I'm trying to follow the procedure in the below link to convert a vmdk to an iso, and ended up in this thread which has some related information.
My issue is that I have the following partitions:
Disk /home/a.rubio/turnkey/turnkeylinux-tklpatch-cd6b779/fedora-security.raw: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags
1 1049kB 2097kB 1049kB bios_grub
2 2097kB 526MB 524MB ext4 ext4 boot
3 526MB 21.5GB 20.9GB lvm
And you can see that the first and last do not have a file system type. Mount fails not knowing the type. I need the three mounted, the lvm being the main partition. I'm thinking I might need to use a vm without lvm. Meantime, would you happen to know how to get those partitions mounted as well?
Aug 21, 2012 4:02 PM
I have downloaded a dmware image and unzipped it -- it has several vmdk files and an ovf file. How can I browse through the contents. I followed the first technique and the technique by Fred! The first one led to "what is the filesystem type for mounting" -- mount led to the problem; and the second one led to -- "/dev/mapper/loop1p1 is not a block device"...
What am I doing wrong and how can I browse through the contents as a directory...