Debian - Install on BTRFS with Snapper Backups, GRUB-BTRFS and ZRAM

Start the Install Process 

  1. Boot the Debian install media

  2. Select Advanced Options

  3. Run through the installer until you get to "Partition Disks"

Create the Partitions

    1. Select "Manual"
    2. Select the free space you are going to install Debian on
      1. Select "Create a new partition". This is the EFI partition
      2. Set the size to "512 MB"
      3. Change "Use as:" to "EFI System Partition"
      4. "Bootable flag:" should be "on"
      5. Select "Done setting up the partition"

      6. Create a 1GB, ext4 partition for /boot
      7. Set "Mount point:" to "/boot"

      8. Create another partition with the remaining free space
      9. Set "Use as:" to "btrfs journaling file system"
      10. Set "Mount point:" to "/"

    3. Select "Finish partitioning and write changes to disk"

    4. Do not create a swap partition. We are going to use ZRAM. Select "No" to continue

    5. Write the changes to disk

Create the BTRFS System and Subvolumes

  1. Press alt -> ctrl -> F2 to go to a BusyBox terminal

  2. Use the "df -h" command to see the current mounted file system (/boot /boot/efi /)

  3. Unmount the target file system

    # umount /target/boot/efi/
    # umount /target/boot/
    # umount /target/

  4. Mount the root filesystem to /mnt

    mount /dev/nvme0n1p7 /mnt

  5. Change directory to /mnt and use "ls" to confirm the root BTRFS subvolume

    # cd /mnt
    # ls
    @rootfs

  6. Create the additional BTRFS subvolumes

    btrfs subvolume create @snapshots @home @log @cache @crash @tmp @spool @AccountsService @gdm

  7. Mount the root subvolume to be able to create the additional directories for the subvolumes

    mount -o noatime,space_cache=v2,compress=zstd:4,ssd,discard=async,subvol=@rootfs /dev/nvme0n1p7 /target

  8. Create the mount points for each subvolume

    cd /target
    mkdir -p .snapshots home var/log var/cache var/crash var/tmp var/spool var/lib/AccountsServices var/lib/gdm3

  9. Create mount points for /var/lib/portables and /var/lib/machines. systemd creates them automatically as nested subvolumes. Nested subvolumes will force you to do some manual removal after restoring a snapshot and removing old snapshots

    mkdir -p var/lib/portables var/lib/machines

  10. Mount each subvolume

    mount -o noatime,space_cache=v2,compress=zstd:4,ssd,discard=async,subvol=@snapshots /dev/nvme0n1p7 /target/.snapshots
    mount -o noatime,space_cache=v2,compress=zstd:4,ssd,discard=async,subvol=@home /dev/nvme0n1p7 /target/home
    mount -o noatime,space_cache=v2,compress=zstd:4,ssd,discard=async,subvol=@log /dev/nvme0n1p7 /target/var/log
    mount -o noatime,space_cache=v2,compress=zstd:4,ssd,discard=async,subvol=@cache /dev/nvme0n1p7 /target/var/cache
    mount -o noatime,space_cache=v2,compress=zstd:4,ssd,discard=async,subvol=@crash /dev/nvme0n1p7 /target/var/crash
    mount -o noatime,space_cache=v2,compress=zstd:4,ssd,discard=async,subvol=@tmp /dev/nvme0n1p7 /target/var/tmp
    mount -o noatime,space_cache=v2,compress=zstd:4,ssd,discard=async,subvol=@spool /dev/nvme0n1p7 /target/var/spool
    mount -o noatime,space_cache=v2,compress=zstd:4,ssd,discard=async,subvol=@AccountsService /dev/nvme0n1p7 /target/var/lib/AccountsService
    mount -o noatime,space_cache=v2,compress=zstd:4,ssd,discard=async,subvol=@gdm /dev/nvme0n1p7 /target/var/lib/gdm3

  11. Mount the "boot" and "efi" partitions (check the comments in etc/fstab if you have any doubts)

    mount /dev/nvme0n1p6 boot
    mount /dev/nvme0n1p2 boot/efi

  12. Add the root BTRFS subvolumes to the fstab file

    nano etc/fstab

    /dev/nvme0n1p7    /        btrfs    noatime,space_cache=v2,compress=zstd:4,ssd,discard=async,subvol=@rootfs        0    0

  13. Press CTRL -> K to cut the line, then press CTRL -> U ten times to paste a line for each subvolume
    1. Edit the second through to the tenth lines to correct the mount point and subvolume. The mounts should appear as follows:

      /dev/nvme0n1p7 / btrfs noatime,space_cache=v2,compress=zstd:4,ssd,discard=async,subvol=@rootfs 0 0
      /dev/nvme0n1p7 /.snapshots btrfs noatime,space_cache=v2,compress=zstd:4,ssd,discard=async,subvol=@snapshots 0 0
      /dev/nvme0n1p7 /home btrfs noatime,space_cache=v2,compress=zstd:4,ssd,discard=async,subvol=@home 0 0
      /dev/nvme0n1p7 /var/log btrfs noatime,space_cache=v2,compress=zstd:4,ssd,discard=async,subvol=@log 0 0
      /dev/nvme0n1p7 /var/cache btrfs noatime,space_cache=v2,compress=zstd:4,ssd,discard=async,subvol=@cache 0 0
      /dev/nvme0n1p7 /var/crash btrfs noatime,space_cache=v2,compress=zstd:4,ssd,discard=async,subvol=@crash 0 0
      /dev/nvme0n1p7 /var/tmp btrfs noatime,space_cache=v2,compress=zstd:4,ssd,discard=async,subvol=@tmp 0 0
      /dev/nvme0n1p7 /var/spool btrfs noatime,space_cache=v2,compress=zstd:4,ssd,discard=async,subvol=@spool 0 0
      /dev/nvme0n1p7 /var/lib/AccountsService btrfs noatime,space_cache=v2,compress=zstd:4,ssd,discard=async,subvol=@AccountsService 0 0
      /dev/nvme0n1p7 /var/lib/gdm3 btrfs noatime,space_cache=v2,compress=zstd:4,ssd,discard=async,subvol=@gdm 0 0

    2. CTRL -> X to exit
    3. Y to save
    4. ENTER to confirm the file name

  14. Move back to the root directory, unmount /mnt and exit the console back to the install process

    cd /
    umount /mnt
    exit
    CTRL -> ALT -> F1

  15. Continue the install with your preferences

Comments

Popular posts from this blog

Linux: Permanent CIFS/SMB mount

Docker