+64-3-3595735

Home » How To » Mount A VBox VDI Disk File With LVM Structure

Mount A VBox VDI Disk File With LVM Structure

The problem:

A vbox virtual machine had failed to start. It was not recovering itself and was in an environment where the vbox image was being run headless.

The data needed recovering so we needed to mount the vdi virtual disk file.

Mounting The VDI Disk File

The first step was to convert it to a raw image:

VBoxManage clonehd --format RAW my-virtual-drive.vdi my-virtual-driveimg

Mount this:

mount -o loop,rw ./my-virtual-drive.img /mnt/<somefoldername>

For me this failed,telling me, ‘mount: unknown filesystem type ‘LVM2_member’

Mine was an LVM volume  but yours might be unknown file type.

If this is not an LVM volume ( unknown file type) then:

You will need to mount it with an offset as it likely contains more than one partition.

fdisk -l ./my-virtual-drive.img

Should tell you something similar to:

Disk /dev/loop1: 19.77 GiB, 21223178240 bytes, 41451520 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: gpt
Disk identifier: 4F198AE2-A256-4319-AFB7-B5684BD97A50

Device         Start      End        Sectors   Size       Type
/dev/loop1p1   2048       4095       2048      1M       BIOS boot
/dev/loop1p2   4096       3676159    3672064   1.8G     Linux filesystem
/dev/loop1p3   3676160    41449471   37773312  18G      Linux filesystem

 

If this is the case add in an offset to your mount command.

mount -o loop,rw,offset=<Sectors * start> ./my-virtual-drive.img /mnt/<somefoldername>

In this case sectors are 512 abd start is 3676160  so

mount -o loop,rw,offset=1882193920 ./my-virtual-drive.img /mnt/<somefoldername>

You should now be able to see files at /mnt/<somefoldername>

 

If this is an LVM Image

losetup /dev/loop0 my-virtual-drive.img
ls /dev/mapper

will give you the name of the mapped volume ( ubuntu-vg in my case )

vchange -ay ubuntu-vg ls /dev/ubuntu-vg/

will tell you the name of the volume ( ubuntu-lv in my case)

mount /dev/ubuntu-vg/ubuntu-lv /mnt

Please note – making a sub folder of /mnt and mounting to that will fail. That is a folder where as /mnt/ is not a ‘folder’ but a mount point able to handle the volume / group we are mounting.

ls /mnt showed me the disk I had just mounted.

 

To clean up.

umount /mnt 
losetup -d my-virtual-drive.img

 

Image From : https://unsplash.com/photos/businessman-looking-at-growth-chart-with-magnifying-glass-7BxTIzHTfiU