Btrfs: Difference between revisions

imported>Taxborn
m Typo and slight grammar change
Brauni (talk | contribs)
Removed "Erase your darlings" from "Encryption" Section. With the Setup that was described there was NO persistence.
Line 209: Line 209:
# Create the subvolumes  
# Create the subvolumes  


btrfs subvolume create /mnt/root # The subvolume for /, which will be cleared on every boot
btrfs subvolume create /mnt/root # The subvolume for /


btrfs subvolume create /mnt/home # The subvolume for /home, which should be backed up
btrfs subvolume create /mnt/home # The subvolume for /home, which should be backed up


btrfs subvolume create /mnt/nix # The subvolume for /nix, which needs to be persistent but is not worth backing up, as it’s trivial to reconstruct
btrfs subvolume create /mnt/nix # The subvolume for /nix, which needs to be persistent but is not worth backing up, as it’s trivial to reconstruct
btrfs subvolume create /mnt/persist # The subvolume for /persist, containing system state which should be persistent across reboots and possibly backed up


btrfs subvolume create /mnt/log # The subvolume for /var/log.
btrfs subvolume create /mnt/log # The subvolume for /var/log.
# Take an empty *readonly* snapshot of the root subvolume, which can be rollback to on every boot.
btrfs subvolume snapshot -r /mnt/root /mnt/root-blank
</syntaxhighlight>
Add the following nix config to clear the root volume on every boot([https://grahamc.com/blog/erase-your-darlings/ Erase your darlings]):
<syntaxhighlight lang="nix">
{
  boot.initrd.postDeviceCommands = lib.mkAfter ''
    mkdir /mnt
    mount -t btrfs /dev/mapper/enc /mnt
    btrfs subvolume delete /mnt/root
    btrfs subvolume snapshot /mnt/root-blank /mnt/root
  '';
}
</syntaxhighlight>
</syntaxhighlight>


Line 254: Line 236:


mount -o subvol=nix,compress=zstd,noatime /dev/mapper/enc /mnt/nix
mount -o subvol=nix,compress=zstd,noatime /dev/mapper/enc /mnt/nix
mkdir /mnt/persist
mount -o subvol=persist,compress=zstd,noatime /dev/mapper/enc /mnt/persist


mkdir -p /mnt/var/log
mkdir -p /mnt/var/log
Line 268: Line 246:


mount "$DISK"p1 /mnt/boot
mount "$DISK"p1 /mnt/boot
</syntaxhighlight >
</syntaxhighlight>


Configure <code>hardware-configuration.nix</code>
Configure <code>hardware-configuration.nix</code>