Mounting Logical Volumes Under Linux

Let’s say you have a disk that you want to put in an external USB enclosure, mount and read some files.  What if it’s a boot disk that uses LVM?  What if you have two LVM groups with the same name?

Here’s a quick how-to on mounting just this type of LVM volumes from a USB disk.

When you first attach your disk in it’s USB enclosure you should be able to see which device it is associated with by looking at /var/log/messages.  In my case, it was assigned to /dev/sdc

When you run an fdisk command on the drive you’ll get something like:

Disk /dev/sdc: 80.0 GB, 80000000000 bytes
255 heads, 63 sectors/track, 9726 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xd0f4738c

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1   *           1          13      104391   83  Linux
/dev/sdc2              14        9726    78019672+  8e  Linux LVM

The problem is a bit more complicated when both your existing OS and the disk that you want to mount have the same name for their logical volume.

Do a pvscan and you’ll be able to see the names of the logical volumes on the two disks.

# pvscan
  PV /dev/sdc2   VG VolGroup00   lvm2 [74.38 GB / 0    free]
  PV /dev/sda2   VG VolGroup00   lvm2 [74.31 GB / 32.00 MB free]

In this case, you will need to rename the volume group on the disk that you want to mount via the USB enclosure.  You’ll need to do one of two things:

  • Shutdown your existing computer, disconnect the drives from it, attach the erstwhile USB mounted disk and fire it up with some sort of boot/rescue CD
  • Put the disk in another box, and fire up with the aforementioned boot/rescue CD

I had an extra chassis lying around that I could use so instead of mucking around in my machine, I just used it.  I also used the Fedora Core 8 installation DVD, but you should be able to use any type of Linux rescue disk that contains the lvm binaries.

So once you’ve got your hardware all set up, boot using the rescue disk.  In this case, using the FC 8 install disk, when you get to the prompt where it asks if you want to search for and mount an exsiting partition/installation, select "Skip".

You’ll now be on the command line.  Keep in mind that in rescue mode, all lvm commands need to be preceded with "lvm".

Do a search/scan for your logical volumes with one of the following commands:

# lvm vgscan
# lvm lvscan
# lvm pvscan

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

Then rename your volume group:

# lvm vgrename VolGroup00 VolGroup01

You could name it anything that you want, that’s just what I happened to use.

Shutdown your machine and put the newly renamed volume group disk back in it’s USB enclosure, attach to your computer and fire it up.

A vgscan should display the following:

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

Activate the volume:

# vgchange -a y /dev/VolGroup01
  2 logical volume(s) in volume group "VolGroup01" now active

Mount the volume group

# mount /dev/mapper/VolGroup01-LogVol00 /mnt

Done!

You may or may not have to include the "mapper/" entry in the path, check with your distro to see how it deals with paths to volume groups.  All I had to do was "tab" once I typed /dev/mapper/VolGroup01 and it scrolled through the available logical volumes in the group.

Leave a Reply