Table of Contents
How to Setup Linux Volume Management for a Linux Install
Guide assumes a fresh install will be performed, existing disk partitions will removed before LVM is created. This can be embedded into the Arch Install Guide, which does not exist yet. Encryption article needs to be written as well.
Installation with LVM
The following details an installation using LVM on Archlinux, though it can be adapted to create any LVM management scheme even for non-boot disks.
Wiping
Check if there is anything on the disk
lsblk
Wipe
sgdisk --zap-all /dev/<target_drive>
Make Partitions
cfdisk /dev/<target_drive>
Select MBR/DOS Set size to 1G, this will be /boot Make an Extended Partition, this will show as a 1K partition and will contain the LVM physical volume Inside the extended partition, create a partition using all of the remaining space.
Example of the lsblk for after you are done:
nvme0n1 259:0 0 223.6G 0 disk ├─nvme0n1p1 259:2 0 1G 0 part ├─nvme0n1p2 259:5 0 1K 0 part └─nvme0n1p5 259:6 0 222.6G 0 part
Make LVM
Create the physical volume on the nested partition in the extended partition
pvcreate /dev/<partition in extended partition>
The volume group will be created here and given a name, use the same partition as above.
vgcreate <volume_group> /dev/<partition in extended partition>
Logical Volume creation starts here. The follow commands will setup a root and swap partition. Be sure to use the same volume group name as you created in the previous step. Sizes are specified as G=gigabyte, M=megabyte, and so on.
lvcreate -L <size> <volume_group> -n root lvcreate -l 100%FREE <volume_group> -n swap
Example:
nvme0n1 259:0 0 223.6G 0 disk ├─nvme0n1p1 259:2 0 1G 0 part ├─nvme0n1p2 259:5 0 1K 0 part └─nvme0n1p5 259:6 0 222.6G 0 part ├─archvg-root 254:2 0 214.6G 0 lvm └─archvg-swap 254:3 0 8G 0 lvm
Formating
mkfs.ext4 /dev/<volume_group>/root mkswap /dev/<volume_group/swap swapon /dev/<volume_group/swap
The lvm partitions are always refered to as /dev/<volume_group>/<lvm_part>
Example:
/dev/archvg/root/
Pacstrap and rest of install guide
After you have your partitions you can continue installing Arch with the guide. You only need to take note to use the lvm names of the partitions and make sure to edit the mkinitcpio.conf file in the step below.
Editing mkinitcpio
Before installing the boot loader (grub), do the following so that the kernel can see the lvm structure.
Add systemd and sd-lvm2 to /etc/mkinitcpio.conf
HOOKS=(base systemd ... block sd-lvm2 filesystems)
Generate init using new hooks
mkinitcpio -p linux
Appending disk to LVM and extending the ext4 filesystem
There are numerous scenarios where one may want to resize your LVM root volume, such as after a migration to a larger boot disk.
Create partition of appended disk
First the space that is going to be appended needs to be partitioned.
I prefer to use cfdisk for this.
$ sudo cfdisk /dev/sdX
Take note of the newly created block device partition.
Create physical volume
Create a physical volume with pvcreate of your newly created partition.
$ sudo pvcreate /dev/sdX
Append the physical volume to the volume group
You can type vgdisplay if you are unsure what your volume group is called.
$ sudo vgextend <volume-group> /dev/sdX
Extend logical volume
You can now extend the root logical volume with lvextend
$ sudo lvextend -l +100%FREE /dev/<volume-group/<logical-volume>
You can type lvdisplay if you are unsure what your volume group is called.
Extend ext4 filesystem
You can check your filesystem size, before and after extending with df -h /:
Extend filesystem with resize2fs without umount:
sudo resize2fs /dev/<volume-group/<logical-volume>