Debian - Install on BTRFS with Snapper Backups, GRUB-BTRFS and ZRAM
Start the Install Process
- Boot the Debian install media
- Select Advanced Options
- Run through the installer until you get to "Partition Disks"
Create the Partitions
- Select "Manual"
- Select the free space you are going to install Debian on
- Select "Create a new partition". This is the EFI partition
- Set the size to "512 MB"
- Change "Use as:" to "EFI System Partition"
- "Bootable flag:" should be "on"
- Select "Done setting up the partition"
- Create a 1GB, ext4 partition for /boot
- Set "Mount point:" to "/boot"
- Create another partition with the remaining free space
- Set "Use as:" to "btrfs journaling file system"
- Set "Mount point:" to "/"
- Select "Finish partitioning and write changes to disk"
- Do not create a swap partition. We are going to use ZRAM. Select "No" to continue
- Write the changes to disk
Create the BTRFS System and Subvolumes
- Press alt -> ctrl -> F2 to go to a BusyBox terminal
- Use the "df -h" command to see the current mounted file system (/boot /boot/efi /)
- Unmount the target file system
# umount /target/boot/efi/
# umount /target/boot/
# umount /target/ - Mount the root filesystem to /mnt
mount /dev/nvme0n1p7 /mnt - Change directory to /mnt and use "ls" to confirm the root BTRFS subvolume
# cd /mnt
# ls
@rootfs - Create the additional BTRFS subvolumes
btrfs subvolume create @snapshots @home @log @cache @crash @tmp @spool @AccountsService @gdm - 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 - 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 - 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 - 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 - 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 - 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 - Press CTRL -> K to cut the line, then press CTRL -> U ten times to paste a line for each subvolume
- 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 - CTRL -> X to exit
- Y to save
- ENTER to confirm the file name
- Move back to the root directory, unmount /mnt and exit the console back to the install process
cd /
umount /mnt
exit
CTRL -> ALT -> F1 - Continue the install with your preferences
Comments