Mount a VMDK in linux without having VMWare installed
發表於 : 2015-01-10 23:28:44
http://www.cyborgworkshop.org/2014/07/0 ... installed/
I have a vmdk file that I need to mount on a linux box to move some data around, but unfortunately I don’t have vmware installed on that box. I could install it and go through that hassle, or I could spend 10 times as much effort trying to figure out how to mount a raw vmdk in linux natively. Lets do that instead!
First off, I’m working on a vmdk from an ESXI 5.5 install. The vmdk is flat, no snapshots, no additional extents. I have no idea how you would do this if things are more complex.
First step, we need to look at the disk itself and figure out the partition table. Fortunately for us, vmdk files act a lot like a regular disk so we can use the tools that linux already has. We start by attaching the vmdk to a loop back device
losetup /dev/loop0 vi-flat.vmdk
Now we inspect that file to see if we can find the partition table
#fdisk -l -u /dev/loop0
Disk /dev/loop0: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders, total 104857600 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
Disk identifier: 0x0008f880
Device Boot Start End Blocks Id System
/dev/loop0p1 * 2048 499711 248832 83 Linux
/dev/loop0p2 501758 104855551 52176897 5 Extended
/dev/loop0p5 501760 104855551 52176896 8e Linux LVM
That looks familiar. We need to know the offset of the partitions on the disk in order to mount them manually, so we’re going to take the sector size (512 bytes in my case) and multiply that by the value of the partition start sector to come up with the bytes offset . In my case its
512 * 2048 = 1048576
Now we are going to setup a loopback device that attaches to our vmdk, but starts at the offset that we just calculated. That gives us just the partition we want.
#losetup -o 1048576 /dev/loop1 /dev/loop0
And now we can mount that loopback just like we would any drive
#mount /dev/loop1 /mnt/vmdkfile/
And use it like a regular drive mount
#ls /mnt/vmdkfile/
abi-3.8.0-39-generic config-3.8.0-41-generic initrd.img-3.8.0-41-generic
…
When you are done, just unmount the file and detach the loops
umount /mnt/vmdkfile/
losetup -d /dev/loop1
losetup -d /dev/loop0
Happy hacking!
I have a vmdk file that I need to mount on a linux box to move some data around, but unfortunately I don’t have vmware installed on that box. I could install it and go through that hassle, or I could spend 10 times as much effort trying to figure out how to mount a raw vmdk in linux natively. Lets do that instead!
First off, I’m working on a vmdk from an ESXI 5.5 install. The vmdk is flat, no snapshots, no additional extents. I have no idea how you would do this if things are more complex.
First step, we need to look at the disk itself and figure out the partition table. Fortunately for us, vmdk files act a lot like a regular disk so we can use the tools that linux already has. We start by attaching the vmdk to a loop back device
losetup /dev/loop0 vi-flat.vmdk
Now we inspect that file to see if we can find the partition table
#fdisk -l -u /dev/loop0
Disk /dev/loop0: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders, total 104857600 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
Disk identifier: 0x0008f880
Device Boot Start End Blocks Id System
/dev/loop0p1 * 2048 499711 248832 83 Linux
/dev/loop0p2 501758 104855551 52176897 5 Extended
/dev/loop0p5 501760 104855551 52176896 8e Linux LVM
That looks familiar. We need to know the offset of the partitions on the disk in order to mount them manually, so we’re going to take the sector size (512 bytes in my case) and multiply that by the value of the partition start sector to come up with the bytes offset . In my case its
512 * 2048 = 1048576
Now we are going to setup a loopback device that attaches to our vmdk, but starts at the offset that we just calculated. That gives us just the partition we want.
#losetup -o 1048576 /dev/loop1 /dev/loop0
And now we can mount that loopback just like we would any drive
#mount /dev/loop1 /mnt/vmdkfile/
And use it like a regular drive mount
#ls /mnt/vmdkfile/
abi-3.8.0-39-generic config-3.8.0-41-generic initrd.img-3.8.0-41-generic
…
When you are done, just unmount the file and detach the loops
umount /mnt/vmdkfile/
losetup -d /dev/loop1
losetup -d /dev/loop0
Happy hacking!