LVM + dm-cache (unencrypted)
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
Term | Description |
---|---|
Physical Volume (PV) | On-disk partitioning format to be combined in a VG to a common storage pool |
Volume Group (VG) | Grouping of one or more PVs to provide a combined storage pool from which storage can be requested in the form of LVs. |
Logical Volume (LV) | Logical partition format which can be accessed like a block device to hold file systems and data. |
Preparing the cache device
Listthe available disks need to be determined. This can easily be achieved withfdisk
:fdisk -l
- start
Startthepartitionaingactualtoolpartitioningforprocessprimarystartdisk(cfdisk
isandapointlittle easierit tousetheasdiskityouhaswishatonice TUI)partition:WARNING: Make sure to select your actually desired device!
cfdisk /dev/nvme0n1
Partition
withthe disk in the followingschemeway:FS Type Size Mount Point Comment |vfat|1G1G |/boot|EFI System||LVM|(remaining)||Linux LVM|
First
To
Preparing the origin device
- the
Startdiskpartioningbytoolstartingcfdisk
and pointing it to the disk forsecondarythediskorigin device:WARNING: Make sure to select your actually desired device!
cfdisk /dev/sda
Partition
withthe disk in the followingschemeway:FS Type Size Mount Point Comment |LVM|(all)||Linux LVM|
Partition
Creating physical volumes, volume group and logical volumes
Create LVMcreate physical volumes as the basis for the LVM setup, usepvcreate
and point it to the partitions you created in the two previous steps:pvcreate /dev/nvme0n1p2 # SSD pvcreate /dev/sda1 # HDD
- by
CreatecreatingLVMa volume group withvgcreate
that spans both physical volumes you just created:NOTE:
vg0
is used as an example here. Use whatever you like.vgcreate vg0 /dev/nvme0n1p2 /dev/sda1
Create LVMcreate logical volumes inside the volume group withlvcreate
, using 100% of the available space on the HDD and specifying the cache pool on the SSD:lvcreate -l 100%FREE -n lv_root vg0 /dev/sda1 lvcreate --type cache-pool -n lv_cache -l 100%FREE vg0 /dev/nvme0n1p2
#LinkFinally, link the cache
devicespool to the origin device withlvconvert
:lvconvert --type cache --cachepool vg0/lv_cache vg0/lv_root
To
Continue
Next,
Formatting devices
Createthe partitions with the appropriatemkfs
subcommand:mkfs.fat -F 32 /dev/nvme0n1p1 # EFI System Partition mkfs.btrfs /dev/mapper/vg0-lv_root # Btrfs root file system
Createthe root Btrfssubvolumesfile system:# First, mount root file systemmount /dev/mapper/vg0-lv_root /mnt#CreateNext, create the subvolumes with the
btrfs
user space tools:btrfs subvolume create /mnt/@ btrfs subvolume create /mnt/@home
Mount partitions#Unmount the root file system again:
umount -R /mnt
#Mount the
@
subvolume at/mnt
:mount /dev/mapper/vg0-lv_root -o noatime,compress-force=zstd,space_cache=v2,subvol=@ /mnt
#Create
mountpointsdirectories for subsequent mount points:mkdir -p /mnt/{boot,home}
#Mount the remaining
partitions/subvolumesfile systems:mount /dev/nvme0n1p1 /mnt/boot mount /dev/mapper/vg0-lv_root -o noatime,compress-force=zstd,space_cache=v2,subvol=@home /mnt/home
Format
Mount