Mounting partition stored inside Logical Volume

On a KVM Virtual machine using LVM storage, the LVM disk is partitioned as follows.

root@mail:~# parted /dev/vg1/iredmail print
Model: Linux device-mapper (linear) (dm)
Disk /dev/dm-1: 64.4GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name  Flags
 1      1049kB  2097kB  1049kB                     bios_grub
 2      2097kB  1076MB  1074MB  ext4
 3      1076MB  64.4GB  63.3GB

root@mail:~# 

I want to mount partition number 2 on the host machine.

 2      2097kB  1076MB  1074MB  ext4

To make the partition available to mount, you need to use kpartx utility. Install kpartx with

apt install kpartx

To make the partitions inside the Logical volume available to mount, use the command

kpartx -a LVM_DEIVE_NAME

In this case, I used

kpartx -a /dev/vg1/iredmail

Now lvscan command will display the new device

root@mail:~# lvscan
  ACTIVE            '/dev/vg1/win10' [100.00 GiB] inherit
  ACTIVE            '/dev/vg1/iredmail' [60.00 GiB] inherit
  ACTIVE            '/dev/ubuntu-vg/ubuntu-lv' [29.50 GiB] inherit
root@mail:~# 

To mount the device, you can use the command

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

IMPORTANT: do not mount the device on the host if it is used in the guest VM as it will result in data corruption. I mounted the disk on the host machine and created some files, but it did not show in the guest. After I reboot the guest VM, it did not boot back, I had to do fsck to get the VM to work again.

Back to LVM

Need help with Linux Server or WordPress? We can help!

Leave a Reply

Your email address will not be published. Required fields are marked *