Monday, April 7, 2014

Mounting VMDK files in Linux

This is pretty awesome - useful for recovery.

From: http://cromoteca.com/en/blog/mountflatvmwarediskimagesunderlinux/
Here's my extra notes.

First, mount the flat vmdk file as loop0, eg:
losetup /dev/loop0 /srv/data/deadserver-flat.vmdk

Now, investigate the structure with parted, eg:
# parted /dev/loop0
GNU Parted 2.1
Using /dev/loop0
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) unit bytes
(parted) print
Model:  (file)
Disk /dev/loop0: 12884901888B
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start       End           Size          Type     File system  Flags
 1      32256B      131604479B    131572224B    primary  ext3         boot
 2      131604480B  238533119B    106928640B    primary               raid
 3      238533120B  12880788479B  12642255360B  primary               lvm


The figures in the start column can be used as offsets into the loop device to get to the partitions stuck in the vmdk file.

Next, mount the partition from within the vmdk as another loop device, eg:
losetup -o 238533120 /dev/loop2 /dev/loop0

Finally, confirm it worked:
# blkid /dev/loop2
/dev/loop2: UUID="oc9FXU-tSLN-jdy9-1Zpy-XpA1-qgkI-Ng2l4w" TYPE="LVM2_member"


Cool.  Now you can use loop2 as a block-device.

No comments:

Post a Comment