User:2r/NixOS on ZFS: Difference between revisions
imported>2r No edit summary |
imported>2r No edit summary |
||
| Line 189: | Line 189: | ||
rpool/sys</pre> | rpool/sys</pre> | ||
==== System datasets ==== | ==== System datasets ==== | ||
<pre>zfs create -o canmount=off -o mountpoint=none bpool/ | <pre>zfs create -o canmount=off -o mountpoint=none bpool/NixOS/BOOT | ||
zfs create -o canmount=off -o mountpoint=none rpool/ | zfs create -o canmount=off -o mountpoint=none rpool/NixOS/ROOT | ||
zfs create -o canmount=off -o mountpoint=none rpool/ | zfs create -o canmount=off -o mountpoint=none rpool/NixOS/DATA | ||
zfs create -o canmount=off -o mountpoint=/ rpool/ | zfs create -o canmount=off -o mountpoint=/ rpool/NixOS/DATA/local | ||
zfs create -o canmount=off -o mountpoint=/ rpool/ | zfs create -o canmount=off -o mountpoint=/ rpool/NixOS/DATA/safe | ||
zfs create -o mountpoint=legacy -o canmount=noauto bpool/ | zfs create -o mountpoint=legacy -o canmount=noauto bpool/NixOS/BOOT/default | ||
zfs create -o mountpoint=legacy -o canmount=noauto rpool/ | zfs create -o mountpoint=legacy -o canmount=noauto rpool/NixOS/ROOT/default | ||
mount -t zfs rpool/ | mount -t zfs rpool/NixOS/ROOT/default /mnt | ||
mkdir /mnt/boot | mkdir /mnt/boot | ||
mount -t zfs bpool/ | mount -t zfs bpool/NixOS/BOOT/default /mnt/boot | ||
for i in {nix,}; do | for i in {nix,}; do | ||
zfs create -o canmount=on -o mountpoint=legacy rpool/ | zfs create -o canmount=on -o mountpoint=legacy rpool/NixOS/DATA/local/$i | ||
mkdir -p /mnt/$i | mkdir -p /mnt/$i | ||
mount -t zfs rpool/ | mount -t zfs rpool/NixOS/DATA/local/$i /mnt/$i | ||
done | done | ||
for i in {root,home,home/user}; do | for i in {root,home,home/user}; do | ||
zfs create -o canmount=on -o mountpoint=legacy rpool/ | zfs create -o canmount=on -o mountpoint=legacy rpool/NixOS/DATA/safe/$i | ||
mkdir -p /mnt/$i | mkdir -p /mnt/$i | ||
mount -t zfs rpool/ | mount -t zfs rpool/NixOS/DATA/safe/$i /mnt/$i | ||
done | done | ||
chmod 750 /mnt/root | chmod 750 /mnt/root | ||
chmod 700 /mnt/home/user</pre> | chmod 700 /mnt/home/user</pre> | ||
=== System Installation === | |||
Except a few additional options, the procedure is identical with normal installation. | |||
==== General ==== | |||
Generate Host ID<pre>head -c 8 /etc/machine-id</pre> | |||
Generate and edit config file<pre>nixos-generate-config --root /mnt | |||
vim /mnt/etc/nixos/configuration.nix</pre> | |||
Add ZFS: | |||
<pre>boot.supportedFilesystems = [ "zfs" ]; | |||
networking.hostId = "deadbeef";</pre> | |||
If not using <code>/dev/disk/by-id</code>:<pre>boot.zfs.devNodes = "/dev/disk/by-path";</pre> | |||
If swap partition:<pre>swapDevices = [ | |||
{ | |||
device = "/dev/disk/by-id/disk1-part4"; | |||
randomEncryption.enable = true; | |||
} | |||
];</pre> | |||
==== GRUB ==== | |||
===== UEFI ===== | |||
For UEFI, delete systemd-boot and other <code>boot.loader</code> options and use GRUB: | |||
<pre>boot.loader = { | |||
# grub.efiInstallAsRemovable = true; | |||
efi.canTouchEfiVariables = true; | |||
efi.efiSysMountPoint = "/boot/efi"; | |||
grub.enable = true; | |||
grub.version = 2; | |||
grub.copyKernels = true; | |||
grub.efiSupport = true; | |||
grub.devices = [ "nodev" ]; | |||
};</pre> | |||
For multiple disks, mirror EFI system partition <code>/boot/efi</code> with <code>boot.loader.grub.mirroredBoots</code> option. See <code>man configuration.nix</code>. | |||
===== BIOS ===== | |||
For BIOS, delete <code>boot.loader</code> options and use GRUB: | |||
<pre>boot.loader = { | |||
grub.enable = true; | |||
grub.version = 2; | |||
grub.copyKernels = true; | |||
grub.devices = [ "/dev/disk/by-id/disk1" "/dev/disk/by-id/disk2" ]; | |||
};</pre> | |||
==== Installation ==== | |||
After finishing configuration, install system: | |||
<pre>nixos-install --root /mnt</pre> | |||
=== Finishing installation === | |||
Take an initial snapshot: | |||
<pre>zfs snapshot -r rpool/sys@install | |||
zfs snapshot -r bpool/sys@install</pre> | |||
Unmount EFI system partition:<pre>umount /mnt/boot/efi</pre>Also unmount mirrored ESP, if any. | |||
Export pools:<pre>zpool export bpool | |||
zpool export rpool</pre> | |||