Translate

Archives

Access A VMware Virtual Disk from Linux

Recently I needed to recover some data off a VMware Workstation virtual disk using Linux. As you probably know, VMware Workstation (and VMware vSphere) represents a physical disk by a virtual disk whose backing store is one or more VMDK files.

VMDK (Virtual Machine Disk) is a documented file format, which uses the file extension .vmdk. It describes containers for virtual hard disk drives to be used in virtual machines like VMware Workstation or VirtualBox. Initially developed by VMware for its virtual appliance products, nowadays VMDK is an open format.

Fortunately, VMware provides a simple utility, vmware-mount, for mounting a VMware virtual disk on a Linux system. The utility depends on Fuse (File system in USEr Space) which is a loadable kernel module. Fuse allows regular (non-root) users to create and access their own file systems. The file system code runs in user space, while the Fuse module provides a bridge to the actual kernel mount interfaces. Fuse was merged into mainstream Linux in kernel version 2.6.14.

# lsmod | grep fuse
fuse    91371  7

# modinfo --filename fuse
/lib/modules/3.17.8-300.fc21.x86_64/kernel/fs/fuse/fuse.ko.xz


Note that you may have to create loop devices (/dev/loopX) for Fuse to work correctly. Fedora 20 and 21, for example, do not have loop devices installed by default.

You can mount the VMDK as a loop device:

# ls -l
-rw-r--r--. 1 fpm fpm 7706112 Jan 28 09:14 UEFI-disk1.vmdk

# vmware-mount -p ./UEFI-disk1.vmdk
Nr      Start       Size Type Id Sytem
-- ---------- ---------- ---- -- ------------------------
 1       2048    2095104 BIOS  B Win95 FAT32

# vmware-mount ./UEFI-disk1.vmdk /mnt
# df
Filesystem     1K-blocks      Used Available Use% Mounted on
....
/dev/loop0       1045488     28304   1017184   3% /mnt
#

# cd /mnt
# ls -l
total 8
drwxr-xr-x. 6 root root 4096 Dec  1 05:04 efi
-rwxr-xr-x. 1 root root   10 Nov 29 19:24 startup.nsh

# find efi/tools
efi/tools
efi/tools/ftp.efi
efi/tools/hostname.efi
efi/tools/hexdump.efi
efi/tools/which.efi
efi/tools/python.efi
#

# vmware-mount -d /mnt
#

or you can mount a flat-file representation of the entire virtual disk:

# vmware-mount -f ./UEFI-disk1.vmdk /mnt

# df
Filesystem     1K-blocks      Used Available Use% Mounted on
/dev/sda4      479468544  17989652 460335532   4% /
devtmpfs         8153896         0   8153896   0% /dev
tmpfs            8164292       260   8164032   1% /dev/shm
tmpfs            8164292      1004   8163288   1% /run
tmpfs            8164292         0   8164292   0% /sys/fs/cgroup
tmpfs            8164292       256   8164036   1% /tmp
/dev/sda4      479468544  17989652 460335532   4% /home
/dev/sdb1      480589524 383220116  72933748  85% /home/fpm
/dev/sda2         487652    131166    326790  29% /boot
/dev/sda1         204580    105944     98636  52% /boot/efi
tmpfs            1632860        20   1632840   1% /run/user/1000
/dev/sdc1         978692     35016    943676   4% /run/media/fpm/CENTON USB

# cd /mnt
# ls -al
total 1048576
-rw-r--r--. 1 fpm fpm 1073741824 Jan 30 21:47 flat

# vmware-mount -L
Disks with mounted partitions:
	/home/fpm/tmp/UEFI-disk1.vmdk	/mnt/flat

# fdisk -lu /mnt/flat

Disk /mnt/flat: 1 GiB, 1073741824 bytes, 2097152 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00067806

Device     Boot Start     End Sectors  Size Id Type
/mnt/flat1       2048 2097151 2095104 1023M  b W95 FAT32

# dd if=/mnt/flat bs=512 skip=2048 count=1 | xxd
0000000: eb58 906d 6b64 6f73 6673 0000 0208 2000  .X.mkdosfs.... .
0000010: 0200 0000 00f8 0000 3f00 ff00 0000 0000  ........?.......
0000020: 00f8 1f00 0008 0000 0000 0000 0200 0000  ................
0000030: 0100 0600 0000 0000 0000 0000 0000 0000  ................
0000040: 0000 2967 c83b 9120 2020 2020 2020 2020  ..)g.;.
0000050: 2020 4641 5433 3220 2020 0e1f be77 7cac    FAT32   ...w|.
0000060: 22c0 740b 56b4 0ebb 0700 cd10 5eeb f032  ".t.V.......^..2
0000070: e4cd 16cd 19eb fe54 6869 7320 6973 206e  .......This is n
0000080: 6f74 2061 2062 6f6f 7461 626c 6520 6469  ot a bootable di
0000090: 736b 2e20 2050 6c65 6173 6520 696e 7365  sk.  Please inse
00000a0: 7274 2061 2062 6f6f 7461 626c 6520 666c  rt a bootable fl
00000b0: 6f70 7079 2061 6e64 0d0a 7072 6573 7320  oppy and..press
00000c0: 616e 7920 6b65 7920 746f 2074 7279 2061  any key to try a
00000d0: 6761 696e 202e 2e2e 200d 0a00 0000 0000  gain ... .......
00000e0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000f0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000100: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000110: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000120: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000130: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000140: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000150: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000160: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000170: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000180: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000190: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00001a0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00001b0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00001c0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00001d0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00001e0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00001f0: 0000 0000 0000 0000 0000 0000 0000 55aa  ..............U.


Recognize what sector this is? Look at the 55 AA signature at the end of the sector. This designates an Master Boot Record (MBR). An MBR is located in the first sector of an MBR-partitioned disk.

Note that with VMware Workstation 10 you may get the error message VixDiskLib: Invalid configuration file parameter. Failed to read configuration file. You can safely ignore that message.

Best practice is to make a backup copy of your virtual disk before mounting it using the vmware-mount utility.

Comments are closed.