The Funtoo Linux project has transitioned to "Hobby Mode" and this wiki is now read-only.
LVM Install Guide
Introduction
This tutorial will show you how to install Funtoo, including the rootfs, on logical volumes. This guide is meant to complement the regular Funtoo Installation Guide. It is recommended that you open it in another tab/window and follow along with it as we will only be documenting the steps that are different or in addition to the regular guide.
LVM (Logical Volume Management) offers a much more flexible way of managing your storage devices. Not only does it allow you to resize your volumes
Live CD
Please read the Live CD section in the regular guide. The only thing you need in addition to the requirements it mentions is the sys-fs/lvm2 package or equivalent. If you use System Rescue CD, it includes the lvm2 package.
Prepare the drives and partitions
For this guide, we are assuming you are using MBR, that you have a /dev/sda1 (a boot drive) and /dev/sdb1 (a system drive), and that you are only using LVM with one drive, even though LVM supports adding multiple hard disks and partitions to a volume group. Please adapt these instructions to suit your needs.
Preparing the hard disk for an LVM install isn't much different from a normal install except that we won't be creating a bunch of partitions as we are going to use logical volumes instead.
Find the disk:
root # fdisk -l
Verify the disk:
root # fdisk -l /dev/sdb
Zap the disk:
root # sgdisk --zap-all /dev/sdb
Create the partition table:
If you are using MBR, review paritioning Partitioning Using fdisk and if you are using GPT, review Partitioning using gdisk. The basic idea is to create what ncessary and then allocate the rest for LVM.
For MBR, this is the boot partition (if you want it on the system drive), every else goes to LVM like so:
root # fdisk /dev/sdb
Disk /dev/sdb: 596.2 GiB, 640135028736 bytes, 1250263728 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0xaa6abfe1 Device Boot Start End Blocks Id System /dev/sdb1 2048 264191 131072 83 Linux /dev/sdb2 264192 1250263727 624999768 83 Linux
For GPT, this is the BIOS boot partion and the boot partition (if you want them on the system drive), every else goes to LVM like so:
root # gdisk /dev/sdb
Disk /dev/sdb: 596.2 GiB, 640135028736 bytes, 1250263728 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x6ba8799c Device Boot Start End Blocks Id System /dev/sdb1 2048 6143 2048 ef EFI (FAT-12/16/32) /dev/sdb2 6144 268287 131072 83 Linux /dev/sdb3 268288 1250263727 624997720 83 Linux
You'll notice in both cases that a swap partition wasn't created. This is becasue if one is desired, it can be done in LVM.
Create the physical volume:
As a reminder, for this guide, we are assuming you are using MBR, that you have a /dev/sda1 (a boot drive) and /dev/sdb1 (a system drive), and that you are only using LVM with one drive. Change this to suit your purposes.
Our first step is to create a physical volume which basically just tells the lvm where to write the data to.
root # pvcreate -f -f /dev/sdb1
Physical volume "/dev/sdb1" successfully created
Display the physical volume:
root # pvdisplay
"/dev/sdb1" is a new physical volume of "596.17 GiB" --- NEW Physical volume --- PV Name /dev/sdb1 VG Name PV Size 596.17 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID IDDrWr-t3PD-7t31-fRQ3-pay2-eMGy-1NgrD0
Create the volume group:
Now that we have a place to store our data we need to create a volume group for it. A volume group is simply a named group of at least one physical volume. This allows multiple physical volumes to be used to store data. In our simple example we only have one physical volume so we'll create a volume group and add our physical volume to it in one command. We are going to call our volume group "funtoo" but you can name it anything you want.
root # vgcreate funtoo /dev/sdb1
Volume group "funtoo" successfully created
Display the volume group:
root # vgdisplay
--- Volume group --- VG Name funtoo System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 1 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 1 Act PV 1 VG Size 596.17 GiB PE Size 4.00 MiB Total PE 152619 Alloc PE / Size 0 / 0 Free PE / Size 152619 / 596.17 GiB VG UUID jFubWA-SGaa-w3C7-Zrst-9Hqo-mWPZ-9JqYZ4
Create the logical volumes:
We now come to the heart of using LVM, logical volumes. Here we get to create logical volumes to store our data. Remember that the best part of LVM is the ability to resize volumes later on the fly so keep that in mind when deciding how big to make volumes. No need to allocate all your space right away. Also keep in mind when choosing a file system type that it must support resizing in order to take advantage of LVM's resizing features.
For our simple example we are only going to create 4 logical volumes and use them for: (SWAP) /(ROOT), /home/my and /home/my/media.
root # lvcreate -L 32G -n SWAP funtoo
Logical volume "SWAP" created
root # lvcreate -L 64G -n ROOT funtoo
Logical volume "ROOT" created
root # lvcreate -L 128G -n home_my funtoo
Logical volume "home_my" created
root # lvcreate -L 256G -n home_my_media funtoo
Logical volume "home_my_media" created
Display the logical volumes:
root # lvdisplay
--- Logical volume --- LV Path /dev/funtoo/SWAP LV Name SWAP VG Name funtoo LV UUID VkdEAk-Jshp-qcQ0-jU7m-m7f4-fyG6-1FZJlh LV Write Access read/write LV Creation host, time funtoo, 2014-07-24 04:39:19 -0400 LV Status available # open 0 LV Size 32.00 GiB Current LE 8192 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:1 --- Logical volume --- LV Path /dev/funtoo/ROOT LV Name ROOT VG Name funtoo LV UUID 2WE7dL-R5BN-dM78-eMx5-hwS8-SjWJ-mUjzL4 LV Write Access read/write LV Creation host, time funtoo, 2014-07-24 04:39:24 -0400 LV Status available # open 0 LV Size 64.00 GiB Current LE 16384 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:2 --- Logical volume --- LV Path /dev/funtoo/home_my LV Name home_my VG Name funtoo LV UUID OJnpYM-399Y-8pa3-iMTY-Nle3-IyK1-keDtng LV Write Access read/write LV Creation host, time funtoo, 2014-07-24 04:40:16 -0400 LV Status available # open 0 LV Size 128.00 GiB Current LE 32768 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:3 --- Logical volume --- LV Path /dev/funtoo/home_my_media LV Name home_my_media VG Name funtoo LV UUID tt7cin-igC4-VD85-fDKV-J692-fV3F-auJYcU LV Write Access read/write LV Creation host, time funtoo, 2014-07-24 04:40:30 -0400 LV Status available # open 0 LV Size 256.00 GiB Current LE 65536 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:4
Activate swap:
root # mkswap /dev/mapper/funtoo-SWAP
Setting up swapspace version 1, size = 33554428 KiB no label, UUID=ccc83857-28da-4508-a393-84e974e0eeb1
root # swapon /dev/mapper/funtoo-SWAP
Create the filesystems:
Before proceeding you should read through the brief section Creating filesystems in the install guide and decide what type of filesystem you would like to use. Do not actually create any file systems though, we will cover that below.
root # mkfs.ext2 /dev/sda1
[...]
root # mkfs.ext4 /dev/mapper/funtoo-ROOT
mke2fs 1.42.10 (18-May-2014) Creating filesystem with 16777216 4k blocks and 4194304 inodes Filesystem UUID: 0ab8f9ab-e824-4d69-a9c4-201d4ccd99ac Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done
root # mkfs.ext4 /dev/mapper/funtoo-home_my
mke2fs 1.42.10 (18-May-2014) Creating filesystem with 33554432 4k blocks and 8388608 inodes Filesystem UUID: 46e394c1-3635-4f13-ba51-10c537d2b5ed Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done
root # mkfs.xfs /dev/mapper/funtoo-home_my_media
meta-data=/dev/mapper/funtoo-home_my_media isize=256 agcount=4, agsize=16777216 blks = sectsz=512 attr=2, projid32bit=0 data = bsize=4096 blocks=67108864, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 log =internal log bsize=4096 blocks=32768, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0
Label the filesystems:
root # e2label /dev/sda1 boot
Prepare for chroot
Activiate the volumes:
root # vgscan root # vgchange -a y
Mount the filesystems:
root # mkdir -p /mnt/funtoo root # mount /dev/mapper/funtoo-ROOT /mnt/funtoo root # mkdir -p /mnt/funtoo/boot root # mount /dev/sda1 /mnt/funtoo/boot root # mkdir -p /mnt/funtoo/home/my root # mount /dev/mapper/funtoo-home_my /mnt/funtoo/home/my root # mkdir -p /mnt/funtoo/home/my/media root # mount /dev/mapper/funtoo-home_my_media /mnt/funtoo/home/my/media
Resume from Funtoo Linux Installation
You may safely resume from Installing the Stage 3 tarball with few exceptions:
fstab
# <filesystem> <mountpoint> <type> <opts> <dump> <pass> /dev/funtoo/SWAP none swap sw 0 0 /dev/funtoo/ROOT / ext4 noatime 0 1 LABEL=boot /boot ext2 noatime 0 0 /dev/funtoo/home_my /home/my ext4 noatime 0 2 /dev/funtoo/home_my_media /home/my/media xfs noatime 0 2
kernel
Enable kernel options:
General setup ---> [*] Initial RAM filesystem and RAM disk (initramfs/initrd) support
Device Drivers ---> Generic Driver Options ---> [*] Maintain a devtmpfs filesystem to mount at /dev
Device Drivers ---> [*] Multiple devices driver support ---> <*>Device Mapper Support
Build initramfs (genkernel):
This builds only an initramfs with lvm support. It does not build the whole kernel so you still have to do that.
root # genkernel --lvm initramfs
boot-update
boot { generate grub default "Funtoo Linux" timeout 3 } "Funtoo Linux" { kernel kernel-genkernel-x86_64-3.14.13 initrd initramfs-genkernel-x86_64-3.14.13 params += dolvm real_root=/dev/mapper/funtoo-ROOT rootfstype=ext4 resume=swap:/dev/mapper/funtoo-SWAP quiet }
software
root # emerge -va lvm2
For the most part, LVM "just works" without any additional configuration. This is especially true for versions below 2.02.107. If you are using >=sys-fs/lvm2-2.02.107 with Funtoo, there are two features be desired that are turned off by default:
The Metadata Daemon (lvmetad)
Thinly-Provisioned Logical Volumes (Thin Volumes)
Enabling either is simply a matter of enabling their USE flags.
Cleaning up
root # exit root # cd / root # cat /proc/mounts | grep funtoo | awk '{print $2}' | grep "^$MOUNTPOINT" | sort -r | xargs umount root # umount /mnt/funtoo root # swapoff -v /dev/mapper/funtoo-SWAP root # vgchange -a n root # init 0
Special notes
Resizing
Resizing is filesystem specific. Most can be grown but cannot be shrunk.
Growing /home/my by 8G
root # lvextend -L+8G /dev/mapper/funtoo-home_my
ext2/ext3/ext4
root # resize2fs /mnt/funtoo/home/my
xfs
root # xfs_growfs /mnt/funtoo/home/my
Shrinking /home/my by 8G
You generally need to umount first.
ext2/ext3/ext4
root # umount /mnt/funtoo/home/my root # lvreduce -r -L -8G /dev/mapper/funtoo-home_my
xfs
XFS cannot be shrunk.
Beyond the basics
The LVM Fun page may be of interest.
As well as these pages from Red Hat: Creating Snapshot Volumes Creating Thinly-Provionsed Logical Volumes Creating Mirrored Volumes