This commit is contained in:
Christoph Cullmann 2024-10-04 16:19:08 +02:00
parent df2c614845
commit b33c9a7c2a
No known key found for this signature in database

View file

@ -54,14 +54,45 @@ mkfs.fat -F 32 -n EFIBOOT $DISK-part1
sleep 5
# create the crypto container
cryptsetup luksFormat --batch-mode --verify-passphrase $DISK-part2
# ZFS zpool creation with encryption
zpool create \
-o ashift=13 \
-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
# open the container
cryptsetup luksOpen $DISK-part2 crypt0
sleep 5
# create one large btrfs on them with strong checksum
mkfs.btrfs -f --checksum blake2 --features block-group-tree --label nix /dev/mapper/crypt0
# show the pool
zpool status
sleep 5
# 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
# we want 64 KB recordsize
zfs set recordsize=64K zpool/data
zfs set recordsize=64K zpool/nix
zfs set recordsize=64K zpool/tmp
sleep 5
# show the pool
zpool status
sleep 5
@ -69,27 +100,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 /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
@ -101,7 +130,7 @@ nixos-generate-config --root /mnt
# copy config data from another machine including secrets
sudo scp -r /nix/data/nixos root@192.168.13.xxx:/mnt/nix/data
sudo scp -r /data/nixos root@192.168.13.102:/mnt/data
# install
@ -109,9 +138,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
sync
umount -Rl /data /mnt
zpool export -a
# shutdown once