Add ZFS install instructions

This commit is contained in:
Thomas Avé 2024-10-29 14:44:50 +01:00
parent bd0ba374e7
commit 7b2bb64bbd
1 changed files with 101 additions and 16 deletions

117
README.md
View File

@ -2,30 +2,102 @@
## NixOS
Install instructions:
Install instructions for NixOS.
First open a shell with vim and git:
```bash
sudo parted /dev/nvme0n1 -- mklabel gpt
sudo parted /dev/nvme0n1 -- mkpart ESP fat32 1MB 512MB
sudo parted /dev/nvme0n1 -- mkpart root ext4 512MB 100%
sudo parted /dev/nvme0n1 -- set 1 esp on
sudo mkfs.fat -F 32 -n BOOT /dev/nvme0n1p1
sudo mkfs.ext4 -L NixOS /dev/nvme0n1p2
sudo mount /dev/disk/by-label/NixOS /mnt
sudo mkdir -p /mnt/boot
sudo mount -o umask=077 /dev/disk/by-label/BOOT /mnt/boot
sudo nixos-generate-config --root /mnt
nix-shell -p git vim
```
### EXT4
```bash
parted /dev/nvme0n1 -- mklabel gpt
parted /dev/nvme0n1 -- mkpart ESP fat32 1MB 512MB
parted /dev/nvme0n1 -- mkpart root ext4 512MB 100%
parted /dev/nvme0n1 -- set 1 esp on
mkfs.fat -F 32 -n BOOT /dev/nvme0n1p1
mkfs.ext4 -L NixOS /dev/nvme0n1p2
mount /dev/disk/by-label/NixOS /mnt
mkdir -p /mnt/boot
mount -o umask=077 /dev/disk/by-label/BOOT /mnt/boot
nixos-generate-config --root /mnt
```
### ZFS
First stop the zfs-zed service, and unload the ZFS kernel modules:
```bash
systemctl stop zfs-zed
lsmod | grep zfs | cut -d' ' -f1 | xargs rmmod -f
```
Then add the following to `/etc/nixos/configuration.nix`:
```bash
boot.supportedFilesystems = [ "zfs" ];
```
And rebuild the system:
```bash
nixos-rebuild switch --upgrade
```
Partition the disk:
```bash
parted --script /dev/nvme0n1 -- mklabel gpt mkpart esp fat32 1MiB 512MiB mkpart primary 512MiB 100% set 1 boot on
```
Create an encrypted pool:
```bash
zpool create -f -o ashift=12 -O encryption=on -O keyformat=passphrase -O mountpoint=none rpool /dev/nvme0n1p2
```
Create a root partition:
```bash
zfs create -o mountpoint=legacy rpool/root
mkdir -p /mnt
mount -t zfs rpool/root /mnt
```
And home partition:
```bash
zfs create -o mountpoint=legacy -o compression=on rpool/home
mkdir -p /mnt/home
mount -t zfs rpool/home /mnt/home
```
Format the boot partition:
```bash
mkfs.fat -F 32 -n BOOT /dev/nvme0n1p1
mkdir -p /mnt/boot
mount -t vfat /dev/nvme0n1p1 /mnt/boot
```
Generate the configuration:
```bash
nixos-generate-config --root /mnt
```
Add the following to /mnt/etc/nixos/configuration.nix:
```bash
boot.initrd.supportedFilesystems = [ "zfs" ];
boot.supportedFilesystems = [ "zfs" ];
services.zfs.autoScrub.enable = true;
networking.hostName = "Aloria";
networking.hostId = "abcdef01";
```
### Install
Then either clone the repository:
```
git clone https://git.thomasave.be/thomasave/Dotfiles
sudo nixos-install --impure --flake ./Dotfiles#Kell
sudo nixos-install --impure --flake ./Dotfiles#Aloria
mv ./Dotfiles /mnt/home/user/.dotfiles
sudo ln -s /home/user/.dotfiles /mnt/etc/nixos
```
@ -33,5 +105,18 @@ sudo ln -s /home/user/.dotfiles /mnt/etc/nixos
Or install it directly:
```
sudo nixos-install --impure --flake git+https://git.thomasave.be/thomasave/Dotfiles#Kell
sudo nixos-install --impure --flake git+https://git.thomasave.be/thomasave/Dotfiles#Aloria
```
### Post-install
Clean-up:
```bash
umount /mnt/{home,boot}
umount /mnt
```
If using ZFS:
```bash
zpool export -a
```