mounting virtual drives
This entry was tested on ubuntu 8.04 but should not be restricted to this OS. However on Ubuntu I experienced some difficulties that needed to be solved before mounting.
mounting a file that has only one partition is fairly easy using mount -o loop filename mountpoint but if you are using virtual disks like vdi-files or vmdk-files (virtualbox, vmware-server) that contains more than one partitions you would need to calculate the offset and use the offset-param in the mount-commands and things get complicated and are pruned for errors. So better use special tools for doing the job.
STOP ANY RUNNING VM THAT MIGHT ACCESS YOUR VIRTUAL DISK BEFORE EVEN THINKING ABOUT PLAYING WITH THE VIRTUAL DISKS !!
dm_mod
Before using the following tools I had to install the lvm2-package and needed to manually load the dm_mod - module.
kpartx
kpartx is a standard package and can list all the partitions inside a file and make this partitions available as mapper-devices.
kpartx -l FILENAME example: kpartx -l /data/vbox/disks/vbox-zimbra.vdi gpt: 0 slices dos: 6 slices loop0p1 : 0 274984542 /dev/loop0 63 loop0p2 : 0 11727450 /dev/loop0 274984605 loop0p5 : 0 11727387 loop0p1 63
now you can now actually map this partitions to the mentioned mapper-devices:
kpartx -a FILENAME mount /dev/mapper/LOOPDEV MOUNTPOINT examples: kpartx -l /data/vbox/disks/vbox-zimbra.vdi mount /dev/mapper/loop0p2 /mnt/z2
Note that this does not work for dynamic virtual disks that change their size dynamically when data is written inside the virtual machine.
RUN kpartx -d FILENAME when you are finished to release the mappings again !!
dealing with dynamic disks
I dont know how to do it with vbox (virtualbox) but there is a way for this with vmdk-disks as used by vmware2 (vmware-server, esx ...). There is a tool called vmware-mount coming with your vmware-installation that should actually be able to mount any partition from a vmdk-file but it doesnt and failes with you must specify the filesystem type - errors. The web is full of this errormessage when using vmware-mount and full of solutions that didnt work to me. The following solution worked to me. Hopefully it works for you too :)
- step1 : use the -f switch of vmare-mount to mount a flat representation of your dynamic disk. That means that on your mountpoint the non-dynamic (=flat) image of your dynamic disk-image is present:
vmware-mount -f FILE MOUNTPOINT - step2 : use kpartx on this flat image like desribed above :
kpartx -l MOUNTPOINT/flat
do not forget to use vmware-mount -k FILE or a stronger flag (run vmware-mount without any parameter to see the help-message) to unmount the flat-file AFTER you ran kpartx - d to unmount the partitions ....



