Nachdem ich mir die NAS-Hardware zusammen gebaut habe, wird nun ein Betriebssystem installiert. Fehler, Verbesserungen oder Anmerkungen können mir gern per Email geschickt werden.

Anforderungen

  1. Stabil und sicher
  2. Vollverschlüsselung der OS-Festplatte (inkl. Boot-Partition)
  3. Software-Raid-Funktionalität
  4. Deterministische Installation
  5. Individuelle Installation

Damit kommt für mich, fast schon automatisch, ein Debian Stable in Frage. Ich werde, für mich neu, btrfs (als Erstatz von LVM2 mit ext4) als Dateisystem einsetzen. Es hat so viele Features, die man sonst nur kombiniert mit LVM erreichen kann. Ein nachteil wird es hier vorr. geben. Die SWAP-Partition kann erst ab Linux-Kernel 5 ins btrfs gelegt werden. Damit macht man entweder doch ein LVM drum herum oder eine weitere verschlüsselte Parttion auf die Platte. Ich werde einfach warten. Das System hat 16 GB RAM, da wird so schnell keine Limitation eintreten.

Vorraussetzungen

  • Halbwegs sicherer Umgang mit einer Linux Konsole / Terminal.
  • USB-Stick mit Debian Live
  • Kenntnisse über Partitionierung und Formatierung (siehe auch meine Blog-Einträge: Partitionieren & Formatieren dazu).

Limitationen

  • btrfs mit swap … erst ab Linux-Kernel-Version 5.6.
  • btrfs mounten mit … -o discard=async … … erst ab Linux-Kernel-Version 5.6.
  • luks2 statt luks1 für die Partition mit /boot … erst ab Grub-Version 2.04.

Info

Wir werden auf einem PC GNU/Linux Debian Stable (Codename Buster / Version 10) installieren. Das Partitions-Layout wird wie folgt sein:

DEVICE                TYPE                            SIZE    MOUNTPOINT
nvme0n1               gpt                                
├─nvme0n1p1             part, vfat (F32)              512M    /boot/efi
├─nvme0n1p2             part, crypt
│ └─crypt_nvme0n1p2       ext4                        2048M   /boot
├─nvme0n1p3             part, crypt
│ ├─crypt_nvme0n1p3       btrfs @sysroot              230G    /
│ ├─crypt_nvme0n1p3       btrfs @syshome                      /home
│ ├─crypt_nvme0n1p3       btrfs @sysswap
│ └─crypt_nvme0n1p3       btrfs @snapshots
└─nvme0n1p4             part, crypt
  └─crypt_nvme0n1p4       swap                        16G    swap

ISO-Abbild

DEBVER="10.8.0"
DEBARCH="amd64"
DEBDESKTOP="gnome"
    # cinnamon,gnome,kde,lxde,lxqe,mate,standard,xfce
wget https://cdimage.debian.org/debian-cd/current-live/amd64/iso-hybrid/debian-live-${DEBVER}-${DEBARCH}-${DEBDESKTOP}.iso
    # Download eines ISO-Abbildes.
    # Siehe auch: [Debian - Live Install Images](https://www.debian.org/CD/live/)
wget -O debian-live-${DEBVER}-${DEBARCH}-SHA512SUMS https://cdimage.debian.org/debian-cd/current-live/amd64/iso-hybrid/SHA512SUMS
wget -O debian-live-${DEBVER}-${DEBARCH}-SHA512SUMS.sign https://cdimage.debian.org/debian-cd/current-live/amd64/iso-hybrid/SHA512SUMS.sign
gpg2 --recv-keys DF9B9C49EAA9298432589D76DA87E80D6294BE9B
    # Debian CD signing key <debian-cd@lists.debian.org> (2011-01-05)
gpg2 --recv-keys F41D30342F3546695F65C66942468F4009EA8AC3
    # Debian Testing CDs Automatic Signing Key <debian-cd@lists.debian.org> (2014-04-15)
gpg2 --verify debian-live-${DEBVER}-${DEBARCH}-SHA512SUMS.sign
    # Die Checksummen-Datei verifizieren
sha512sum --ignore-missing -c debian-live-${DEBVER}-${DEBARCH}-SHA512SUMS
dd if=debian-live-${DEBVER}-${DEBARCH}-${DEBDESKTOP}.iso of=/dev/sdX
    # Kopieren des Abbildes auf einen USB-Stick.
    # Mittels 'lsblk' oder 'parted -l' können alle angeschlossenen Blockgeräte angezeigt werden.

Schritt für Schritt

Start

  • Booten vom USB-Stick.
  • Live-System starten.
  • In den Einstellungen
    • die Sprache des Keyboard anpassen und
    • ggf. die Bildschirmauflösung ändern.
  • Terminal öffnen:
    • sudo -i
    • apt update
  • loadkeys de oder loadkeys de-latin1
    • Ändern des Tastaturlayouts (Standard ist us), falls es mit obiger Variante nicht funktioniert.
    • Man tippt also loadkezs deßlatin1 mit einer deutschen Tastatur auf englischem Layout.

Festplatte

  • mount | grep efivars
    • Überprüfung der EFI-Variablen
    • Ausgabe: efivars on /sys/firmware/efi/efivars type efivars (rw,nosuid,nodev,noexec,realatime)
  • lsblk oder parted -l
    • Überprüfung der angeschlossenen Laufwerke.
  • Achtung: Da man von USB-Stick gebootet hat, kann es sein, dass dieser unter /dev/sda angesprochen wird und die Zielplatte z. B. unter /dev/sdb zu finden ist.
  • Anhand der dargestellten Eigenschaften sollte man die Zielplatte erkennen.
  • In dieser Anleitung wird das Speichergerät, auf welchem Debian installiert werden soll, mit /dev/nvme0n1 bezeichnet.
    • Hier ist ein NVMe-Laufwerk in Verwendung.

Falls vorher unverschlüsselte Daten auf der Platte gespeichert waren, die auch wirklich verschwinden sollen:

  • shred --verbose --random-source=/dev/urandom --iterations=3 /dev/sdX
    • oder dd if=/dev/urandom of=/dev/sdX
    • Dieser Schritt ist nur notwendig, falls vorher unverschlüsselte Daten auf der Festplatte waren.
    • Das überschreiben mit Zufallszahlen kann sehr lang dauern.
    • ACHTUNG: SSDs mögen es gar nicht, wenn sie komplett neu beschrieben werden. Es ist aber notwendig, da in irgend einem Speicherbereich noch alte Reste gefunden werden könnten. Wenn man gleich von Anfang an verschlüsselt, muss man diesen Schritt hier nicht machen.

Damit man im Live-System gut mit Copy-Paste durch kommt ein paar Variablen. (Fedora nutzt für die Cryptnamen statt crypt_sda1 die UUID a la luks-2a4b8c2d4e-a1b2-4711-0815-f1e3g5i7k9m0.)

# Install device.
DEV1="/dev/nvme0n1"
# Following could be something like sda, hdb or nvme0n1p.
DEV1PART="nvme0n1p"
DEV1PART1NAME="${DEV1PART}1"
DEV1PART2NAME="${DEV1PART}2"
DEV1PART3NAME="${DEV1PART}3"
DEV1PART4NAME="${DEV1PART}4"

DEV1PART1="/dev/${DEV1PART1NAME}"
DEV1PART2="/dev/${DEV1PART2NAME}"
DEV1PART3="/dev/${DEV1PART3NAME}"
DEV1PART4="/dev/${DEV1PART4NAME}"

DEV1PART1CRYPTNAME="Not_in_use_as_crypt"
DEV1PART2CRYPTNAME="crypt_${DEV1PART2NAME}"
DEV1PART3CRYPTNAME="crypt_${DEV1PART3NAME}"
DEV1PART4CRYPTNAME="crypt_${DEV1PART4NAME}"

DEV1PART1CRYPT="Not_in_use_as_crypt"
DEV1PART2CRYPT="/dev/mapper/${DEV1PART2CRYPTNAME}"
DEV1PART3CRYPT="/dev/mapper/${DEV1PART3CRYPTNAME}"
DEV1PART4CRYPT="/dev/mapper/${DEV1PART4CRYPTNAME}"

Partitionieren

Entweder MSDOS-Partitionstabelle oder GPT. Erst ab Linux-Kernel-Version 5.6 kann btrfs ein Swap aufnehmen. Daher erstellen wir eine separate Swap-Partition am Ende der Platte.

sgdisk -p ${DEV1}
sgdisk -o ${DEV1}
sgdisk -n 0:0:+512MiB ${DEV1}
sgdisk -n 0:0:+2048MiB ${DEV1}
sgdisk -n 0:0:-16GiB ${DEV1}
sgdisk -n 0:0:0 ${DEV1}
sgdisk -p ${DEV1}
  • sgdisk --zap-all /dev/nvme0n1
    • Komplett löschen und neu machen.
  • sgdisk -n a:b:c /device
    • a … number, 0 … next available number, also 1 or n is possible
    • b … start, 0 … next available start block
    • c … end, 0 … end of the largest available block
        • … relative from current start
        • … releative from end
  • sgdisk -d 1 /dev/sda
    • delete a partition
  • Alternative ist das interaktive Programm: cgdisk /dev/nvme0n1

Cryptsetup

ACHTUNG: In der hier beschriebenen Konfiguration ist es möglich, dass später beim Booten ein US-Tastatur-Layout verfügbar ist. Man sollte die US-Position verwendeter Sonderzeichen kennen.

cryptsetup benchmark
# Encrypted boot partition. Grub 2.04 is suporting luks2. Currently we have 2.02.
cryptsetup luksFormat -y --type luks1 --cipher=aes-xts-plain --key-size=512 --hash=sha512 --use-random ${DEV1PART2}
# Encrypted root partition.
cryptsetup luksFormat -y --type luks2 --cipher=aes-xts-plain --key-size=512 --hash=sha512 --use-random ${DEV1PART3}
# Encrypted swap partition
cryptsetup luksFormat -y --type luks2 --cipher=aes-xts-plain --key-size=512 --hash=sha512 --use-random ${DEV1PART4}
# Open partitions.
cryptsetup luksOpen --allow-discards ${DEV1PART2} ${DEV1PART2CRYPTNAME}
cryptsetup luksOpen --allow-discards ${DEV1PART3} ${DEV1PART3CRYPTNAME}
cryptsetup luksOpen --allow-discards ${DEV1PART4} ${DEV1PART4CRYPTNAME}
  • Alternativen
  • --allow-discards für SSDs
  • cryptsetup luksKillSlot ${DEV1PART2} 1
  • cryptsetup luksAddKey --key-slot=1 ${DEV1PART2}

Formatieren

# Format EFI partition.
mkfs.fat -F32 ${DEV1PART1}
# Format boot.
mkfs.ext4 -L boot ${DEV1PART2CRYPT}
# Format system.
mkfs.btrfs -d single -m single -L system ${DEV1PART3CRYPT}
# Mount pure btrfs … (no … -o …,subvol= …)
mount -t btrfs -o noatime,discard,ssd,space_cache,commit=120,compress=zstd,autodefrag,defaults ${DEV1PART3CRYPT} /mnt
# … to create subvolumes.
btrfs subvolume create /mnt/@sysroot
btrfs subvolume create /mnt/@syshome
btrfs subvolume create /mnt/@sysswap
btrfs subvolume create /mnt/@snapshots 
# Umount.
cd /
umount /mnt

Mounten

mount -t btrfs -o noatime,discard,ssd,space_cache,commit=120,compress=zstd,autodefrag,defaults,subvol=@sysroot ${DEV1PART3CRYPT} /mnt
mkdir -p /mnt/{boot,home}
mount -t btrfs -o noatime,discard,ssd,space_cache,commit=120,compress=zstd,autodefrag,defaults,subvol=@syshome ${DEV1PART3CRYPT} /mnt/home
mount -t ext4 -o noatime,discard,defaults ${DEV1PART2CRYPT} /mnt/boot
mkdir -p /mnt/boot/efi
mount -t vfat -o noatime,discard,defaults ${DEV1PART1} /mnt/boot/efi

Swap

# Swap erstellen
mkswap -L swap ${DEV1PART4CRYPT}
swapon -L swap

Erst wenn wir swap in btrfs einbauen können wird nachfolgender Abschnitt relevant.

Swapfile-Support gibt es ab Linux-Kernel 5.0. Für ext4 würde man ein fallocate für die Datei machen und dann mkswap ausführen. Für btrfs benötigt man erst eine Zero-Length-Datei mit einigen Attributen. Erst danach kann man die Datei “wachsen” lassen. Alle größen annähernd der RAM-Größe sind eine gute Wahl.

# Swap from btrfs @sysswap instead of ${DEV1PART4CRYPT}.
mkdir -p /mnt/.swapvol
mount -t btrfs -o noatime,discard=async,ssd,space_cache,commit=120,compress=zstd,autodefrag,defaults,subvol=@sysswap ${DEV1PART3CRYPT} /mnt/.swapvol
cd /mnt/.swapvol
truncate -s 0 main
chattr +C main
btrfs property set main compression none
fallocate -l 16G main
chmod 600 main
mkswap main
swapon main

Zwischenstand

Die Partitionen und Dateisysteme des Zielsystems sind nun im gewünschten Layout.

  • ping -c 3 heise.de
    • Internetverbindung testen.
  • dhcpcd
    • Starten des DHCP-Client.
    • Wenn keine Verbindung hergestellt werden konnte hilft dies meist.

debootstrap

apt update
apt install binutils debootstrap arch-install-scripts
debootstrap --arch=amd64 stable /mnt https://ftp.uni-hannover.de/debian/debian/

Alternative Spiegelserver:

  • https://ftp.uni-hannover.de/debian/debian/
  • http://debian.tu-bs.de/debian/
  • http://ftp.tu-chemnitz.de/debian/
  • https://debian.inf.tu-dresden.de/debian/
    • = http://ftp1.de.debian.org/debian/
  • https://ftp.halifax.rwth-aachen.de/debian/
    • = http://ftp2.de.debian.org/debian/

fstab

genfstab -U -p /mnt >> /mnt/etc/fstab 
cat /mnt/etc/fstab
  • genfstab:
    • -U … Verwendung von UUIDs.
    • -p … Verhindert die Aufnahme von Pseudodateisystemen in die Liste.

cryptsetup 2

#modprobe dm-crypt
# Add keyfiles. Give some random to the trash before writing next keyfile.
# Order is important to use keyfiles correctly.
mkdir -m 0700 /mnt/etc/keys
dd if=/dev/random bs=16 count=512 of=/dev/null conv=fsync
( umask 0077 && dd if=/dev/random bs=1 count=512 of=/mnt/etc/keys/sysboot.key conv=excl,fsync )
dd if=/dev/random bs=12 count=1024 of=/dev/null conv=fsync
dd bs=512 count=4 if=/dev/random of=/etc/keys/sysroot.key iflag=fullblock
( umask 0077 && dd if=/dev/random bs=1 count=512 of=/mnt/etc/keys/sysroot.key conv=excl,fsync )
dd if=/dev/random bs=14 count=768 of=/dev/null conv=fsync
( umask 0077 && dd if=/dev/random bs=1 count=512 of=/mnt/etc/keys/sysswap.key conv=excl,fsync )
ls -lisa /mnt/etc/keys
cryptsetup luksAddKey --key-slot=7 ${DEV1PART2} /mnt/etc/keys/sysboot.key
cryptsetup luksAddKey --key-slot=7 ${DEV1PART3} /mnt/etc/keys/sysroot.key
cryptsetup luksAddKey --key-slot=7 ${DEV1PART4} /mnt/etc/keys/sysswap.key
chmod 600 /mnt/etc/keys/sysboot.key
chmod 600 /mnt/etc/keys/sysroot.key
chmod 600 /mnt/etc/keys/sysswap.key
cryptsetup luksDump ${DEV1PART2}
cryptsetup luksDump ${DEV1PART3}
cryptsetup luksDump ${DEV1PART4}
  • dd bs=512 count=4 if=/dev/random of=/.rootvol/.keyfile iflag=fullblock
    • chmod 600 /.rootvol/.keyfile
    • chmod 600 /boot/initramfs-linux*
    • cryptsetup luksAddKey /dev/sda1 /.rootvol/.keyfile
  • cryptsetup luksKillSlot ${DEV1PART2} 7
  • cryptsetup luksKillSlot ${DEV1PART3} 7
  • cryptsetup luksKillSlot ${DEV1PART4} 7
  • cryptsetup luksKillSlot --key-file ${KEYFILE} ${DEVPART}

crypttab

DEV1PART2UUID=$(blkid -o value -s UUID ${DEV1PART2})
DEV1PART3UUID=$(blkid -o value -s UUID ${DEV1PART3})
DEV1PART4UUID=$(blkid -o value -s UUID ${DEV1PART4})
echo ${DEV1PART2UUID}
echo ${DEV1PART3UUID}
echo ${DEV1PART4UUID}
echo "# <name>              <device>                                  <password>                <options>" > /mnt/etc/crypttab
echo "${DEV1PART2CRYPTNAME}       UUID=${DEV1PART2UUID} /etc/keys/sysboot.key     luks,discard,key-slot=7" >> /mnt/etc/crypttab
echo "${DEV1PART3CRYPTNAME}       UUID=${DEV1PART3UUID} /etc/keys/sysroot.key     luks,discard,key-slot=7" >> /mnt/etc/crypttab
echo "${DEV1PART4CRYPTNAME}       UUID=${DEV1PART4UUID} /etc/keys/sysswap.key     luks,discard,key-slot=7" >> /mnt/etc/crypttab
cat /mnt/etc/crypttab
  • PART2UUID=$(blkid ${DEV1PART2} | cut -d "\"" -f2)
  • PART3UUID=$(blkid ${DEV1PART3} | cut -d "\"" -f2)
  • PART3UUID=$(blkid ${DEV1PART4} | cut -d "\"" -f2)
  • cryptdisks_start ${DEV1PART2CRYPTNAME}

chroot

CHRDIR=/mnt
mount --bind /dev ${CHRDIR}/dev
mount --bind /dev/pts ${CHRDIR}/dev/pts
mount --bind /proc  ${CHRDIR}/proc
mount --bind /sys  ${CHRDIR}/sys
mount --bind /run  ${CHRDIR}/run
LANG=C chroot ${CHRDIR} /bin/bash
# Don't forget to reload variables from above!

update

cat > /etc/apt/sources.list <<__EOF__
# https://wiki.debian.org/SourcesList

# Debian Stable - Official Debian repository for the current release.
deb https://ftp.uni-hannover.de/debian/debian/ stable main contrib non-free

# Debian Stable Security - Official Debian repository for frequent security updates.
deb http://deb.debian.org/debian-security/ stable-security main contrib non-free

# Debian Stable Updates - Official Debian repository for changes that cannot wait for the next point release, packages are also added to StableProposedUpdates for inclusion in the next point release.
deb http://deb.debian.org/debian stable-updates main contrib non-free

# Debian Stable Proposed Updates - However, the quality is usually very high (It should still be considered higher quality than Debian Testing, Backports... ) You are welcome to test those updates if you can recover minor problems (but don't test on production servers ;-). 
#deb http://deb.debian.org/debian/ bullseye-proposed-updates main contrib non-free

# Dabian Backports - More recent versions of some packages, compatible with DebianStable. 
#deb http://deb.debian.org/debian bullseye-backports main contrib non-free
__EOF__

apt update
apt install aptitude linux-image-amd64 firmware-linux-nonfree grub-efi-amd64 grub-efi-amd64-signed efibootmgr arch-install-scripts locales cryptsetup-bin cryptsetup-initramfs gnupg openssh-server firewalld fail2ban ca-certificates keyutils gdisk btrfs-progs screen bash-completion make git timeshift network-manager wget curl 
  • Eine Alternative, um gleich eine ganze Umgebung zu installieren ist: tasksel
    • → Z.B. cinnamon und ssh server auswählen.

firmware

git clone https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git /root/linux-firmware
mkdir -p /lib/firmware/rtl_nic/
cp -r /root/linux-firmware/rtl_nic/* /lib/firmware/rtl_nic/
  • Wenn das paket firmware-linux-nonfree nicht installiert wurde ggf.:
    • mkdir -p /lib/firmware/i915/
    • cp -r /root/linux-firmware/i915/* /lib/firmware/i915/
  • update-initramfs -u -k all
    • Sollte weiter unten keine Fehlermeldungen bzgl. fehlender Firmware ausgeben.

hostname

THISHOSTNAME=jorina
echo ${THISHOSTNAME} > /etc/hostname 
hostnamectl set-hostname ${THISHOSTNAME}

locale

sed -i 's|#.*de_DE.UTF-8.*|de_DE.UTF-8 UTF-8|' /etc/locale.gen
sed -i 's|#.*en_DK.UTF-8.*|en_DK.UTF-8 UTF-8|' /etc/locale.gen
sed -i 's|#.*en_US.UTF-8.*|en_US.UTF-8 UTF-8|' /etc/locale.gen
locale-gen

cat > /etc/default/locale <<__EOF__
LANG=en_US.UTF-8
#LANGUAGE=en_US:en_GB:en
LC_COLLATE=C
LC_CTYPE=en_US.UTF-8
LC_DATE=en_DK.UTF-8
LC_TIME=en_DK.UTF-8
LC_ADDRESS=de_DE.UTF-8
LC_IDENTIFICATION=de_DE.UTF-8
LC_MESSAGES=en_US.UTF-8
LC_MEASUREMENT=de_DE.UTF-8
LC_MONETARY=de_DE.UTF-8
LC_NAME=de_DE.UTF-8
LC_NUMERIC=de_DE.UTF-8
LC_PAPER=de_DE.UTF-8
LC_TELEPHONE=de_DE.UTF-8
LC_ALL=
__EOF__
update-locale
  • Alternative: dpkg-reconfigure locales

grub

Wichtig ist die Aktivierung, so dass verschlüsselte Partitionen gemountet werden können. Beim Überprüfen des Grub-Menus ist es wichtig genau zu schauen, dass die einzelnen Einträge auch insmod cryptodisk und insmod luks enthalten!

# Enable cryptomount.
echo "GRUB_ENABLE_CRYPTODISK=y" >> /etc/default/grub
# Noot be needed, else grub-mkconfig won't write insmod cryptodisk and insmod luks into every boot entry.
#echo "GRUB_PRELOAD_MODULES=\"part_gpt part_msdos cryptodisk luks\"" >> /etc/default/grub
cat /etc/default/grub

grub-install --target=x86_64-efi --recheck --efi-directory=/boot/efi --bootloader-id=grub
cat /boot/efi/EFI/grub/grub.cfg

grub-mkconfig -o /boot/grub/grub.cfg
# Verify included insmod cryptodisk and insmod luks into every menuentry! This the point of most failure during boot.
cat /boot/grub/grub.cfg
  • nano /etc/default/grub
  • grub-install ${DEV1}
  • update-grub
  • update-initramfs -u -k all

initramfs

# Include key path names into initramfs.
echo "KEYFILE_PATTERN=\"/etc/keys/*.key\"" >> /etc/cryptsetup-initramfs/conf-hook
cat /etc/cryptsetup-initramfs/conf-hook

# Root-only access to avoid key leakage.
echo UMASK=0077 >> /etc/initramfs-tools/initramfs.conf

# Re-generate.
update-initramfs -u -k all

# Check.
stat -L -c "%A  %n" /initrd.img
	# → -rw-------  /initrd.img
lsinitramfs /initrd.img | grep "^cryptroot/"
	# → cryptroot/crypttab
	# → cryptroot/keyfiles
	# → cryptroot/keyfiles/crypt_nvme0n1p3.key
	# → cryptroot/keyfiles/crypt_nvme0n1p4.key
	# Different names are OK, 'cause this is initramfs internal naming.
  • update-grub
  • grub-install ${DEV1}

logins

#  Festlegen des Root-Passwortes.
passwd root

# Default user
THISUSER="frank"
useradd -m -G users -s /bin/bash ${THISUSER}
passwd ${THISUSER}

# list users
less /etc/passwd
cat /etc/passwd
getent passwd
# usernames only
cat /etc/passwd | awk -F: '{print $1}'
getent passwd ${THISUSER}
  • useradd -m -g users -G ${THISUSER} -s /bin/bash ${THISUSER}
  • sed -i 's/^# %wheel ALL=(ALL) ALL/%wheel ALL=(ALL) ALL/' /etc/sudoers
    • Wenn ein Nutzer in die Wheels-Gruppe aufgenommen wird, kann er hiermit auch sudo nutzen.

Fertig

Ab diesen Moment sind wir fertig mit der installation. Wir können ins System booten und uns anmelden. Doch wo wir gerade mit einer bequemen Methode im System sind, können wir es auch ein wenig weiter machen und an dieser Stelle die Konfigurationen für Bash und SSH tätigen.

exit

# Exit chroot.
exit

# Unmount.
[ ! -z ${CHRDIR} ] && echo "chroot directory: ${CHRDIR}"
[ ! -z ${CHRDIR} ] && umount ${CHRDIR}/run
[ ! -z ${CHRDIR} ] && umount ${CHRDIR}/sys
[ ! -z ${CHRDIR} ] && umount ${CHRDIR}/proc
[ ! -z ${CHRDIR} ] && umount ${CHRDIR}/dev/pts
[ ! -z ${CHRDIR} ] && umount ${CHRDIR}/dev

# Turn swap off.
swapoff ${DEV1PART4CRYPT}

reboot

Cheatsheet

Grub Rescue

ls
cryptomount (hd3,gpt2)
set prefix=(crypto0)/grub
insmod normal
normal

Network

nmcli dev
nmcli r wifi on
nmcli r wifi off

dhclient

ip a
ip addr
ip link show

luks

cryptsetup luksDump /dev/nvme0n1p2
cryptsetup luksAddKey --key-slot=5 /dev/nvme0n1p2
cryptsetup luksKillSlot /dev/nvme0n1p2 5

Quellen