User:SwifT/Wikified but not merged documents/LVM2

Introduction
This guide is based on an example with two SATA hard disks. It means that you will more than likely need to change the drive, partition names and partition sizes to match your own setup and needs.

Initial requirements
If you do a fresh install of Gentoo, you will need to use a bootable CD with LVM2 support such as a Gentoo Installation CD. You can find the Installation CDs for an x86 architecture on our mirrors under. Other architectures might be supported as well.

If you install LVM2 on a currently running system with some spare hard disk space, you will need to enable the LVM2 module in the kernel. This module is available in. Compiling your kernel and getting LVM2 to work is covered later in this guide.

Partitions
Our example system has two SATA hard disks and will be partitioned as follows:


 * /dev/sda1 -- /boot
 * /dev/sda2 -- (swap)
 * /dev/sda3 -- /
 * /dev/sda4 -- Will be used by LVM2
 * /dev/sdb1 -- Will be used by LVM2

OK, time to start...

Installation
Follow the handbook, but with the following amendments to chapter ''4. Preparing the Disks'' :

Use  as described in the handbook, but use the partition scheme mentioned above as an example. It is only an example, adapt it to your own needs.

Create a small physical partition (sda1). In this example, will be not managed by LVM2. This partition will contain your bootloader and your kernel(s). A 64MB partition should be well enough for quite a few kernel generations.

Create a swap partition (sda2).

Create a / (root) partition (sda3). If you are interested in trying to put your root partition under LVM management (which we do not recommend), see the resources section at the end of this guide 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 and  in an LVM2 Volume Group (vg). In this case, 1GB should be sufficient. Note however that, if you have or  in an LVM2 volume group, you will need to boot the system with an initramfs.

Assuming the, swap and root partitions do not use the whole physical disk, create a fourth 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).

Create the filesystems on and , and create and activate the swap on  as described in the handbook.

Start the lvm service.

Starting the lvm service

It is recommended to add the lvm service to the boot runlevel. This way LVM2 will be activated each time the system boots.

Adding lvm to the boot runlevel

Before scanning and activating LVM, you might want to edit to exclude some devices. By default, LVM2 will scan all devices, even your CDROM which can generate error messages. In the following example, the line that allows scanning of all devices is replaced by one that rejects every device but our two SATA disks.

Activating LVM

Prepare the partitions.

Preparing the partitions

Setup a volume group. A volume group is the result of combining several physical units into a single logical device.

In our example,,  and  are the  , swap and root partitions so we need to combine  and. It can be done with a single command, but, as an example, we will create our volume group and extend it.

Creating and extending a volume group

Create the logical volumes. Logical volumes are the equivalent of partitions you would create using fdisk in a non LVM2 environment. In our example, we create the following partitions:

Since we are going to use LVM2, we should not worry too much about partition sizes because they can always be expanded as needed.

Creating and extending logical volumes

Create filesystems on the logical volumes the same way you would on a regular partition. We use ext3 on the logical volumes but any filesystem of your choice will work:

Creating the filesystems

Mount your partitions as described in the handbook and mount your LVM2 logical volumes as if they were partitions. Replace the usual with.

Mounting your logical volumes

When configuring your kernel, make sure to configure your kernel to support LVM2. Select the LVM2 module as follows:

Selecting the LVM2 module in the Linux kernel

The compiled module is called

Also build an initramfs if you have or  on an LVM-based partition. Don't forget to edit your boot loader to boot the system with the initramfs and add in  as a boot parameter.

Building an initramfs

Now, install the lvm2 package.

Emerging the LVM2 package

Edit as described. The file you previously edited is part of your installation environment and will disappear after the next reboot. This time, you edit the real one inside your new Gentoo install.

When editing your file, follow the handbook and add your LVM2 logical volumes as needed. Again, here are a few lines needed for our example:

Extract of /etc/fstab

When you reach the end of the installation part of the handbook, don't forget to umount all your LVM2 logical volumes as well and for a good measure run the following command before you reboot:

Shutting down LVM2

Restart your machine and all partitions should be visible and mounted.

Continuing After a Reboot
If you have interrupted the Gentoo installation at one point and want to continue, you need to create the volume device nodes first:

Reactivating the volumes

Installation CDs with less recent tools might need to reactivate the volumes instead:

Reactivating the volumes

Resources

 * The official LVM2 home page
 * The LVM Howto
 * Daniel Robbins's articles on LVM for IBM's DeveloperWorks: Part 1 and Part 2
 * How to boot your root FS off of LVM1: http://www.the-infinite.org/archive/docs/lvm/howto-boot-off-root-lv.txt

Acknowledgements
Thanks and for their help and comments on this document.

Acknowledgements
We would like to thank the following authors and editors for their contributions to this guide:


 * Avi Schwartz
 * Rajiv Manglani
 * Xavier Neys