📜 ⬆️ ⬇️

Mounting LVM-based volumes (LVM-in-LVM)

The situation in which this procedure may be necessary is not often enough, however, sometimes you have to deal with it, for example, when working with virtual machines.

Imagine that we have a virtual machine on the LVM partition, inside which there are also LVM partitions. For example, CentOS, when installed, by default, creates LVM-based partitions, with the exception of / boot.

Task:

get to the data in these sections from the parent machine.
')


Given:

virtual machine on the LVM partition / dev / mapper / vol-centos1
inside it there are sections / boot, / and swap, and / and swap on LVM

Decision:

First, let's see what is / dev / mapper / vol-centos1 :
# kpartx -l /dev/mapper/vol-centos1
vol-centos1p1: 0 1024000 / dev / loop0 2048
vol-centos1p2: 0 15751168 / dev / loop0 1026048
and we will bury sections:
# kpartx -a /dev/mapper/vol-centos1
after that in / dev / mapper we will have two sections
vol-centos1p1 vol-centos1p2

The first vol-centos1p1 (/ boot) section does not interest us, we can mount it even now. We are interested in the second section vol-centos1p2, in which there are / and swap.
Scan and see LVM volumes:
# lvm pvscan
PV / dev / mapper / vol-centos1p2 VG VolGroup lvm2 [7.51 GiB / 0 free]
Total: 1 [7.51 GiB] / in use: 1 [7.51 GiB] / in no VG: 0 [0]

now we need to activate the LVM volumes to get to them, we do:
# lvm vgchange -ay
2 logical volume (s) in volume group "VolGroup" now active

two more sections will appear in / dev / mapper
vol-centos1p1 vol-centos1p2 VolGroup-lv_root VolGroup-lv_swap

now we can safely mount the VolGroup-lv_root section and conveniently work with it:
# mount /dev/mapper/VolGroup-lv_root /mnt

After work, everything must be returned to normal.
unmount # umount /dev/mapper/VolGroup-lv_root
deactivate LVM volumes # lvm vgchange -an VolGroup
remove the mapping # kpartx -d /dev/mapper/vol-centos1

Source: https://habr.com/ru/post/127690/


All Articles