-
Follow the handbook until chapter 4. Preparing the Disks
-
Use fdisk 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 /boot partition (hda1). In this example, /boot 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 (hda2) and activate it.
# mkswap /dev/hda2
# swapon /dev/hda2
-
Create a / (root) partition (hda3). 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
/opt /usr /home /var and /tmp in an LVM2 Volume Group
(vg). In this case, 150M is sufficient.
It is not recommended to put the following directories in an
LVM2 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.
-
Assuming the /boot, 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).
Considering the huge size of current disks, you might consider splitting your
hard disks into smaller partitions instead of creating a big partition that
will be added to an LVM2 volume group in one block. LVM2 makes it easy to
extend your volumes after all. This leaves you some unallocated partitions you
might need to use outside of an LVM2 group. In short, don't use your disk space
until you know you need it. As an example, one contributor had split his
160 Gb hard disk into 8 partitions of 20 Gb each.
-
Load the LVM2 dm-mod module. For some reason, this module has been
compiled into the kernel 2.6 (named smp) on the Gentoo LiveCD. If you
used this kernel instead of the default 2.4 (named gentoo), you can skip
this step or ignore the warning you will get.
# modprobe dm-mod
-
Scan and activate LVM:
(Avoid scanning your cdrom)
# echo 'devices { filter=["r/cdrom/"] }' >/etc/lvm/lvm.conf
# vgscan
Reading all physical volumes. This may take a while...
No volume groups found
Prepare the partitions.
# pvcreate /dev/hda4 /dev/hdb1
No physical volume label read from /dev/hda4
Physical volume "/dev/hda4" successfully created
No physical volume label read from /dev/hdb1
Physical volume "/dev/hdb1" successfully created
-
Setup a volume group. A volume group is the result of combining several
physical units into a single logical device.
In our example, /dev/hda1, /dev/hda2 and
/dev/hda3 are the /boot, swap and root partitions so
we need to combine /dev/hda4 and /dev/hdb1. It can be
done with a single command, but, as an example, we will create our volume group
and extend it.
(Create a volume group named vg)
# vgcreate vg /dev/hda4
/etc/lvm/backup: fsync failed: Invalid argument (Ignore this warning)
Volume group "vg" successfully created
(Extending an existing volume group)
# vgextend vg /dev/hdb1
/etc/lvm/backup: fsync failed: Invalid argument (Ignore this warning, again and later as well)
Volume group "vg" successfully extended
-
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:
| Directory |
Size |
/usr10 GB
/home5 GB
/opt5 GB
/var10 GB
/tmp2 GB
Since we are going to use LVM2, we should not worry too much about partition
sizes because they can always be expanded as needed.
As Terje Kvernes commented, 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.
# lvcreate -L10G -nusr vg
Logical volume "usr" created (Further similar messages not displayed)
# lvcreate -L5G -nhome vg
# lvcreate -L5G -nopt vg
# lvcreate -L10G -nvar vg
# lvcreate -L2G -ntmp vg
(As an example, let's extend a logical volume)
# lvextend -L10G -nhome vg
-
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:
# mke2fs -j /dev/vg/usr
# mke2fs -j /dev/vg/home
# mke2fs -j /dev/vg/opt
# mke2fs -j /dev/vg/var
# mke2fs -j /dev/vg/tmp
-
Mount your partitions as described in the handbook and mount your LVM2 logical
volumes as if they were partitions. Replace the usual /dev/hdxx
with /dev/vg/logical_volumename.
(Make sure you have mounted your root partition as described in the handbook first)
# mkdir /mnt/gentoo/usr
# mount /dev/vg/usr /mnt/gentoo/usr
# mkdir /mnt/gentoo/home
# mount /dev/vg/home /mnt/gentoo/home
# mkdir /mnt/gentoo/opt
# mount /dev/vg/opt /mnt/gentoo/opt
# mkdir /mnt/gentoo/var
# mount /dev/vg/var /mnt/gentoo/var
# mkdir /mnt/gentoo/tmp
# mount /dev/vg/tmp /mnt/gentoo/tmp
The rest of the installation handbook is mostly unchanged so we shall not
walk you through it again except to point out differences.
-
When configuring your kernel, make sure to configure your kernel to
support LVM2. Select the LVM2 module as follows:
Multi-device support (RAID and LVM) --->
[*] Multiple devices driver support (RAID and LVM)
< > RAID support
(Note that LVM is not selected on purpose, this was for LVM1)
< > Logical volume manager (LVM) support
<M> Device-mapper support
< > Mirror (RAID-1) support
Device Drivers --->
Multi-device support (RAID and LVM) --->
[*] Multiple devices driver support (RAID and LVM)
< > RAID support
<M> Device mapper support
[*] ioctl interface version 4
The compiled module is called dm-mod.ko
After you have built your kernel and installed its modules, add the following
line to your /etc/modules.autoload.d/kernel-{KV} where {KV}
represents your kernel version (2.4 or 2.6) so that the LVM2 module gets loaded
when your machine is booted:
# nano -w /etc/modules.autoload.d/kernel-2.6
(Add the following line)
dm-mod
Now, install the lvm2 package.
Make sure your /usr/src/linux link points to the kernel sources you
are using because the lvm2 ebuild depends on the device-mapper ebuild which
will check the presence of a required source file under
/usr/src/linux/include/linux.
# emerge lvm2
(Prevent lvm2 from probing your cdrom)
# echo 'devices { filter=["r/cdrom/"] }' >> /etc/lvm/lvm.conf
-
When editing your /etc/fstab file, follow the handbook and add
your LVM2 logical volumes as needed. Again, here are a few lines needed for
our example:
/dev/hda1 /boot ext3 noauto,noatime 1 1
/dev/hda2 none swap sw 0 0
/dev/hda3 / ext3 noatime 0 0
# Logical volumes
/dev/vg/usr /usr ext3 noatime 0 0
/dev/vg/home /home ext3 noatime 0 0
/dev/vg/opt /opt ext3 noatime 0 0
/dev/vg/var /var ext3 noatime 0 0
/dev/vg/tmp /tmp ext3 noatime 0 0
-
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:
# vgchange -an
-
Restart your machine and all partitions should be visible and mounted.