How to mount a lvm volume which is inside a lvm volume
Tags: lvm, linux, mount
Published: 2019-11-12 23:23:44

---
title: How to mount a lvm volume which is inside a lvm volume
published: true
description: Mounting a lvm volume inside another lvm volume with the same name is a littly bit tricky.
tags: #lvm, #linux, #mount
cover_image: https://thepracticaldev.s3.amazonaws.com/i/fdtvx84lq1svrlhwt84g.jpg
---

if you use something like kvm for virtualization and also use lvm on the host system a good practice is to create a volume for each virtual machine.

to don't make a difference between a physical system and a virtual system, i like to also use lvm in the virtual systems. it works like charm but mounting a volume from virtual machine is kind of tricky. it's getting even trickier if your volume groups all have the same names.

```
kvm host:
    vg_main:
        home
        tmp
        ...
        kvm_web01
            vg_main:
                home
                tmp
                ...

```

so if you try to mount kvm_web01 directly you get an error:

```
mount /dev/mapper/vg_main-kvm_web01  /mnt/web01/
mount: /mnt/web01: wrong fs type, bad option, bad superblock on /dev/mapper/vg_main-kvm_web01, missing codepage or helper program, or other error.
```

with `kpartx` (`aptitude install kpartx`) you can detect partitions inside of an lvm volume and make them accessible:

```
kpartx -av /dev/mapper/vg_main-kvm_web01
add map vg_main-kvm_web01p1 (253:16): 0 389120 linear 253:7 2048
add map vg_main-kvm_web01p2 (253:17): 0 2 linear 253:7 393214
add map vg_main-kvm_web01p5 (253:18): 0 83490816 linear 253:7 393216
```

now the partitions are accessible. you can mount the non lvm boot partition `vg_main-kvm_web01p1` but you still get an error if you try to mount the physical volume on partition `vg_main-kvm_web01p2`

```
mount: ....  unknown filesystem type 'LVM2_member'.
```
(this message is not 100% accurate because i already finished the recovery and i am reproducing the steps without redoing all again)


with `pvscan` the partition made visible with `kpartx` are now also known by lvm.
```
pvscan
vgdisplay
```
in my case i ran in the next problem of having two volume groups with the same name `vg_main`. lvs gave the correct output with most of the partitions duplicated

```
lvs
root@zhaan ~ # lvs
  LV             VG      Attr     LSize   Pool Origin Data%  Move Log Copy%  Convert
  home           vg_main -wi-ao--   1.00g
  home           vg_main -wi-ao--   2.00g
...
```

so you use `vgdisplay` to find out the id of the inner volume group (should be the one with less harddisk space) and `vgrename` to rename it.

```
vgrename -v 6FW1tp-aeVy-1oTW-Ho1M-DwV7-TPB0-QCIoz4 vg_web01
    Cache: Duplicate VG name vg_main: Existing 306MGq-WfN8-LFx5-SKvw-uIfv-dSj0-QCSfGT (created here) takes precedence over 6FW1tp-aeVy-1oTW-Ho1M-DwV7-TPB0-QCIoz4
  Processing VG vg_main because of matching UUID 6FW1tp-aeVy-1oTW-Ho1M-DwV7-TPB0-QCIoz4
    Cache: Duplicate VG name vg_main: Existing 306MGq-WfN8-LFx5-SKvw-uIfv-dSj0-QCSfGT (created here) takes precedence over 6FW1tp-aeVy-1oTW-Ho1M-DwV7-TPB0-QCIoz4
    Archiving volume group "vg_main" metadata (seqno 8).
    Writing out updated volume group
    Renaming "/dev/vg_main" to "/dev/vg_web01"
    Creating volume group backup "/etc/lvm/backup/vg_web01" (seqno 9).
  Volume group "6FW1tp-aeVy-1oTW-Ho1M-DwV7-TPB0-QCIoz4" successfully renamed to "vg_web01"
```  
 
and the use `vgchange` to "refresh" the logical volume list:

```
vgchange -a y
  6 logical volume(s) in volume group "vg_web01" now active
  16 logical volume(s) in volume group "vg_main" now active
```

then you simply use mount to make it accessible on your host system:

```
mount /dev/vg_web01/home /mnt/web01/home
```


lvm rocks! :)

(hope i put my notes together correct. if you find an error trying it out, please comment)

links:

- cover image by jackmac34 https://pixabay.com/photos/matryoshka-russian-dolls-nesting-970943/
- https://stackoverflow.com/questions/14048965/how-to-mount-a-lvm-partition-within-a-lvm-volume
- https://unix.stackexchange.com/questions/339011/how-do-i-mount-an-lvm-partition
- https://documentation.online.net/en/dedicated-server/rescue/mount-lvm-partition
- https://askubuntu.com/questions/110226/how-do-you-mount-a-lvm-patition-that-has-the-same-vg-name-as-my-current-partitio
- https://pissedoffadmins.com/os/mount-unknown-filesystem-type-lvm2_member.html
- https://askubuntu.com/questions/766048/mount-unknown-filesystem-type-lvm2-member