How-to: Linux Mint 13 or 14 with LVM

Write tutorials and howtos in here
There are more tutorials here http://community.linuxmint.com/tutorial/welcome
Forum rules
Do not start a support topic here please. Before you post please read this

How-to: Linux Mint 13 or 14 with LVM

Postby powerhouse on Tue Jul 24, 2012 5:14 pm

The following describes the installation of Linux Mint 13 or 14 using LVM (logical volume manager) for / and /home. I've tested it with LM 13 and 14, both Mate and Cinnamon, and it's been reported to work for the XFCE edition, too. If you are familiar with LVM, you can skip down to "Here comes the how-to" http://forums.linuxmint.com/viewtopic.php?f=42&t=108442#p610315.

Important: Linux Mint 15 includes an LVM option in the installer, which makes this how-to obsolete.

For those who want to use UEFI boot (EFI), have a look here: http://forums.linuxmint.com/viewtopic.php?f=46&t=107620#p608123.

The how-to was inspired by this how-to http://forums.linuxmint.com/viewtopic.php?f=197&t=71159 and uses some of it's steps. However, when trying to install Linux Mint 13 Maya using the mentioned how-to, I ran into some perhaps minor issues:

1) You have to setup your user account. locales, etc. manually after installation. You won't have the convenience of the installer.
2) It was written for the Gnome display manager but I use Mate (mdm), so it needs some adaptation for Mate. It's quite easy to do but you need to edit some configuration files manually.

The following how-to should work on most PCs or laptops without issues. It should also work with different Linux Mint releases and desktops - Gnome, KDE, or whatever. I've done this installation at least 4-5 times, including some some modified installation procedure for UEFI. UEFI can be a pain in the neck, so unless you really need it, choose the MBR method below.

If you need encryption as well, check the above mentioned how-to. I haven't tried encryption, but I believe this how-to could be adopted to work with encryption as well. If anyone managed to modify it for encrypted drives/partition, please report back with instructions.

You can skip the introduction and follow the installation part below if you are familiar with LVM!

Why use LVM?

LVM stands for Logical Volume Manager. LVM virtualizes your hard disk drives. Ever ran out of hard disk space? If you did you probably know what that means: Installing a new (usually larger) drive and copying your stuff to the new drive, or creating new partitions to hold the data. In most cases people want to keep their data organized into folders. If the disk is full your folder can't store any more files. Unless you have some spare space on your disk and can resize the partitions, you're forced to add a new drive and copy your folder to that drive. And what if that folder or drive fills up?

Well, you could put your data on RAID using several disks. But eventually these will fill up and then you need to add additional storage. Of course you can expand your RAID and add a new disk, but that procedure may be challenging. If you need to backup all your data, you may need lots of disk space to do that. My old PC holds somewhere around 5-6TB of data on 5 hard disks, plus external storage for backup of the critical data.

LVM is the solution.

What does LVM do?

LVM virtualizes disks. First you create a PV or Physical Volume. This is the hard drive or partition layer. Then you create a VG or Volume Group which is the logical layer for one or multiple drives or partitions. Then you create the LV or Logical Volume, which is the equivalent of a partition. The beautiful thing about LVM is that you can expand VGs and LVs over several drives or partitions. Sounds difficult? It isn't. Let's see an example:

Disk 1 has 3 partitions: /dev/sda1 for /boot, /dev/sda2 for swap, and /dev/sda3 formatted to LVM to hold / and /home. Let's say the disk has 60GB (like a small modern SSD). If your /home folder/partition runs out of disk space, you just add another disk, create a PV (physical volume), add it to the same VG (volume group) as the one that contains the /home partition, and expand the LV (logical volume) to include that disk. Let's say the new disk has a size of 2TB. Now you have a LV mounted as /home with a size of 2TB plus the space you reserved on your original LV. Once that fills up, you add another disk, for example a 3TB disk. Now you have the original disk space you reserved for /home on /dev/sda3 plus the 2TB drive plus the 3TB drive, so somewhere around 5TB+ of disk space on a single logical volume (like a single partition). Not enough, just add disks.

You can even stripe disks (LVs) to get similar performance improvements to RAID. And you can use RAID in combination with LVs.

The beautiful thing about LVM is that you don't need to worry about disk size or type. Hard drive technology and size develops very quickly. My old PC from 5 years ago had 2 250GB drives. Today it holds 5-6TB of data, unfortunately without LVM. I'll move the drives the to the new PC, copy the data onto the new LVM formatted disks, and format these "old" drives to LVM. At the end I will have 10TB on 6 drives. My PC can hold 8 internal drives. If the old drives are too small, I'll copy their data onto external media and copy the data back onto larger LVM drives.

By the way, this does not only pertain to data drives. If your / partition runs out of space, just add a partition on the same or other drive to the LV, or increase the LV to include some empty space of the drive or other drives. Remember, your drive space is virtual and you add as much storage space as your disks or computer allow.

Last not least LVM is the preferred storage option for Xen. With Xen it provides increased read/write speed compared to normal ext4 or other formats.

Size

With LVM you want to assign a reasonable but conservative size to each LV. Why? Because if you leave spare room you can always increase a volume that fills up. For reference, a typical LM13/LM14 installation will use somewhere around 6GB on the / volume (given that you created a separate /home volume).

Partitioning

I suggest 15GB for / unless your are tight on disk space. /boot should be somewhere around 512MB to 1GB, depending on how many kernels you like to install. The size of /home depends on your data structure and needs - it can be anything between ~10GB to several Terabyte.

Increasing the size of logical volumes

Increasing the size of a logical volume is quite easy. Here are the steps involved:

a) Add a physical volume (disk or partition) to the volume group. This is only necessary if your VG runs out of disk space.

b) Extend the logical volume using the "lvextend" command.
Code: Select all
lvextend -L+50G /dev/vg1/lv1
will increase lv1 in volume group vg1 by 50GB. Note the +.

c) Resize the file system using resize2fs (for ext2, ext3, and ext4 file systems).

A concise description of the LVM commands can be found here: http://www.howtogeek.com/howto/40702/how-to-manage-and-use-lvm-logical-volume-management-in-ubuntu/.

For more information on LVM administration, look here: http://www.centos.org/docs/5/html/5.1/Cluster_Logical_Volume_Manager/index.html.
Last edited by powerhouse on Fri May 17, 2013 11:05 am, edited 16 times in total.
Asus Sabertooth X79 (NOT recommended), i7 3930K CPU, 8x4GB Kingston DDR3 RAM, Noctua NH-D14 SE2011 CPU cooler, Sapphire (AMD) 6450 GPU, PNY Quatro 2000 GPU, Sandisk Extreme 120GB SSD, WD 2TB WD20EARX HD, Corsair 500R case, SeaSonic 660W Gold X-Series PS
powerhouse
Level 4
Level 4
 
Posts: 361
Joined: Thu May 03, 2012 3:54 am

Linux Mint is funded by ads and donations.
 

How-to: Linux Mint 13 or 14 with LVM (cont.)

Postby powerhouse on Tue Jul 24, 2012 6:29 pm

Here comes the how-to

Caution - this procedure destroys all data on your target drive (/dev/sda in this example) !!!

Prerequisites: You need a bootable live USB stick or a bootable live DVD/CD with LM13 64 bit installed on it. I downloaded the LM13 Maya DVD ISO and used unetbootin to create a bootable USB stick. It also works with UEFI boot but requires some additional steps. In the end I chose to use an MBR partitioned disk since grub2 1.99 is buggy and doesn't allow you to boot a Xen hypervisor later on.

You also need a working Internet connection to download the lvm2 package!

Set your motherboard BIOS to boot with MBR (that is NOT the UEFI boot option)!

With the LM13 Maya 64 bit live USB stick:

    1. Boot LM13 from USB stick using the non-UEFI option in the BIOS boot menu (make sure you use the option that DOESN'T have "UEFI" preceding the USB stick name !
    2. Open a terminal window and install the lvm2 package:
    Code: Select all
    sudo -i

    Code: Select all
    apt-get install lvm2

    Note: Linux Mint 14 already comes with LVM support on the ISO image, but the installer unfortunately neither offers a LVM option, nor does it install LVM on disk.
    3. Check your devices using
    Code: Select all
    fdisk -l

    and make sure to choose the correct drive in the next step!
    4. This step wipes your disk clean !!! So backup everything you need. Let's assume you install to /dev/sda:

    4.1 Run gparted from the Linux Mint "administration" menu.

    4.1 Partition the disk (/dev/sda) to MBR (default option).

    4.2. Create /dev/sda1 size 512MB formatted as ext2 and flagged as "boot".

    4.3. Create /dev/sda2 unformatted using the rest of the disk.

    5. Open a terminal window and enter:

    Code: Select all
    sudo -i


    We create a physical volume on /dev/sda2:
    Code: Select all
    pvcreate /dev/sda2


    Now we create a volume group named "lm13" on /dev/sda2:
    Code: Select all
    vgcreate lm13 /dev/sda2


    a logical volume called "root", size 15 GB, in volume group "lm13":
    Code: Select all
    lvcreate -L 15G -n root lm13


    a logical volume called "swap", size 5 GB, in volume group "lm13" - NOTE: you can also install the swap partition on a different drive (if you don't like having it on an SSD, for example):
    Code: Select all
    lvcreate -L 5G -n swap lm13


    and a logical volume called "home", size 35 GB, in volume group "lm13":
    Code: Select all
    lvcreate -L 35G -n home lm13


    We need to format the LVs else the installer won't recognize them. First check that the "virtual partitions" (LVs) have been created:
    Code: Select all
    ls /dev/mapper

    The output should look something like:
      control lm13-home lm13-root lm13-swap

    Let's create the file systems for the newly created logical volumes:
    Code: Select all
    mkfs -t ext4 /dev/mapper/lm13-root

    Code: Select all
    mkfs -t ext4 /dev/mapper/lm13-home

    Code: Select all
    mkswap /dev/mapper/lm13-swap


    6. Now run the Linux Mint 13 installer.

    In the partitioner, select "something else" - DON'T use the preselected option!

    Image

    You will then get something like this:
    Image

    Press "Change" to edit the /dev/mapper/lm13-home partition:
    Image

    Do the same for the /dev/mapper/lm13-root partition and assign it to /.

    And change the /dev/sda1 as follows:
    Image

    After you assigned all partitions you should get something like this:
    Image

    Make sure that "Device for bootloader installation:" at the bottom reads "/dev/sda" !

    Check that everything is OK and press "Install Now".

    7. After the installer finishes, DON'T reboot !!!

    Go back to the terminal and enter:
    Code: Select all
    mount /dev/mapper/lm13-root /mnt

    Code: Select all
    mount /dev/mapper/lm13-home /mnt/home

    Code: Select all
    mount /dev/sda1 /mnt/boot

    EDIT: We copy the resolv.conf file with the DNS servers:
    Code: Select all
    cp /etc/resolv.conf /mnt/etc/


    8. Mount the /dev file system to /mnt/dev and chroot to the installed system:
    Code: Select all
    mount --bind /dev /mnt/dev

    Code: Select all
    chroot /mnt

    Root is now the / on your new system. We must mount the special file systems:
    Code: Select all
    mount -t sysfs none /sys

    Code: Select all
    mount -t proc none /proc

    Code: Select all
    mount -t devpts none /dev/pts


    9. Now we update the packages and install lvm2 onto the installed system (our previous lvm2 install didn't update the initram file since the USB disk is read only):
    Code: Select all
    apt-get update

    Code: Select all
    apt-get install lvm2

    Enter "y" when asked "Do you want to continue?"

    "apt-get install lvm2" should update grub and the initram file - look at the output messages.

    10. Let's check the partitions and file systems:
    Code: Select all
    blkid

    The screen should look similar to that:
      /dev/loop0: TYPE="squashfs"
      /dev/sda1: UUID="bef3dfcf-eda3-4f36-bca5-3b3da8d11b84" TYPE="ext2"
      /dev/sda2: UUID="olwatC-fcdl-atIX-m4a7-suCY-uoXo-bjhfJd" TYPE="LVM2_member"
      /dev/sdc1: LABEL="USBDISK" UUID="D4B7-1DAB" TYPE="vfat"
      /dev/mapper/lm13-home: UUID="079228e8-a467-4cfc-9bb1-66586a5c7f39" TYPE="ext4"
      /dev/mapper/lm13-root: UUID="862e50e7-6683-4da9-b7ed-c4dc77b3ebad" TYPE="ext4"
      /dev/mapper/lm13-swap: UUID="045c015c-75a9-4561-b747-1db9f6a9d1b5" TYPE="swap"
      /dev/dm-5: UUID="045c015c-75a9-4561-b747-1db9f6a9d1b5" TYPE="swap"

    11. Now we umount the installed system and exit chroot:
    Code: Select all
    umount /dev/pts

    Code: Select all
    umount /proc

    Code: Select all
    umount /sys

    exit chroot:
    Code: Select all
    exit   # exits chroot

    Code: Select all
    umount /mnt/dev

    Code: Select all
    umount /mnt/home

    Code: Select all
    umount /mnt/boot

    Code: Select all
    umount /mnt

    Code: Select all
    sync   # write all changes to disk (just to be safe)


    12. Now comes the moment of truth - reboot the system.
Last edited by powerhouse on Mon Jan 28, 2013 2:27 am, edited 3 times in total.
Asus Sabertooth X79 (NOT recommended), i7 3930K CPU, 8x4GB Kingston DDR3 RAM, Noctua NH-D14 SE2011 CPU cooler, Sapphire (AMD) 6450 GPU, PNY Quatro 2000 GPU, Sandisk Extreme 120GB SSD, WD 2TB WD20EARX HD, Corsair 500R case, SeaSonic 660W Gold X-Series PS
powerhouse
Level 4
Level 4
 
Posts: 361
Joined: Thu May 03, 2012 3:54 am

Re: How-to: Linux Mint 13 Maya with LVM

Postby Paul38 on Sat Sep 01, 2012 6:50 am

Thank you so much for this tutorial.
I am coming from OpenSUSE and had my disk formatted in LVM already, with spare logical volumes and a spare primary partition ready to receive a new OS (usually the next version of OpenSUSE).
By following your tutorial step by step I managed to flawlessly install Mint13(xfce) instead. Not a single hitch!

Great stuff!
Paul.
Paul38
Level 1
Level 1
 
Posts: 1
Joined: Sat Sep 01, 2012 6:44 am

Re: How-to: Linux Mint 13 Maya with LVM

Postby powerhouse on Sat Sep 01, 2012 7:29 am

Paul38 wrote:Thank you so much for this tutorial.
I am coming from OpenSUSE and had my disk formatted in LVM already, with spare logical volumes and a spare primary partition ready to receive a new OS (usually the next version of OpenSUSE).
By following your tutorial step by step I managed to flawlessly install Mint13(xfce) instead. Not a single hitch!

Great stuff!
Paul.


Hello Paul,

I'm glad it worked. Moreover, now I can add XFCE to "tested" systems :) .

Enjoy Linux Mint - it's awesome!
Asus Sabertooth X79 (NOT recommended), i7 3930K CPU, 8x4GB Kingston DDR3 RAM, Noctua NH-D14 SE2011 CPU cooler, Sapphire (AMD) 6450 GPU, PNY Quatro 2000 GPU, Sandisk Extreme 120GB SSD, WD 2TB WD20EARX HD, Corsair 500R case, SeaSonic 660W Gold X-Series PS
powerhouse
Level 4
Level 4
 
Posts: 361
Joined: Thu May 03, 2012 3:54 am

Re: How-to: Linux Mint 13 or 14 with LVM

Postby Locuust on Wed Apr 03, 2013 11:28 am

Oh man... I was an idiot last night. I know better but I did it anyway. After upgrading my machine my intention was to at least get Mint 14 loaded before I went to bed (ran into some space/cable routing issues). I had read some howto's and such on LVM in the past but I didn't trust my memory so I came here from the link in your xen tutorial. I backed up my home/data directories to another disk, killed my extended partition with my older Mint install, and left my Windows 7 install alone at the beginning of the disk. But I didn't do a backup on Win7.... I think you can see where this is going. Long story short as I was following along with your instructions I failed to replace device names a few steps in and... goodbye Win7 partition. Or rather Win7 turned into an LVM PV.

Thankfully most of my data was actually stored on another drive. So I really only lost a few save games. But seriously I feel like such a noob. After all the server upgrades and data migrations I've done in the past and I get sloppy like that. I probably could have used some data recovery tools as I have my doubts lvm does much more than write out some headers and metadata, but I decided to just wipe all the partitions, start anew, and lvm the whole drive (well besides /boot). Lesson (re)learned.

Anyways, thanks for the tutorial. Once I got my head out of my arse it worked great ;)

By the way it does look like you need to do an update-grub after installing LVM2 into the new install. At least on Mint 14 it doesn't appear that a grub script fires. Unless that's part of what initram does? No biggie. You do say to check for that. So I just did another update-grub to be safe.
Locuust
Level 3
Level 3
 
Posts: 156
Joined: Thu Oct 02, 2008 4:54 pm

Re: How-to: Linux Mint 13 or 14 with LVM

Postby powerhouse on Thu Apr 04, 2013 2:26 am

Locuust wrote:Oh man... I was an idiot last night. I know better but I did it anyway. After upgrading my machine my intention was to at least get Mint 14 loaded before I went to bed (ran into some space/cable routing issues). I had read some howto's and such on LVM in the past but I didn't trust my memory so I came here from the link in your xen tutorial. I backed up my home/data directories to another disk, killed my extended partition with my older Mint install, and left my Windows 7 install alone at the beginning of the disk. But I didn't do a backup on Win7.... I think you can see where this is going. Long story short as I was following along with your instructions I failed to replace device names a few steps in and... goodbye Win7 partition. Or rather Win7 turned into an LVM PV.

Thankfully most of my data was actually stored on another drive. So I really only lost a few save games. But seriously I feel like such a noob. After all the server upgrades and data migrations I've done in the past and I get sloppy like that. I probably could have used some data recovery tools as I have my doubts lvm does much more than write out some headers and metadata, but I decided to just wipe all the partitions, start anew, and lvm the whole drive (well besides /boot). Lesson (re)learned.

Anyways, thanks for the tutorial. Once I got my head out of my arse it worked great ;)

By the way it does look like you need to do an update-grub after installing LVM2 into the new install. At least on Mint 14 it doesn't appear that a grub script fires. Unless that's part of what initram does? No biggie. You do say to check for that. So I just did another update-grub to be safe.


Wow, that sucks! Hope you see the importance of backup on a different drive, preferably on an external drive that is disconnected when you do installations or upgrades or anything that touches the partitions/volumes. In addition to local backup on dedicated backup drives, I backup my data onto external drives that are always disconnected except for when I run the backup. Plus, I keep at least 2 different system backups, so if I inadvertently backup a broken system, I can revert to the previous working system.

With LVM volumes, it's good practice to save and print the output of pvdisplay, vgdisplay, and lvdisplay.

Better luck next time.
Asus Sabertooth X79 (NOT recommended), i7 3930K CPU, 8x4GB Kingston DDR3 RAM, Noctua NH-D14 SE2011 CPU cooler, Sapphire (AMD) 6450 GPU, PNY Quatro 2000 GPU, Sandisk Extreme 120GB SSD, WD 2TB WD20EARX HD, Corsair 500R case, SeaSonic 660W Gold X-Series PS
powerhouse
Level 4
Level 4
 
Posts: 361
Joined: Thu May 03, 2012 3:54 am


Return to Tutorials / Howtos

Who is online

Users browsing this forum: No registered users and 10 guests