How can i mount a Partition of a VM-LVM

Jan 9, 2012
282
2
18
Hi,

i have installed a Ubuntu-VM on a LVM.

When the VM is running

fdisk -l /dev/Raid-VG/vm-103-disk-1

shows

Device Boot Start End Blocks Id System
/dev/Raid-VG/vm-103-disk-1p1 * 1 2497 20051968 83 Linux
/dev/Raid-VG/vm-103-disk-1p2 2497 2611 916481 5 Extended
/dev/Raid-VG/vm-103-disk-1p5 2497 2611 916480 82 Linux swap / Solaris

But when the VM is off, the fdisk-command shows nothing.

Is it possible to mount the partitions of "/dev/Raid-VG/vm-103-disk-1p1" from the host?


Alex
 
You need to use a utility named kpartx

Install it:
Code:
apt-get install kpartx

Run it:
Code:
kpartx -a /dev/Raid-VG/vm-103-disk-1

See new mappings:
Code:
ls /dev/mapper/

Mount the first partition:
Code:
mount /dev/mapper/Raid-VG-vm--103--disk--1p1 /mnt

Unmount:
Code:
umount /mnt

Undo what kpartx did and return system to normal:
Code:
kpartx -d /dev/Raid-VG/vm-103-disk-1
 
This is excellent. Any idea how to install grub on a VM image created this way? My goal is to use the same tar ball for VMs as containers. I struggled a lot and failed. There's probably a simple answer.