prepare for zfs

This commit is contained in:
Christoph Cullmann 2024-10-03 00:50:52 +02:00
parent 3ed8d71a5f
commit d5e6a93db3
No known key found for this signature in database
10 changed files with 75 additions and 119 deletions

View file

@ -70,18 +70,31 @@ mkfs.fat -F 32 -n EFIBOOT $DISK-part1
sleep 5
# create the crypto containers with proper 4k sectors
cryptsetup luksFormat --sector-size 4096 --batch-mode --verify-passphrase $DISK-part2
cryptsetup luksFormat --sector-size 4096 --batch-mode --verify-passphrase $DISK2
cryptsetup luksFormat --sector-size 4096 --batch-mode --verify-passphrase $DISK3
# ZFS zpool creation with encryption
zpool create \
-o ashift=13 \
-o recordsize=64K \
-o autotrim=off \
-O acltype=posixacl \
-O atime=off \
-O canmount=off \
-O compression=on \
-O dnodesize=auto \
-O utf8only=on \
-O normalization=formD \
-O xattr=sa \
-O mountpoint=none \
-O encryption=on \
-O keylocation=prompt \
-O keyformat=passphrase \
zpool $DISK-part2 $DISK2 $DISK3
# open the containers
cryptsetup luksOpen $DISK-part2 crypt0
cryptsetup luksOpen $DISK2 crypt1
cryptsetup luksOpen $DISK3 crypt2
sleep 5
# create one large btrfs on them, RAID0 with strong checksum
mkfs.btrfs -f -d raid0 -m raid0 --checksum blake2 --features block-group-tree --label nix /dev/mapper/crypt0 /dev/mapper/crypt1 /dev/mapper/crypt2
# create all the volumes
zfs create -o mountpoint=legacy zpool/data
zfs create -o mountpoint=legacy zpool/nix
zfs create -o mountpoint=legacy zpool/tmp
sleep 5
@ -89,27 +102,25 @@ sleep 5
mount -t tmpfs none /mnt
# Create directories to mount file systems on
mkdir -p /mnt/{nix,home,boot,root,etc/nixos}
mkdir -p /mnt/{data,nix,home,boot,root,etc/nixos,tmp}
# mount the ESP
mount $DISK-part1 /mnt/boot
# mount large btrfs
mount -t btrfs /dev/mapper/crypt0 -o device=/dev/mapper/crypt1 -o device=/dev/mapper/crypt2 /mnt/nix
# ensure tmp fills not the RAM
mkdir -p /mnt/tmp /mnt/nix/tmp
mount --bind /mnt/nix/tmp /mnt/tmp
# mount volumes
mount -t zfs zpool/data /mnt/data
mount -t zfs zpool/nix /mnt/nix
mount -t zfs zpool/tmp /mnt/tmp
# bind mount persistent stuff to data
mkdir -p /mnt/nix/data/{home,root,nixos/$HOST}
mount --bind /mnt/nix/data/home /mnt/home
mount --bind /mnt/nix/data/root /mnt/root
mount --bind /mnt/nix/data/nixos/$HOST /mnt/etc/nixos
mkdir -p /mnt/data/{home,root,nixos/$HOST}
mount --bind /mnt/data/home /mnt/home
mount --bind /mnt/data/root /mnt/root
mount --bind /mnt/data/nixos/$HOST /mnt/etc/nixos
# create fake /nix/data to have the right paths
mkdir -p /nix/data
mount --bind /mnt/nix/data /nix/data
# create fake /data to have the right paths
mkdir -p /data
mount --bind /mnt/data /data
# take a look
mount
@ -121,7 +132,7 @@ nixos-generate-config --root /mnt
# copy config data from another machine including secrets
sudo scp -r /nix/data/nixos root@192.168.13.171:/mnt/nix/data
sudo scp -r /data/nixos root@192.168.13.171:/mnt/data
# install
@ -129,11 +140,8 @@ nixos-install --option experimental-features 'nix-command flakes' --no-root-pass
# unmount all stuff and sync
umount -Rl /nix/data /mnt
cryptsetup luksClose crypt0
cryptsetup luksClose crypt1
cryptsetup luksClose crypt2
sync
umount -Rl /data /mnt
zpool export -a
# shutdown once
@ -141,4 +149,4 @@ shutdown -h now
# sync all /data after the install
sudo -E rsync -va --delete --one-file-system /nix/data/ root@192.168.13.171:/nix/data/
sudo -E rsync -va --delete --one-file-system /data/ root@192.168.13.171:/data/