Btrfs: Difference between revisions
imported>Fricklerhandwerk add disko as recommendation |
imported>Vieta TODO Addding "erase your darlings" config |
||
| Line 174: | Line 174: | ||
btrfs subvolume snapshot /snapshots/home_snapshot_202302 /home | btrfs subvolume snapshot /snapshots/home_snapshot_202302 /home | ||
</syntaxhighlight> | </syntaxhighlight> | ||
After this you can mount <code>/home</code> again. | After this you can mount <code>/home</code> again./ | ||
| Line 184: | Line 184: | ||
sudo btrfs send /snapshots/nixos_snapshot_202302 | zstd | ssh root@192.168.178.110 'zstd -d | btrfs receive /mnt/nixos' | sudo btrfs send /snapshots/nixos_snapshot_202302 | zstd | ssh root@192.168.178.110 'zstd -d | btrfs receive /mnt/nixos' | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== Installation with encryption == | |||
Using [https://en.wikipedia.org/wiki/Linux_Unified_Key_Setup Luks2]: | |||
<syntaxhighlight lang="bash"> | |||
cryptsetup --verify-passphrase -v luksFormat "$DISK"p2 | |||
cryptsetup open "$DISK"p2 enc | |||
</syntaxhighlight> | |||
You can use any device paritition for your bootloader # Notice that this bootloader is unencrypted on default: | |||
<code> | |||
mkfs.vfat -n boot "$DISK"p1 | |||
</code> | |||
=== Creatings Subvolumes === | |||
<syntaxhighlight lang="bash"> | |||
mkfs.btrfs /dev/mapper/enc # Creating btrfs partition | |||
mount -t btrfs /dev/mapper/enc /mnt | |||
# Create the subvolumes | |||
btrfs subvolume create /mnt/root # The subvolume for /, which will be cleared on every boot | |||
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/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. I’m not so interested in backing up logs but I want them to be preserved across reboots, so I’m dedicating a subvolume to logs rather than using the persist subvolume | |||
# 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> | |||
Unmount to mount on the subvolumes for the next steps: | |||
<code> | |||
umount /mnt | |||
</code> | |||
Once the subvolumes has been created, mount them with the options. | |||
Example with [https://facebook.github.io/zstd/ Zstandard compression] with noatime: | |||
<syntaxhighlight lang="bash"> | |||
mount -o subvol=root,compress=zstd,noatime /dev/mapper/enc /mnt | |||
mkdir /mnt/home | |||
mount -o subvol=home,compress=zstd,noatime /dev/mapper/enc /mnt/home | |||
mkdir /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 | |||
mount -o subvol=log,compress=zstd,noatime /dev/mapper/enc /mnt/var/log | |||
# do not forget to create and mount the bootloader | |||
mkdir /mnt/boot | |||
mount "$DISK"p1 /mnt/boot | |||
</syntaxhighlight > | |||
Generate Nixconfig: | |||
<syntaxhighlight lang="bash"> | |||
nixos-generate-config --root /mnt | |||
</syntaxhighlight > | |||
[[Category: Configuration]] | [[Category: Configuration]] | ||
[[Category:Filesystem]] | [[Category:Filesystem]] | ||