LVM: Difference between revisions

Axka (talk | contribs)
Add ArchWiki link and document PE to explain that LVs don't have to be contiguous on a PV.
Axka (talk | contribs)
Tidy up text and code blocks.
 
Line 11: Line 11:


=== Create an LV ===
=== Create an LV ===
 
Below are shell commands to setup a PV, a VG and an LV from scratch. LVM comes enabled by default on NixOS.<syntaxhighlight lang="shell">
<syntaxHighlight lang=bash>
# format the partion into a physical volume (check with pvdisplay)
# formats the partion into a physical volume (check with pvdisplay)
pvcreate /dev/sda2
pvcreate /dev/sda2
# creates a new volume group named pool (check with vgdisplay)
# create a new volume group named pool (check with vgdisplay)
vgcreate pool /dev/sda2
vgcreate pool /dev/sda2
# creates a new logical volume named "home" with the size of 10GB (check with lvdisplay)
# create a new logical volume named "home" with the size of 10GB (check with lvdisplay)
# makes /dev/pool/home available
# makes /dev/pool/home available
lvcreate --size 10G --name home pool
lvcreate --size 10G --name home pool
# finally, create a filesystem inside the logical volume
mkfs.ext4 /dev/pool/home
mkfs.ext4 /dev/pool/home
</syntaxHighlight>
</syntaxhighlight>


=== Use the LV ===
=== Use the LV ===
in your <code>configuration.nix</code>:
Mount the filesystem on the logical volume by adding an entry to the {{Nixos:option|fileSystems}} NixOS option.
 
{{File|3=fileSystems."/home" = {
<syntaxHighlight lang=nix>
fileSystems."/home" = {
   device = "/dev/pool/home";
   device = "/dev/pool/home";
   fsType = "ext4";
   fsType = "ext4";
};
};|name=/etc/nixos/configuration.nix|lang=nix}}
</syntaxHighlight>


== Booting with special LVM Modes ==
== Booting with special LVM Modes ==
LVM provides a number of special features such as creating snapshots, RAID for single LVs and much more. If you want to use these devices on bootup, the associated <code>dm-*</code> kernel module must be provided in the initrd (see for example {{Issue|33646}}). This is a non-exhaustive list of features and the corresponding kernel module and other options to put into your <code>configuration.nix</code>:
LVM provides a number of special features such as creating snapshots, RAID for single LVs and much more. If you want to use these devices on bootup, the associated <code>dm-*</code> kernel module must be provided in the initrd (see for example Nixpkgs issue {{Issue|33646}}). Here is a non-exhaustive list of features and the corresponding kernel module and other options to put into your NixOS configuration:
<syntaxHighlight lang=nix>
 
boot.initrd.kernelModules = [
{{File|3=boot.initrd.kernelModules = [
   "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`
Line 42: Line 39:
];
];


services.lvm.boot.thin.enable = true; # when using thin provisioning or caching
services.lvm.boot.thin.enable = true; # when using thin provisioning or caching|name=/etc/nixos/configuration.nix|lang=nix}}
</syntaxHighlight>


== Automated Partitioning ==
== Automated Partitioning ==