LVM: Difference between revisions

From NixOS Wiki
imported>Hyperfekt
Added thin/cache bootup tools option
imported>Hyperfekt
m lvmcache: load cache policy module as well
Line 36: Line 36:
   "dm-snapshot" # when you are using snapshots
   "dm-snapshot" # when you are using snapshots
   "dm-raid" # e.g. when you are configuring raid1 via: `lvconvert -m1 /dev/pool/home`
   "dm-raid" # e.g. when you are configuring raid1 via: `lvconvert -m1 /dev/pool/home`
   "dm-cache" # when using volumes set up with lvmcache
   "dm-cache-default" # when using volumes set up with lvmcache
];
];



Revision as of 11:04, 3 July 2022

The Logical Volume Manager (LVM) provides means to dynamically organize partitions.

Basic Setup

LVM manages three types:

  • physical volumes - directly on a physical partition
  • volume groups - a group of physical volumes
  • logical volumes

Create a logical volume

# formats the partion into a physical volume (check with pvdisplay)
pvcreate /dev/sda2
# creates a new volume group named pool (check with vgdisplay)
vgcreate pool /dev/sda2
# creates a new logical volume named "home" with the size of 10GB (check with lvdisplay)
# makes /dev/pool/home available
lvcreate -L 10G -n home pool
mkfs.ext4 /dev/pool/home

Use the Logical Volume

in your configuration.nix:

fileSystems."/home" = {
  device = "/dev/pool/home";
  fsType = "ext4";
};

Booting with special LVM Modes

LVM provides a number of special features such as creating snapshots, raid for single Logical Volumes and much more. If you want to use these devices on bootup, the associated dm-* kernel module must be provided in the initrd (see for example #33646) . This is a non-exhaustive list of features and the corresponding kernel module and other options to put into your configuration.nix:

boot.initrd.kernelModules = [
  "dm-snapshot" # when you are using snapshots
  "dm-raid" # e.g. when you are configuring raid1 via: `lvconvert -m1 /dev/pool/home`
  "dm-cache-default" # when using volumes set up with lvmcache
];

services.lvm.boot.thin.enable = true; # when using thin provisioning or caching

Automated Partitioning

People have created a number of tools to automate the partitioning in NixOS:

NixOps

NixOps can repartition Hetzner Physical Machines, see [NixOps Manual].

Disko

Disko provides means to automatically generate the creation and configuration of logical volumes, see http://cgit.lassul.us/disko/tree/README.md .