Gentoo LVM installation Avi Schwartz In this guide I describe how I setup my Gentoo machine using the Logical Volume Manager(LVM). While all examples are from my specific installation, it may serve as a starting point to your own installation. 1.0 4 May 2002 Preface

This guide describes my experience in setting up my specific Gentoo system using the Logical Volume Manager (LVM). This means that you will more then likely need to change the drive, partition names and partition sizes to match your own setup and needs.

This document is not intended to be an LVM tutorial. It serves as a supplement to the Gentoo installation document and as such it references steps in the general installation guide. Make sure to read the Gentoo Installation Guide before you start your installation process. For a complete LVM HOWTO point your browser to http://www.sistina.com/lvm_howtos/lvm_howto/
Partitions

I have 2 SCSI drives, each 36 GB in size and a third drive which is IDE and is 100 GB in size. In this example, I am not using the IDE drive since my plan is to move its data to LVM before I reformat it and add it to the volume group.

The partition names on my system are:

  • /dev/sda1 -- /boot
  • /dev/sda2 -- /
  • /dev/sda3 -- Will be used by LVM
  • /dev/sdb1 -- Will be used by LVM

OK, time to start...

Installation

  1. Go through steps 1 - 5 of the installation guide.
  2. Steps 3 - 9 of this document replace step 6 (Set up partitions) of the installation guide.
  3. Create a small physical /boot partition. In this example, /boot will be not managed by LVM. This partition will contain your booting kernel and Grub. I created a 100 MB partition, enough for quite a few kernel generations.
  4. Create a / (root) partition. If you are interested in trying to put your root partition under LVM management, see the resources section at the end for a link to a mini-howto on how to do this. The size of the root partition need not be large if you will keep /opt /usr /home /var and /tmp in an LVM Volume Group (vg). I would also recommend NOT to put the following directories in an LVM partition:
    • /etc
    • /lib
    • /mnt
    • /proc
    • /sbin
    • /dev
    • /root

    This way, you would still be able to log into your system (crippled, but still somewhat usable, as root) if something goes terribly wrong.

  5. Assuming the /boot and root partitions do not use the whole physical disk, create a third partition on this disk and set it to type 8e (Linux LVM). If you have more physical drives you would like to use with LVM, create one partition on each and give them the same type (8e). You can also prepare a whole device instead of a partition.
  6. Prepare the partitions.
    pvcreate /dev/sda3
    pvcreate /dev/sdb1
    
  7. Setup a volume group. vgcreate does not recognize links pointing to the physical partition therefore use
    ls -l /dev/hd* and or /dev/sd*
    
    to find out the actual devices.

    In my case /dev/sda1 and /dev/sda2 are the /boot and root partitions so I care only about /dev/sda3 and /dev/sdb1. /dev/sda3 points to /dev/scsi/host1/bus0/target0/lun0/part3 and /dev/sdb1 points to /dev/scsi/host1/bus0/target1/lun0/part1. Therefore my vgcreate will look as follows:

    vgcreate vg /dev/scsi/host1/bus0/target0/lun0/part2 \
                /dev/scsi/host1/bus0/target1/lun0/part1
    
  8. Create the logical volumes. Logical volumes are the equivalent of partitions you create using fdisk in a non LVM environment. In my example I create the following partitions: /usr10 GB/home5 GB/opt5 GB/var10 GB/tmp2 GB
    Directory Size

    Since I was going to use LVM, I didn't worry too much about partition sizes since I can always move space around as needed.

    Terje Kvernes commented correctly, that it is easier to increase the size of a partition then to shrink it. You might want therefore to start with smaller partitions and increase their size as needed. I also created a swap partition on LVM. You will be probably better off not using LVM for swap, but I felt I had to try it :-)
    lvcreate -L10G -nusr vg
    lvcreate -L5G -nhome vg
    ...
    lvcreate -L2G -ntmp vg
    
  9. Format the logical volumes the same way you format a regular partition:

    First, lets take care of the swap logical volume:

        mkswap /dev/vg/swap
    

    I am using ext3 on the rest of the logical volumes:

        mke2fs -j /dev/vg/usr
        ...
    
    The rest of the installation document is mostly unchanged so I will not walk you through it again except to point differences.
  10. Follow step 7 (Mount partitions) of the installation document exchanging /dev/vg/partition_name for /dev/hdxx (except of course for the boot and root partitions since they are not on a LVM).
  11. Step 14 (Final steps: kernel and system logger) - Make sure to configure your kernel to support LVM. You can find this option in the entry named

    Multi-device support (RAID and LVM)

    also make sure to merge the lvm-user package.

  12. Step 16 (Final steps: /etc/fstab) - Add your LVM partitions to /etc/fstab as needed. Again, here are few lines from my machine:
    /dev/sda1   /boot   ext3    noauto,noatime 1 1
    /dev/sda2   /       ext3    noatime        0 0
    /dev/vg/opt /opt    ext3    noatime        0 0
    /dev/vg/usr /usr    ext3    noatime        0 0
    ...
    

    If you configured LVM as a module when you configured the kernel, add to your /etc/modules.autoload the line

    lvm-mod
    
  13. Step 17 (Installation complete!) - Don't forget to umount all your LVM partitions as well and for a good measure run the following command before you reboot:
    vgchange -an
    
  14. Reboot your machine, but be warned that the boot process will likely give you many error messages since the localmount script will fail to recognize the fact that LVM is in use. Once you log into your system, issue the following command:
    vgscan
    
    This will generate the /etc/lvmtab that the localmount script uses to check if it should start LVM. Restart your machine and now all partitions should be visible and mounted.
Resources

The LVM Howto: http://www.sistina.com/lvm_howtos/lvm_howto/

Daniel Robbins' articles on LVM at IBM's DeveloperWorks: http://www-106.ibm.com/developerworks/linux/library/l-lvm/?dwzone=linux http://www-106.ibm.com/developerworks/linux/library/l-lvm2.html?dwzone=linux

How to boot your root FS off of LVM: http://www.the-infinite.org/archive/docs/lvm/howto-boot-off-root-lv.txt

Acknowledgements I would like to thank Thilo Bangert and Terje Kvernes for their help and comments on this document.