[HowTo] Debian Live installation with BTRFS, Subvolume, Snapper rollout

Share your HowTo, Documentation, Tips and Tricks. Not for support questions!.
Post Reply
Message
Author
robertocannito
Posts: 8
Joined: 2023-08-20 07:14
Been thanked: 3 times

[HowTo] Debian Live installation with BTRFS, Subvolume, Snapper rollout

#1 Post by robertocannito »

This tutorial has the purpose to install Debian with BTRFS file system, automatic subvolumes and Snapper rollout.

As you know Debian Live use Calamares for install and every program must have config somewhere :)

So, start booting with usb live, I've used Gnome Edition and stop to start installation, first we must open terminal:

Code: Select all

sudo -i

nano /etc/calamares/modules/mount.conf 
and past at the end of the file:

Code: Select all

btrfsSubvolumes:
    - mountPoint: /
      subvolume: /@
    - mountPoint: /home
      subvolume: /@home
    - mountPoint: /root
      subvolume: /@root
    - mountPoint: /srv
      subvolume: /@srv      
    - mountPoint: /var/cache
      subvolume: /@cache
    - mountPoint: /var/log
      subvolume: /@log
    - mountPoint: /var/tmp
      subvolume: /@tmp      
    - mountPoint: /var/lib/AccountsService
      subvolume: /@var@lib@AccountsService
    - mountPoint: /var/lib/gdm3
      subvolume: /@var@lib@gdm3
    - mountPoint: /.snapshots
      subvolume: /@snapshots
When you edit /etc/calamares/modules/mount.conf, you must be very careful to respect space and tabulation or you will receive error during installation

For better use here you may find the file with correct space and tabulation:

Code: Select all

https://u.pcloud.link/publink/show?code=XZ5S0aVZsykifrjkVJFKlWSCeMPsBBPmALf7
you may change add or delete subvolumes that you need

After that you may start standard installation with BTRFS file system as usual, at the end restart BUT THERE'S A TRICK

Debian use in fstab incorrect variation and system stop to work correctly, you must restart again with Debian Live and arrange same change in fstab:

boot again with live and open terminal

Code: Select all

sudo -i
you must mount your root disk in mnt, if you don't know the disk id, open app Disk and check there if is sda2 or other

Code: Select all

 
mount /dev/sda2 /mnt

cd /mnt

cd @

there you will find etc and then fstab

Code: Select all

cd etc

nano fstab 
my fstab is:

Code: Select all

 
UUID=47d34a4f-b1f9-4540-9f2d-a2aa563c41e5 / btrfs subvol=/@,defaults,noatime,space_cache=v2,compress=zstd,discard 0 0

UUID=47d34a4f-b1f9-4540-9f2d-a2aa563c41e5 /root btrfs subvol=/@root,defaults,noatime,space_cache=v2,compress=zstd,discard 0 0

UUID=47d34a4f-b1f9-4540-9f2d-a2aa563c41e5 /srv btrfs subvol=/@srv,defaults,noatime,space_cache=v2,compress=zstd,discard 0 0

UUID=47d34a4f-b1f9-4540-9f2d-a2aa563c41e5 /var/cache btrfs subvol=/@cache,defaults,noatime,space_cache=v2,compress=zstd,discard 0 0

UUID=47d34a4f-b1f9-4540-9f2d-a2aa563c41e5 /var/log btrfs subvol=/@log,defaults,noatime,space_cache=v2,compress=zstd,discard 0 0

UUID=47d34a4f-b1f9-4540-9f2d-a2aa563c41e5 /var/tmp btrfs subvol=/@tmp,defaults,noatime,space_cache=v2,compress=zstd,discard 0 0

UUID=47d34a4f-b1f9-4540-9f2d-a2aa563c41e5 /var/lib/AccountsService btrfs subvol=/@var@lib@AccountsService,defaults,noatime,space_cache=v2,compress=zstd,discard 0 0

UUID=47d34a4f-b1f9-4540-9f2d-a2aa563c41e5 /var/lib/gdm3 btrfs subvol=/@var@lib@gdm3,defaults,noatime,space_cache=v2,compress=zstd,discard 0 0

UUID=47d34a4f-b1f9-4540-9f2d-a2aa563c41e5 /.snapshots btrfs subvol=/@snapshots,defaults,noatime,space_cache=v2,compress=zstd,discard 0 0

UUID=5ad96b47-98e1-410b-a7ca-6246c9d43d81 /home btrfs defaults,noatime,space_cache=v2,compress=zstd,discard 0 0 
The trick part is to change all is over noatime with the up above, save fstab and restart normally.

This is the fist step, to have a correct file system in btrfs with correct subvolumes

As you may see my /home is in normal partition and not in subvolume, this is a problem for Calameres because I have 2 disks and home is in second disk and Calamares doesn't recognize this, on my other laptop with only 1 hard disk all has gone well.


SNAPPER

We will install Snapper and the required packages to set GRUB-BTRFS with:

Code: Select all

sudo apt install snapper inotify-tools git make
We need to make some prep-work to set snapper to save our snapshots to the subvolume snapshots that we created previously.

Code: Select all

cd /

sudo umount .snapshots

sudo rm -r .snapshots 
At this point we can create a new configuration for Snapper:

Code: Select all

sudo snapper -c root create-config /
The new configuration should have created a new “.snapshots” directory and as well a new BTRFS subvolume of the same name.

We will remove this new subvolume and link our own created snapshots subvolume to this path, so our snapshots will be safely stored in a different location.

To remove the auto-created subvolume use:

Code: Select all

sudo btrfs subvolume delete /.snapshots
Let’s re-create the directory:

Code: Select all

sudo mkdir /.snapshots
Now we can re-mount our subvolume snapshots to “/.snapshots” with:

Code: Select all

sudo mount -av
Disabling auto-snapshot on boot:

Code: Select all

sudo systemctl disable snapper-boot.timer
Disabling the Snapper timeline:

Code: Select all

sudo snapper -c root set-config 'TIMELINE_CREATE=no'
Add the “sudo” group to allow our user to use snapper:

Code: Select all

sudo snapper -c root set-config 'ALLOW_GROUPS=sudo

sudo snapper -c root set-config 'SYNC_ACL=yes' 
I will keep only 30 pairs of snapshots, you can set a different number if you desire, use the command to set this limit:

Code: Select all

sudo snapper -c root set-config "NUMBER_LIMIT=30"

sudo snapper -c root set-config "NUMBER_LIMIT_IMPORTANT=30" 
Let's create a first new snapshot:

Code: Select all

sudo snapper -c root create --description "default fresh install"
GRUB-BTRFS

GRUB-BTRFS is not available on the Debian repos so we are going to install from source, let’s clone the repo and install it:

Code: Select all

git clone https://github.com/Antynea/grub-btrfs.git

cd grub-btrfs

sudo make install 
The installation should be successful and if it is it should also already detect our created snapshot.

Now we must enable the monitoring service so that GRUB-BTRFS can automatically update every time we create or delete a snapshot and update our grub menu with:

Code: Select all

# To start the daemon run:

sudo systemctl start grub-btrfsd

# To activate it during system startup, run:

sudo systemctl enable grub-btrfsd 

Snapper-Rollback

Also needs to be installed from Git:

Code: Select all

cd ..

# if you were inside the previous git repo

git clone https://github.com/jrabinow/snapper-rollback.git

cd snapper-rollback

sudo cp snapper-rollback.py /usr/local/bin/snapper-rollback

sudo cp snapper-rollback.conf /etc/

sudo nano /etc/snapper-rollback.conf 
Since we are using Debian, the main subvolume will be named rootfs instead of @. Thus, it's necessary to edit that line to make it look like this:

Code: Select all

# config for btrfs root

[root]

# Name of your linux root subvolume

subvol_main = @rootfs 
That is all, I've tested on my two notebook and I hope this will help you in this matter

Additional tools:

If you want you may also install btrfs-assistant, this is an easy tools for snapshots management, very nice to use:

https://gitlab.com/btrfs-assistant/btrfs-assistant

Another tools also good for description in snapper is

https://gist.github.com/imthenachoman/f ... 2d83263118

in debian snapper has not description, just one pre and one post apt, with this script you will have a full descption.
Last edited by robertocannito on 2023-09-16 14:26, edited 2 times in total.

RolfSE
Posts: 5
Joined: 2022-11-08 18:26
Has thanked: 7 times

Re: [HowTo] Debian Live installation with BTRFS, Subvolume, Snapper rollout

#2 Post by RolfSE »

Hi
Many thanks for the tutorial. Unfortunately the first part doesn't work for me: it seems like the changes in mount.cfg don't take effect. I still end up with a BTRFS partition with a single subvolume @rootfs. Any idea what I'm doing wrong?
Rolf

robertocannito
Posts: 8
Joined: 2023-08-20 07:14
Been thanked: 3 times

Re: [HowTo] Debian Live installation with BTRFS, Subvolume, Snapper rollout

#3 Post by robertocannito »

The subvolume part to append, cancelling the one present in the original one must be written with the correct tabulation and space, otherwise doesn't works

In this link you will find the perfect one with space and tabulation:
https://u.pcloud.link/publink/show?code ... sBBPmALf7[


just open etc/calamares/modules/mount.conf

leave all what is there included, but cancel all the rest starting from btrfsSubvolumes in down

and paste the part for file that I've sent you link

this procedure works good, I've installed in two my notebooks and also in 2 virtual machine

Pls let me know

RolfSE
Posts: 5
Joined: 2022-11-08 18:26
Has thanked: 7 times

Re: [HowTo] Debian Live installation with BTRFS, Subvolume, Snapper rollout

#4 Post by RolfSE »

Everything worked good!
My mistake was probably not an incorrect editing of mount.conf, but that I did a reboot afterwards instead of starting the installation directly from the live system menu. Maybe you can add that to your tutorial.
Thank you again for your work and your support.

robertocannito
Posts: 8
Joined: 2023-08-20 07:14
Been thanked: 3 times

Re: [HowTo] Debian Live installation with BTRFS, Subvolume, Snapper rollout

#5 Post by robertocannito »

Everything worked good!
Good, I'm glad that all has been perfect.

JaniceGobeil
Posts: 1
Joined: 2023-09-08 13:20

Re: [HowTo] Debian Live installation with BTRFS, Subvolume, Snapper rollout

#6 Post by JaniceGobeil »

Thanks for the link, I appreciate you.

bidey
Posts: 1
Joined: 2023-10-02 19:25

Re: [HowTo] Debian Live installation with BTRFS, Subvolume, Snapper rollout

#7 Post by bidey »

Hello @robertocannito,

thanks for the great tutorial, worked very well.

Best regards

cogitech
Posts: 25
Joined: 2023-11-17 16:30
Has thanked: 3 times
Been thanked: 8 times

Re: [HowTo] Debian Live installation with BTRFS, Subvolume, Snapper rollout

#8 Post by cogitech »

Excellent! Worked perfectly! Thanks!

dulhaver
Posts: 2
Joined: 2024-11-11 10:26

Re: [HowTo] Debian Live installation with BTRFS, Subvolume, Snapper rollout

#9 Post by dulhaver »

thanks @robertocannito for putting this together.

I feel like there is missing an essentiatl point though ... partitioning,
This (setting up those partitions manually) in the calamares installer works for me, but I am not certain whether it is ideal.

size         mountpoint    flag    fs
400MiB       /boot/efi     boot    FAT32
476,54GiB*   /                     btrfs

(*) being the remaining free space on a single disk

also I have a notion that snapper rollback might be more to the point then snapper rollout in the title of your thread
Last edited by dulhaver on 2024-11-15 15:34, edited 1 time in total.

dulhaver
Posts: 2
Joined: 2024-11-11 10:26

Re: [HowTo] Debian Live installation with BTRFS, Subvolume, Snapper rollout

#10 Post by dulhaver »

so, this is what I have to do different then the above how-to in order to make this work

1. install python3-btrfsutil (required by snapper-rollback)
2. not change subvol_main = @rootfs in /etc/snapper-rollback.conf
3. have a subvol @btrfsroot mounted to /.btrfsroot with subvolid-5 (required by snapper-rollback) with the blow fstab entry

Code: Select all

UUID=f0c486a7-b4f3-4c31-b976-50a15f0f34d3 /.btrfsroot    btrfs subvolid=5,defaults,noatime,space_cache=v2,compress=zstd,discard 0 0

Post Reply