Partitioning (LVM + Cache)
NOTE: This partition scheme is tailored towards a desktop computer setup with enough RAM and no SWAP (and therefore no hibernate/suspend-to-disk support).
CAUTION: This setup does NOT utilize LUKS disk encryption.
LVM cache combines the benefits of a fast mass storage device (e.g. SSD) with a slow mass storage device (HDD), utilizing the former as a read/write cache for the latter. This allows the system to manage blocks of data in a way such that often used blocks are kept on the fast cache device, making the whole system a lot more responsive. Over time the cache device fills up with frequently accessed data and the system accesses the cache device more often than the origin device (the HDD). This can be used to cost-effectively speed up an inexpensive large storage device (think Apple Fusion Drive).
This guide assumes the following:
/dev/nvme0n1
is the primary disk (cache device)/dev/sda
is the secondary disk (origin device)
Nomenclature
Expression | Abbreviation | Meaning |
---|---|---|
Physical Volume | PV | Unix block device node, usable for storage by LVM. Examples: a hard disk, an MBR or GPT partition. |
Volume Group | VG | Group of PVs that serves as a container for LVs. PEs are allocated from a VG for a LV. |
Logical Volume | LV | "Virtual/logical partition" that resides in a VG and is composed of PEs. LVs are Unix block devices analogous to physical partitions, e.g. they can be directly formatted with a file system. |
Physical Extents | PE | The smallest contiguous extent (default 4 MiB) in the PV that can be assigned to a LV. Think of PEs as parts of PVs that can be allocated to any LV. |
Preparing the cache device
-
List available disks
fdisk -l
-
Start partitionaing tool for primary disk (
cfdisk
is a little easier to use as it has a nice TUI)WARNING: Make sure to select your actually desired device!
cfdisk /dev/nvme0n1
-
Partition with the following scheme
FS Type Size Mount Point Comment vfat 1G /boot EFI System LVM (remaining) Linux LVM
Preparing the origin device
-
Start partioning tool for secondary disk
WARNING: Make sure to select your actually desired device!
cfdisk /dev/sda
-
Partition with the following scheme
FS Type Size Mount Point Comment LVM (all) Linux LVM
Creating physical volumes, volume group and logical volumes
-
Create LVM physical volumes
pvcreate /dev/nvme0n1p2 # SSD pvcreate /dev/sda1 # HDD
-
Create LVM volume group
NOTE:
vg0
is used as an example here. Use whatever you like.vgcreate vg0 /dev/nvme0n1p2 /dev/sda1
-
Create LVM logical volumes
lvcreate -l 100%FREE -n lv_root vg0 /dev/sda1 lvcreate --type cache-pool -n lv_cache -l 100%FREE vg0 /dev/nvme0n1p2 # Link cache devices lvconvert --type cache --cachepool vg0/lv_cache vg0/lv_root
Formatting devices
- Create partitions
mkfs.fat -F 32 /dev/nvme0n1p1 # EFI System Partition mkfs.btrfs /dev/mapper/vg0-lv_root # Btrfs root file system
- Create Btrfs subvolumes
# First, mount root file system mount /dev/mapper/vg0-lv_root /mnt # Create subvolumes btrfs subvolume create /mnt/@ btrfs subvolume create /mnt/@home
- Mount partitions
# Unmount the root file system umount -R /mnt # Mount the @ subvolume mount /dev/mapper/vg0-lv_root -o noatime,compress-force=zstd,space_cache=v2,subvol=@ /mnt # Create mountpoints mkdir -p /mnt/{boot,home} # Mount the remaining partitions/subvolumes mount /dev/nvme0n1p1 /mnt/boot mount /dev/mapper/vg0-lv_root -o noatime,compress-force=zstd,space_cache=v2,subvol=@home /mnt/home