LVM

From Leaky
Revision as of 19:28, 21 September 2013 by Leaky (talk | contribs) (Created page with ' == Mounting a filesystem from a Xen disk file that has LVM on it == # losetup /dev/loop7 xenguest1.xvda.img # kpartx -v -a xenguest1.xvda.img If the disk partitions were jus…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Mounting a filesystem from a Xen disk file that has LVM on it

# losetup /dev/loop7 xenguest1.xvda.img
# kpartx -v -a xenguest1.xvda.img

If the disk partitions were just normal ones, you would be able to mount them now as /dev/loop7p1 /dev/loop7p2 etc. If the filesystems are contained within an LVM volume group there are some extra steps.

Scan physical volumes for LVM partitions

# pvscan
PV /dev/mapper/loop7p2   VG vg_xenguest1  lvm2 [29.51 GiB / 0    free]

Scan the partitions for volume groups

# vgscan
Reading all physical volumes.  This may take a while...
Found volume group "vg_xenguest1" using metadata type lvm2

Scan for logical volumes. Any that are currently in use will show ACTIVE in the first column.

# lvscan
 inactive   '/dev/vg_xenguest1/lv_root' [28.54 GiB] inherit
 inactive   '/dev/vg_xenguest1/lv_swap' [992.00 MiB] inherit

Since these are inactive, they can't be used as devices (yet).

# lvdisplay /dev/vg_xenguest1/lv_root
...
 LV Status              NOT available
 LV Size                28.54 GiB
...

First we need to set the volume group active, and then the logical volumes should work fine.

# vgchange -ay vg_xenguest1
2 logical volume(s) in volume group "vg_xenguest1" now active

And now we can mount the root filesystem.

# mkdir /mnt/xenguest1
# mount -t ext3 /dev/mapper/vg_xenguest1/lv_root /mnt/xenguest1

When you're finished with it, use the following commands to make the volumes inactive, remove the partitions from the kernel partition map and then remove the loopback device.

# vgchange -an vg_xenguest1 
# kpartx -v -d /dev/loop7
# losetup -d /dev/loop7