--- Title: VirtualBox - Editing .vdi slug: VirtualBox - Editing .vdi Date: 2018-04-13 Category: Virtualization Tags: VirtualBox Authors: lucanuscervus Summary: ---
How to mount and edit .vdi files with a LVM filesystem.
How to mount a vdi disk image?
#First, install the QEMU tools
sudo apt-get install qemu-utils
#Load the nbd kernel module
sudo modprobe nbd
#Next run qemu-nbd. This will connect the vdi file to the nbd0 device.
sudo qemu-nbd -c /dev/nbd0 /path/to/file.vdi
#Then create device maps from partition tables
sudo kpartx -a /dev/nbd0
#Finally mount the partition
sudo mount /dev/mapper/nbd0p1 /mnt
#When you’re done, unmount the filesystem and shut down the qemu-nbd service.
sudo umount /mnt
sudo qemu-nbd -d /dev/nbd0
How to Mount a Logical Volume
When I tried to mount /dev/nbd0, I got the following error:
lucanuscervus@omv:~$ sudo mount /dev/mapper/nbd0p1 /mnt
mount: unknown filesystem type 'LVM2_member'
So, first I uses the command pvs to find information about the physical volumes on the computer.
lucanuscervus@omv:~$ sudo pvs
PV VG Fmt Attr PSize PFree
/dev/mapper/nbd0p1 vg-root lvm2 a-- 25.00g 0
Then use the lvdisplay command to list all the logical volumes.
lucanuscervus@omv:~$ sudo lvdisplay
--- Logical volume ---
LV Path /dev/vg-root/lv-root
LV Name lv-root
VG Name vg-root
LV UUID 0vFCoR-dsbr-yJra-TBZy-dAan-FLGN-eY0Wyg
LV Write Access read/write
LV Creation host, time ubuntudrone, 2016-04-09 09:23:21 +0100
LV Status NOT available
LV Size 19.41 GiB
Current LE 4968
Segments 1
Allocation inherit
Read ahead sectors auto
--- Logical volume ---
LV Path /dev/vg-root/lv-swap
LV Name lv-swap
VG Name vg-root
LV UUID XMop7w-MR24-EjER-EWWd-cbE0-MEXx-EIlyaT
LV Write Access read/write
LV Creation host, time ubuntudrone, 2016-04-09 09:23:46 +0100
LV Status NOT available
LV Size 976.00 MiB
Current LE 244
Segments 1
Allocation inherit
Read ahead sectors auto
--- Logical volume ---
LV Path /dev/vg-root/lv-home
LV Name lv-home
VG Name vg-root
LV UUID DlguIf-pMPL-HY9l-SS1l-2gcD-9FYT-Z6U2kU
LV Write Access read/write
LV Creation host, time ubuntudrone, 2016-04-09 09:23:56 +0100
LV Status NOT available
LV Size 4.64 GiB
Current LE 1187
Segments 1
Allocation inherit
Read ahead sectors auto
Once, I know where the root filesystem is, I made the volume group active and then I mounted root it in /mnt
lucanuscervus@omv:~$ sudo vgchange -ay vg-root
3 logical volume(s) in volume group "vg-root" now active
lucanuscervus@omv:~$ sudo mount /dev/vg-root/lv-root /mnt
When I finish editing the file, I unmount, make the vg inactive, deactivate kpartx and stop qemu-nbd
sudo umount /mnt
#Make VG inactive. Output like 0 logical volume(s) in volume group "vg-root" now active
sudo vgchange -a n vg-root
#Deactivate kpartx
sudo kpartx -d /dev/nbd0
# Disconnect
sudo qemu-nbd -d /dev/nbd0