How to mount an LVM volume?

38

22

I'm trying to mount an LVM2 volume in Linux, but all the instructions I see online say to mount the Volume Group, such as:

mkdir -p /mnt/VolGroup00/LogVol00

but I don't know how to figure out the name of it. I see the drive in Palimpsest, and that's all the info I know.

99miles

Posted 2010-03-05T17:54:29.533

Reputation: 537

1I am surprised that no one mentioned about findmnt command. You can just do a findmnt -l and you'll get what you want. And for a better version Try this : findmnt -l | grep ' /dev/\S\+' – C0deDaedalus – 2018-05-22T05:56:16.767

Sadly does not see any solution for the ___mount of an LVM volume from a dd/raw image___ in the answers. Would be great to see if some of the solutions are also working for this use case. – gies0r – 2018-11-19T12:47:02.777

Answers

55

Here are the steps I used to accessing a LVM from Fedora 17, it should work with most forms of Linux.

Boot Fedora 17.

Make sure lvm2 is installed:

$ sudo yum install lvm2

Load the necessary module(s) as root:

$ sudo modprobe dm-mod

Scan your system for LVM volumes and identify in the output the volume group name that has your Fedora volume (mine proved to be VolGroup00):

$ sudo vgscan

Activate the volume:

$ sudo vgchange -ay VolGroup00

Find the logical volume that has your Fedora root filesystem (mine proved to be LogVol00):

$ sudo lvs

Create a mount point for that volume:

$ sudo mkdir /mnt/fcroot

Mount it:

$ sudo mount /dev/VolGroup00/LogVol00 /mnt/fcroot -o ro,user

You're done, navigate to /mnt/fcroot and copy the files and paste somewhere else.

Eric Leschinski

Posted 2010-03-05T17:54:29.533

Reputation: 5 303

1Working through this was easy to follow and worked for me in ubuntu (exchanging yum for apt-get of course). Activation in particular, not covered by other answers, was important. This is the way to go if you have an old drive with LVM and attach it to another working system. – Mr Purple – 2016-07-31T04:37:48.180

3This answer should be accepted. vgscan, then vgchange -a y' are the necessary steps. – Daniel Dinnyes – 2016-09-07T19:43:24.743

1Indeed, the activation part was vital to get it to work. – Zitrax – 2016-12-08T14:55:27.020

In RedHat 7, I first had to run pvscan --cache. Without that, vgscan would not even see the new volume group. – Kevin Keane – 2018-06-27T22:55:59.687

Don't forget to create a file system on the LV before mounting if there is none. mkfs -t ext4 /dev/VolGroup00/LogVol00 Otherwise the mount: wrong fs type, bad option, bad superblock error message will appear. – linux64kb – 2020-01-07T15:25:09.953

26

Faced this problem a while ago, I'd posted this on my blog

List out all your partitions, type

linux:/ # lvmdiskscan

You will get a list of something like this

File descriptor 3 left open
File descriptor 4 left open
/dev/dm-0 [ 9.67 GB]
/dev/sda1 [ 78.41 MB]
/dev/dm-1 [ 6.44 GB]
/dev/sda2 [ 115.52 GB]
/dev/dm-2 [ 2.00 GB]
/dev/sda3 [ 18.11 GB] LVM physical volume
/dev/sda5 [ 15.33 GB]

Make a note of /dev/dm-x, those are the devices which correspond to the LVM partitions. Also do note the sizes.

Next, type lvdisplay to show a detailed list of all the logical volumes available.

lvdisplay |more

LV Name /dev/system/home
VG Name system
LV UUID 1QP9XM-vlKi-umNO-CXvV-TnZN-RCLk-e1FDIr
LV Write Access read/write
LV Status available
# open 1
LV Size 9.67 GB
Current LE 2475
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0

— Logical volume —
LV Name /dev/system/root
VG Name system
LV UUID D1fKUJ-uU1C-jlVB-4imh-rrgy-FQu0-TC2Ssm
LV Write Access read/write
LV Status available
# open 1

LV Size 6.44 GB
Current LE 1649
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1

— Logical volume —
LV Name /dev/system/swap
VG Name system
LV UUID w5LqIb-xvcr-Xsbk-y3wg-lT3i-LqdN-GFK8Mi
LV Write Access read/write
LV Status available
# open 0
LV Size 2.00 GB
Current LE 512
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2

Now from the above set of data, we can deduce that my /home partition, of size 9.67 GB is available as LV group /dev/system/home on /dev/dm-0

Now that we know where the partition is available, we can proceed with the mounting using the mount command, as

mount /dev/dm-0 /home

And there you go, your LV partition is mounted!

Sathyajith Bhat

Posted 2010-03-05T17:54:29.533

Reputation: 58 436

7

You can get a list of volume names by running lvscan. The output will look like

/dev/VG1/LV1
/dev/VG1/LV2
/dev/VG2/LV3

i.e. with the volume group names in the middle and logical volumes at the end. See if any of them correspond to the information in Palimpsest Disk Utility.

Also, compare to the list of disks already mounted (mount), and see which one isn't there. It might look a little different, e.g.:

$ mount
/dev/mapper/VG1-LV1 is mounted on /usr
/dev/mapper/VG1-LV2 is mounted on /home

You can see where the volume group and logical volume appear at the end.

Once you've found the right one, mount it in the usual way:

mount /dev/VG2/LV3 /mnt

Peter Westlake

Posted 2010-03-05T17:54:29.533

Reputation: 996

3

I find guestmount(1) the easiest way.

# guestmount -m /invalid/path  -a /path/to/block/device /mnt/
guestmount: '/invalid/path' could not be mounted.
guestmount: Did you mean to mount one of these filesystems?
(...)
guestmount:     /dev/vg0/root (ext4)
(...)

# guestmount -m /dev/vg0/root -a /path/to/block/device /mnt

See also http://libguestfs.org/guestmount.1.html.

Package guestmount on ubuntu, libguestfs-tools on RHEL and derivates.

tobixen

Posted 2010-03-05T17:54:29.533

Reputation: 229

2

Here's another way to mount it I found handy:

DISK=mydisk

lvdisplay | grep $DISK | grep "LV Path" | sed 's/.* //g'
LV_DISK=$(lvdisplay | grep $DISK | grep "LV Path" | sed 's/.* //g')

fdisk -l $LV_DISK
fdisk -lu $LV_DISK | sed -n '/lv[0-9]p[1-3]/ p' | grep p1 | awk '{print $2}'

OFFSET=$(fdisk -lu $LV_DISK | sed -n '/lv[0-9]p[1-3]/ p' | grep p1 | awk '{print $2}')
OFFSET=$((OFFSET * 512))

MOUNT=/mnt/$DISK
mkdir -p $MOUNT
mount -o loop,offset=$OFFSET $LV_DISK $MOUNT

Neil McGill

Posted 2010-03-05T17:54:29.533

Reputation: 206

1

you can view the name of the lvm using the command

lsblk

then you can find that name under /dev/mapper/ dierctory, for example i can mount my old home directory by:

mount /dev/mapper/rhel-home /mnt

once

Posted 2010-03-05T17:54:29.533

Reputation: 111

0

This can be done from UI with KVPM.

Simply select the group you want to mount and click the "mount fs" option.

enter image description here

yms

Posted 2010-03-05T17:54:29.533

Reputation: 708