Saturday, May 30, 2026

Google AI has finally decided to setup snapper on Debian forky with btrfs root

The core hack proposed by Google AI Assistant was Navigating the EFI layer. AI targeted the exact 3-line configuration stub (/boot/efi/EFI/debian/grub.cfg) that overrides the Btrfs default subvolume engine on Debian EFI installations. From my side it was  integrating a native .path watcher framework precisely because  a heavy, compiled inotifywait binary loses its structural handles during a subvolume swap and focus attention on sed substitutions @rootfs with @root_active in grub.cfg files and /etc/fstab.

 Virtual disk layout been selected for  setup

NAME               FSTYPE      FSVER    LABEL UUID                                   FSAVAIL FSUSE% MOUNTPOINTS
sr0                                                                                                  
vda                                                                                                  
├─vda1             vfat        FAT32          A381-BF73                                68.6M    12% /boot/efi
├─vda2             btrfs                      8b9cf5c4-b47b-4aba-8146-9494de4446cc     57.6G     9% /.snapshots
│                                                                                  /
└─vda3             LVM2_member LVM2 001       Ln1ZDW-hEzd-8Ntq-qSh3-v40U-5eYm-krwzXD                 
 ├─debianVG-vol01 xfs                        99456d7d-a85e-4f60-9d77-b7ac2511047d     45.1G     3% /var
 └─debianVG-vol02 xfs                   2c22b8ef-8b21-4304-9396-9c1f2a76493e     27.2G     2% /home


 Stage 1

Log into your SSH session, run sudo -i, and execute this block to replicate our successful migration:

# 1. Mount the underlying hard drive partition core
mkdir -p /mnt/btrfs_base
mount -o subvolid=5 /dev/vda2 /mnt/btrfs_base

# 2. Clone the active OS into your production subvolume and build the snapshot container
btrfs subvolume snapshot / /mnt/btrfs_base/@root_active
btrfs subvolume create /mnt/btrfs_base/@snapshots

# 3. Update the storage mapping tables inside the new subvolume clone
nano /mnt/btrfs_base/@root_active/etc/fstab

# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/vda2 during installation
# UUID=8b9cf5c4-b47b-4aba-8146-9494de4446cc /  btrfs   defaults,subvol=@rootfs 0       0


UUID=8b9cf5c4-b47b-4aba-8146-9494de4446cc / btrfs  defaults,subvol=@root_active,compress=zstd,noatime 0 1
UUID=8b9cf5c4-b47b-4aba-8146-9494de4446cc /.snapshots  btrfs  subvol=@snapshots,compress=zstd,noatime 0 0
# /boot/efi was on /dev/vda1 during installation
UUID=A381-BF73  /boot/efi       vfat    umask=0077   0       1
/dev/mapper/debianVG-vol02 /home xfs     defaults    0       0
/dev/mapper/debianVG-vol01 /var  xfs     defaults    0       0
/dev/sr0   /media/cdrom0   udf,iso9660 user,noauto   0       0
 

Stage 2

# 1. Update the main GRUB configuration tracking lines
sed -i 's/@rootfs/@root_active/g' /boot/grub/grub.cfg

# 2. Update the hidden EFI motherboard priority file so it launches the clone
nano /boot/efi/EFI/debian/grub.cfg
boris@debianForky0529:~$ sudo cat /boot/efi/EFI/debian/grub.cfg ( with valid UUID for "/" )
search --no-floppy --fs-uuid --set=root 0123755e-2d03-48e1-9159-5154860a307d
set prefix=($root)/@root_active/boot/grub
configfile $prefix/grub.cfg
 
(Change the set prefix=($root)/@rootfs... path line to explicitly target /@root_active).
# 3. Rebuild the system kernel modules inside the clone using a clean tool container
# mount --bind /dev /mnt/btrfs_base/@root_active/dev
# mount --bind /proc /mnt/btrfs_base/@root_active/proc
# mount --bind /sys /mnt/btrfs_base/@root_active/sys
# mount /dev/vda1 /mnt/btrfs_base/@root_active/boot/efi
# mount /dev/mapper/debianVG-vol01 /mnt/btrfs_base/@root_active/var  

# chroot /mnt/btrfs_base/@root_active /bin/bash -c "
  update-initramfs -u -k all "
# 1. Step back out to your primary host terminal prompt
exit
# 2. Force the parent GRUB binary to install its EFI modules into the clone's boot folder
$ sudo grub-install --boot-directory=/mnt/btrfs_base/@root_active/boot   /dev/vda
 
# 3. Force the global string replacement on the menu file to direct everything to the clone
$ sudo sed -i 's/@rootfs/@root_active/g' /mnt/btrfs_base/@root_active/boot/grub/grub.cfg
# 4. Clean up mounts and reboot into your new permanent system
$ sudo umount -R /mnt/btrfs_base
$ sudo reboot 
Stage 3 
Once your VM boots cleanly into @root_active, finalize the deployment:
# 1. Wipe out the old legacy installation footprint permanently
# mkdir -p /mnt/btrfs_base
# mount -o subvolid=5 /dev/vda2 /mnt/btrfs_base
# btrfs subvolume delete /mnt/btrfs_base/@rootfs
# umount /mnt/btrfs_base

# 2. Install Snapper, pull grub-btrfs from source, and run installation paths
# apt install snapper btrfs-progs git make build-essential inotify-tools gawk -y

# 1. Temporarily unmount the default layout path
$ sudo umount /.snapshots
# 2. Force remove the lingering local installer directory block
$ sudo rm -rf /.snapshots
# 3. Force Snapper to create the config profile now that the path is clear
$ sudo snapper -c root create-config /
# 4. Snapper just created a basic folder. Delete it so we can use your real subvolume
$ sudo rmdir /.snapshots
# 5.  RE-CREATE THE CORRECT EMPTY MOUNT POINT HOOK
$ sudo mkdir /.snapshots
# 6.  MOUNT YOUR PERMANENT SUBVOLUME LAYOUT FROM FSTAB
$ sudo mount -a
# 7. Secure the proper administrative tracking permissions for the engine
$ sudo chmod 750 /.snapshots
$ git clone https://github.com/Antynea/grub-btrfs.git
$ cd grub-btrfs && sudo make install
$ sudo systemctl daemon-reload 
$ sudo systemctl enable --now grub-btrfsd

# 3. Save your rescue script inside /var/local/sbin/snapper-rescue and symlink it
$ sudo chmod +x /var/local/sbin/snapper-rescue
$ sudo ln -s /var/local/sbin/snapper-rescue /usr/local/bin/snapper-rescue

# 4. Rebuild menu paths and lock in your first restore checkpoint
$ sudo update-grub
$ snapper -c root create --description "Baseline Production Setup"
==========================================
Keeping update-grub invoked automatically to maintain "Debian GNU/Linux. grub sub-menu" when system or user issue  $ sudo snapper -c root create --description ". . . .   "
==========================================
sudo nano /etc/systemd/system/grub-btrfs-watcher.path
[Unit]
Description=Monitor Timeshift Snapshot Directory Changes
 
[Path]
PathChanged=/.snapshots
Unit=grub-btrfs-watcher.service
 
[Install]
WantedBy=multi-user.target
=======================================
sudo nano /etc/systemd/system/grub-btrfs-watcher.service
[Unit]
Description=Regenerate GRUB Menu on Snapshot Change
 
[Service]
Type=oneshot
ExecStart=/usr/sbin/update-grub
======================================
sudo systemctl daemon-reload
sudo systemctl enable --now grub-btrfs-watcher.path
$ sudo reboot

> ssh boris@192.168.0.70
boris@192.168.0.70's password:
Linux debianVM0530 7.0.9+deb14-amd64 #1 SMP PREEMPT_DYNAMIC Debian 7.0.9-1 (2026-05-22) x86_64
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Sat May 30 07:59:24 2026 from 192.168.0.81
boris@debianVM0530:~$ sudo snapper -c root list
[sudo] password for boris:

 

# | Type   | Pre # | Date                            | User | Cleanup  | Description               | Userdata
---+--------+-------+---------------------------------+------+----------+---------------------------+---------
0  | single |       |                                 | root |          | current                   |
1  | single |       | Sat 30 May 2026 06:25:53 AM EDT | root |          | Baseline Production Setup |
2  | single |       | Sat 30 May 2026 06:30:08 AM EDT | root | number   | boot                      |
3- | single |       | Sat 30 May 2026 06:34:23 AM EDT | root |          | Verification step 01      |
4  | single |       | Sat 30 May 2026 06:35:50 AM EDT | root | number   | boot                      |
5  | single |       | Sat 30 May 2026 06:40:58 AM EDT | root | number   | boot                      |
6  | single |       | Sat 30 May 2026 07:00:13 AM EDT | root | timeline | timeline                  |
7  | single |       | Sat 30 May 2026 07:20:27 AM EDT | root | number   | boot                      |
8  | single |       | Sat 30 May 2026 07:56:23 AM EDT | root | number   | boot                      |
9  | single |       | Sat 30 May 2026 08:00:08 AM EDT | root | timeline | timeline                  |

boris@debianVM0530:~$ sudo snapper-rescue 3 

Actually, you are not forced to write script snapper-rescue on your own. Attach Debian Live ISO to virt-manager. Disable load instance from vda and and enable from ISO. You may perform a 3-step terminal override using any Debian Live ISO Instance loaded up

# 1. Mount your base Btrfs drive
$ sudo mount -o subvolid=5 /dev/vda2 /mnt
# 2. Delete the broken active layout
$ sudo btrfs subvolume delete  /mnt/@root_active
# 3. Recreate it instantly from your chosen working snapshot (e.g.,Snapshot ID)
$ sudo btrfs subvolume snapshot   /mnt/@snapshots/ID/snapshot   /mnt/@root_active

When done switch loading device to vda as it was before recovery procedure. Rolling back btrfs "/" volume via Debian Live ISO was tested several times. 

To get desired <ID> you are supposed to reboot via Debian Grub-sub-menu and issue $ sudo snapper -c root list and select <ID> which would serve you in Live instance environment to issue $  sudo btrfs subvolume snapshot   /mnt/@snapshots/ID/snapshot   /mnt/@root_active. Snapper and openssh-server should pre- installed onto Debian Live Instance 


No comments:

Post a Comment