Note

The Funtoo Linux project has transitioned to "Hobby Mode" and this wiki is now read-only.

Difference between revisions of "LVM Install Guide"

From Funtoo
Jump to navigation Jump to search
(Added more information.)
Line 1: Line 1:
{{fancywarning| This page is currently a work in progress }}
== Introduction ==


{{fancynote|This tutorial will show you how to install Funtoo, including the rootfs, on logical volumes. This guide is meant to complement the regular [[Funtoo_Linux_Installation|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.}}


== Introduction ==
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  
This tutorial will show you how to install Funtoo, including the rootfs, on logical volumes. This guide is meant to complement the regular [[Funtoo_Linux_Installation|Funtoo Installation Guide]]. It is recommended to open it in another tab, window ect.. and follow along with it as we will only be documenting the steps that are different or in addition to the regular guide.


=== Introduction to LVM ===
== Live CD ==
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 while the system is still up, it also frees you from having to decide exactly how many or how big volumes need to be at the time of installation.


For a detailed tour and introduction to LVM please consult the [[LVM Fun]] page.
Please read the [[Funtoo Linux Installation#Live CD|Live CD]] section in the regular guide. The only thing you need in addition to the [[Requirements|requirements]] it mentions is the sys-fs/lvm2 package or equivalent. If you use [http://www.sysresccd.org/ System Rescue CD], it includes the lvm2 package.


== Prepare the drives and partitions ==


== Live CD ==
{{fancynote|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.}}
Please read the [[Funtoo Linux Installation#Live CD|Live CD]] section in the regular guide. The only thing you need in addition to the [[Requirements|requirements]] it mentions is the sys-fs/lvm2 package or equivalent. If you use [http://www.sysresccd.org/ System Rescue CD], it includes the lvm2 package.


== Prepare Hard Disk ==
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.
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. All we need is a /boot partition, if your using gpt, you'll need the GRUB partition, and the rest of the space will just be one big partition which we'll create our logical volumes out of.


{{fancynote|We're using the previous mentioned setup to keep things simple in this guide. We are also assuming your only using one hard disk though LVM supports adding multiple hard disks and partitions to a volume group. Please adapt these instructions to suit your needs}}
Find the disk:


The regular install guide does a good job explaining MRB, GPT, and gdisk/fdisk so we won't be repeating that here. Read through the [[Funtoo Linux Installation#Prepare Hard Disk|Prepare Hard Disk]] section and create the previous mentioned partitions.
<console>
If your following our setup your partition table should look like the following when completed:
# fdisk -l
</console>


'''GPT partition table'''
Verify the disk:
<console>Command (? for help): ##i##p
Disk /dev/sda: 83886080 sectors, 40.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): A4E5208A-CED3-4263-BB25-7147DC426931
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 83886046
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)


Number  Start (sector)    End (sector)  Size      Code  Name
<console>
  1            2048        1026047  500.0 MiB  8300  Linux filesystem
# fdisk -l /dev/sdb
  2        1026048        1091583  32.0 MiB    EF02  BIOS boot partition
  3        1091584        83886046  39.5 GiB    8300  Linux filesystem
</console>
</console>


'''MRB partition table'''
Zap the disk:
<console>Command (? for help): ##i##p
 
<console>
# sgdisk --zap-all /dev/sdb
</console>


Disk /dev/sda: 42.9 GB, 42949672960 bytes, 83886080 sectors
Create the partition table:
Units = sectors of 1 * 512 = 512 bytes
 
{{fancynote|If you are using MBR, review paritioning [[Funtoo_Linux_Installation#Partitioning_Using_fdisk_.28MBR.29|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:
 
<console>
# fdisk /dev/sdb
</console>
 
<pre>
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
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x6919e82c
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
</pre>
 
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:


  Device Boot      Start        End      Blocks  Id  System
<console>
/dev/sda1            2048    1026047      512000  83  Linux
# gdisk /dev/sdb
/dev/sda2        1026048    83886079    41430016  83  Linux
</console>
</console>


== Creating Logical Volumes ==
<pre>
In this section we will cover the basics of creating volume groups and logical volumes. For an in depth explanation please see the [[LVM Fun]] page.
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
</pre>
 
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:
 
{{fancynote|As a remindiner, 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.}}


=== Creating a Physical Volume ===
Our first step is to create a physical volume which basically just tells the lvm where to write the data to.
Our first step is to create a physical volume which basically just tells the lvm where to write the data to.
Create a physical volume out of the big partition we created in the previous step. If your using the MRB setup then change /dev/sda3 to /dev/sda2 in the following command
<console># pvcreate /dev/sda3</console>


=== Creating a Volume Group ===
<console>
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 "vg" but you can name it anything you want. Remember to adjust the device path if your using MRB.
# pvcreate -f -f /dev/sdb1
<console># vgcreate vg /dev/sda3</console>
</console>
 
<pre>
  Physical volume "/dev/sdb1" successfully created
</pre>
 
Display the physical volume:
 
<console>
# pvdisplay
</console>
 
<pre>
  "/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
</pre>
 
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.  
 
<console>
# vgcreate funtoo /dev/sdb1
</console>
 
<pre>
  Volume group "funtoo" successfully created
</pre>
 
Display the volume group:
 
<console>
# vgdisplay
</console>
 
<pre>
  --- 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
</pre>
 
Create the logical volumes:


=== Creating 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.
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 3 logical volumes and use them for /(root), /home, and /tmp.
Create the root volume:
<console># lvcreate --size 10G --name root vg
Logical volume "root" created</console>
As you can see we use the --size option to specify a 10 gig volume and the --name option to name the volume 'root'. Again , you can call your volumes anything you want just remember to adjust the paths in the commands for the rest of the guide. You'll notice we specified a relatively small root partition. This is due to our test disk only being 40G. The last item in the command is simply the name of the volume group we created in the previous section. Run 'lvcreate --help' or consult the manpages for more information on the options use.


Now lets create the other 2 logical volumes for our example:
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.
<console># lvcreate --size 5G --name tmp vg
 
Logical volume "tmp" created
<console>
#lvcreate --size 10G --name home vg
# lvcreate -L 32G -n SWAP funtoo
Logical volume "home" created</console>
</console>
 
<pre>
  Logical volume "SWAP" created
</pre>
 
<console>
# lvcreate -L 64G -n ROOT funtoo
</console>
 
<pre>
  Logical volume "ROOT" created
</pre>
 
<console>
# lvcreate -L 128G -n home_my funtoo
</console>
 
<pre>
  Logical volume "home_my" created
</pre>
 
<console>
# lvcreate -L 256G -n home_my_media funtoo
</console>
 
<pre>
  Logical volume "home_my_media" created
</pre>
 
Display the logical volumes:
 
<console>
# lvdisplay
</console>
 
<pre>
  --- 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
</pre>
 
Activate swap:
 
<console>
# mkswap /dev/mapper/funtoo-SWAP
</console>
 
<pre>
Setting up swapspace version 1, size = 33554428 KiB
no label, UUID=ccc83857-28da-4508-a393-84e974e0eeb1
</pre>
 
<console>
# swapon /dev/mapper/funtoo-SWAP
</console>
 
Create the filesystems:


== Creating filesystems ==
{{fancynote|Before proceeding you should read through the brief section [[Funtoo Linux Installation#Creating filesystems|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.}}
{{fancynote|Before proceeding you should read through the brief section [[Funtoo Linux Installation#Creating filesystems|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.}}


<console>
# mkfs.ext2      /dev/sda1
</console>
<pre>
[...]
</pre>
<console>
# mkfs.ext4      /dev/mapper/funtoo-ROOT
</console>
<pre>
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 
</pre>
<console>
# mkfs.ext4      /dev/mapper/funtoo-home_my
</console>
<pre>
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   
</pre>
<console>
# mkfs.xfs        /dev/mapper/funtoo-home_my_media
</console>
<pre>
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
</pre>
Label the filesystems:
<console>
# e2label /dev/sda1 boot
</console>
== Prepare for chroot ==
Activiate the volumes:
<console>
# vgscan
# vgchange -a y
</console>
Mount the filesystems:
<console>
# mkdir -p /mnt/funtoo
# mount /dev/mapper/funtoo-ROOT /mnt/funtoo
# mkdir -p /mnt/funtoo/boot
# mount /dev/sda1 /mnt/funtoo/boot
# mkdir -p /mnt/funtoo/home/my
# mount /dev/mapper/funtoo-home_my /mnt/funtoo/home/my
# mkdir -p /mnt/funtoo/home/my/media
# mount /dev/mapper/funtoo-home_my_media /mnt/funtoo/home/my/media
</console>
Install the bootloader:
<console>
# grub-install /dev/sda1
</console>
== Resume from Funtoo Linux Installation ==
You may safely resume from [http://www.funtoo.org/Funtoo_Linux_Installation#Installing_the_Stage_3_tarball Installing the Stage 3 tarball] with few exceptions:
=== fstab ===
<pre>
# <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
</pre>
=== kernel ===
Enable kernel options:
{{kernelop
|title=
|desc=
General setup --->
      [*] Initial RAM filesystem and RAM disk (initramfs/initrd) support
}}
{{kernelop
|title=
|desc=
Device Drivers --->
      Generic Driver Options --->
      [*] Maintain a devtmpfs filesystem to mount at /dev
}}
{{kernelop
|title=
|desc=
Device Drivers --->
      [*] Multiple devices driver support --->
      <*>Device Mapper Support
}}
Build initramfs (genkernel):
{{fancynote|This builds only an initramfs with lvm support. It does not build the whole kernel so you still have to do that.}}
<console>
# genkernel --lvm initramfs
</console>
=== boot-update ===
<pre>
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
}
</pre>
=== software ===
<console>
# emerge -va lvm2
</console>
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 ([https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Logical_Volume_Manager_Administration/metadatadaemon.html lvmetad])
Thinly-Provisioned Logical Volumes ([https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Logical_Volume_Manager_Administration/thinprovisioned_volumes.html Thin Volumes])
Enabling either is simply a matter of enabling their USE flags.
== Cleaning up ==
<console>
# exit
# cd /
# cat /proc/mounts | grep funtoo | awk '{print $2}' | grep "^$MOUNTPOINT" | sort -r | xargs umount
# umount /mnt/funtoo
# swapoff -v /dev/mapper/funtoo-SWAP
# vgchange -a n
# init 0
</console>
== Special notes ==
=== Resizing ===
{{fancynote|Resizing is filesystem specific. Most can be grown but cannot be shrunk.}}
==== Growing /home/my by 8G ====
<console>
# lvextend -L+8G /dev/mapper/funtoo-home_my
</console>
===== ext2/ext3/ext4 =====
<console>
# resize2fs /mnt/funtoo/home/my
</console>
===== xfs =====
<console>
# xfs_growfs /mnt/funtoo/home/my
</console>
==== Shrinking /home/my by 8G ====
{{fancynote|You generally need to umount first.}}
===== ext2/ext3/ext4 =====
<console>
# umount /mnt/funtoo/home/my
# lvreduce -r -L -8G /dev/mapper/funtoo-home_my
</console>
===== xfs =====
XFS cannot be shrunk.
== Beyond the basics ==
The [[LVM Fun]] page may be of interest.


As well as these pages from Red Hat: [https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Logical_Volume_Manager_Administration/snapshot_command.html Creating Snapshot Volumes]
[https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Logical_Volume_Manager_Administration/thinly_provisioned_volume_creation.html Creating Thinly-Provionsed Logical Volumes]
[https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Logical_Volume_Manager_Administration/mirror_create.html Creating Mirrored Volumes]


[[Category:HOWTO]]
[[Category:HOWTO]]
[[Category:Install]]
[[Category:Install]]
[[Category:Official Documentation]]
[[Category:Official Documentation]]

Revision as of 11:05, July 24, 2014

Introduction

   Note

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

   Note

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:

   Note

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:

   Note

As a remindiner, 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:

   Note

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

Install the bootloader:

root # grub-install /dev/sda1

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):

   Note

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

   Note

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

   Note

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