Mar 18, 2015

How To Mount an LVM2 Volume Using an Ubuntu Live CD/DVD

The other day I had this Ubuntu Linux VM that I hadn't logged onto in a really long time, and for the life of me I couldn't remember the password I set for root. Yeah, I know, I'm not supposed to use root and I'm only supposed to use sudo. Well I don't. I always activate root!

What can I say? I like to live dangerously...

In order to reset it, I had to boot up to a live DVD and chroot into the root partition. The problem was the root partition and the swap partition were both stored in an lvm2 container. To mount a container like that in a live DVD is pretty simple. Just do the following:
  •   Boot using the live DVD. Install lvm2 by running:
    # apt-get install lvm2
  • To make sure the hard disk is recognized, you can use fdisk.
    # fdisk -lu
  • Run pvscan to scan all disks for an lvm2 volume. This is to make sure your LVM hard disk is detected by Ubuntu.
    # pvscan
  • After that run vgscan to scan disks for volume groups.
    # vgscan
  • Activate all volume groups available.
    # vgchange -a y
  • Run lvscan to scan all disks for logical volumes. You can see partitions inside the hard disk are now active.
    # lvscan
  • Your actual partitions contained in the lvm2 volume will now be listed. Mine were:
    ACTIVE '/dev/ubuntu/root' [50 GB] inherit
    ACTIVE '/dev/ubuntu/swap' [4 GB] inherit
  • Mount the root partition to any directory you want, usually to /mnt
    # mount /dev/ubuntu/root /mnt
  • You can access the partition in the /mnt directory now
This is handy if you have to recover files from a dead system, or like in my case, you need to chroot in and reset the root password.

Please... Don't judge me!

One thing you might want to do is make sure that the live DVD you are using has the same architecture as the system you want to mount. For instance, if your system is running 32 bit Ubuntu, make sure you use a 32 bit Ubuntu desktop live DVD. If your system is running 64 bit Ubuntu, use the 64 bit Ubuntu desktop live DVD. You savvy?

If you have any questions, hit me up in the comments.
[Via Linux Wave]

Twitter Delicious Facebook Digg Stumbleupon Favorites More

Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | stopping spam