ZFS: Difference between revisions
m →boot.zfs.devNodes in virtual machines: this can happen in native NixOS installs as well |
Rework encrypted zfs tutorial |
||
Line 47: | Line 47: | ||
Under manual partitioning [https://nixos.org/manual/nixos/stable/#sec-installation-manual-partitioning] do this instead: | Under manual partitioning [https://nixos.org/manual/nixos/stable/#sec-installation-manual-partitioning] do this instead: | ||
'''Partition your disk | '''Partition your disk with your favorite partition tool.''' | ||
We need the following partitions: | |||
* 1G for boot partition with "boot" as the partition label (also called name in some tools) and ef00 as partition code | |||
* 10G for a swap partition with "swap" as the partition label and 8200 as partition code | |||
* The rest of disk space for zfs with "root" as the partition label and 8300 as partition code (default code) | |||
Reason for swap partition: ZFS does use a caching mechanism that is different from the normal Linux cache infrastructure. | |||
In low-memory situations, ZFS therefore might need a bit longer to free up memory from its cache. The swap partition will help with that. | |||
Example output from fdisk: | Example output from fdisk: | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
sudo gdisk /dev/nvme0n1 | |||
GPT fdisk (gdisk) version 1.0.9.1 | |||
... | |||
Command (? for help): p | |||
Disk /dev/nvme0n1: 500118192 sectors, 238.5 GiB | |||
Sector size (logical/physical): 512/512 bytes | |||
Disk identifier (GUID): CA926E8C-47F6-416A-AD1A-C2190CF5D1F8 | |||
Partition table holds up to 128 entries | |||
Main partition table begins at sector 2 and ends at sector 33 | |||
First usable sector is 34, last usable sector is 500118158 | |||
Partitions will be aligned on 2048-sector boundaries | |||
Total free space is 2669 sectors (1.3 MiB) | |||
Number Start (sector) End (sector) Size Code Name | |||
1 2048 2099199 1024.0 MiB EF00 boot | |||
2 2099200 23070719 10.0 GiB 8200 swap | |||
3 23070720 500117503 227.5 GiB 8300 root | |||
Command (? for help): | |||
</syntaxhighlight> | </syntaxhighlight> | ||
'''Make zfs pool with encryption and mount points:''' | '''Make zfs pool with encryption and mount points:''' | ||
Line 72: | Line 88: | ||
zpool create -O encryption=on -O keyformat=passphrase -O keylocation=prompt -O compression=on -O mountpoint=none -O xattr=sa -O acltype=posixacl -o ashift=12 zpool /dev/nvme0n1p2 | zpool create -O encryption=on -O keyformat=passphrase -O keylocation=prompt -O compression=on -O mountpoint=none -O xattr=sa -O acltype=posixacl -o ashift=12 zpool /dev/nvme0n1p2 | ||
zfs create | zfs create zpool/root | ||
zfs create | zfs create zpool/nix | ||
zfs create | zfs create zpool/var | ||
zfs create | zfs create zpool/home | ||
mkdir /mnt/root | mkdir /mnt/root | ||
Line 81: | Line 97: | ||
mkdir /mnt/nix /mnt/var /mnt/home | mkdir /mnt/nix /mnt/var /mnt/home | ||
mount -t zfs zpool/nix /mnt/nix | mount -t zfs zpool/nix /mnt/nix -o zfsutil | ||
mount -t zfs zpool/var /mnt/var | mount -t zfs zpool/var /mnt/var -o zfsutil | ||
mount -t zfs zpool/home /mnt/home | mount -t zfs zpool/home /mnt/home -o zfsutil | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 104: | Line 120: | ||
mkfs.fat -F 32 -n boot /dev/nvme0n1p1 | mkfs.fat -F 32 -n boot /dev/nvme0n1p1 | ||
</syntaxhighlight> | </syntaxhighlight> | ||
'''Installation:''' | '''Installation:''' | ||
Line 133: | Line 150: | ||
}; | }; | ||
# for local disks that are not shared over the network, we don't need this to be random | |||
networking.hostId = "8425e349"; | |||
fileSystems."/ | fileSystems."/" = { | ||
device = "zpool/root"; | |||
fsType = "zfs"; | |||
}; | options = [ "zfsutil" ]; | ||
}; | |||
fileSystems."/ | fileSystems."/nix" = { | ||
device = "zpool/nix"; | |||
fsType = "zfs"; | |||
}; | options = [ "zfsutil" ]; | ||
}; | |||
fileSystems."/ | fileSystems."/var" = { | ||
device = "zpool/var"; | |||
fsType = "zfs"; | |||
}; | options = [ "zfsutil" ]; | ||
}; | |||
fileSystems."/ | fileSystems."/home" = { | ||
{ device = "/dev/disk/by- | device = "zpool/home"; | ||
fsType = "zfs"; | |||
options = [ "zfsutil" ]; | |||
}; | |||
fileSystems."/boot" = { | |||
device = "/dev/disk/by-partlabel/boot"; | |||
fsType = "vfat"; | |||
options = [ "zfsutil" ]; | |||
}; | |||
swapDevices = [ ]; | swapDevices = [{ | ||
device = "/dev/disk/by-partlabel/swap"; | |||
randomEncryption = true; | |||
}]; | |||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> |