Monday, June 8, 2026

FEDORA SERVER 44 BTRFS SETUP and RECOVERY ENGINE (Assisted by Google AI)

In general, instance setup was proposed by Google AI (1-5). My choice was to create four subvolumes followed by "Trick snapper method". (6) I've also suggested to run critical "mv /mnt/btrfs-top/root      /mnt/btrfs-top/root_broken"  inside the Live F44 (KDE Plasma) instance against crashed instance F44 Server been built on top vda with flat architecture been spread across four btrfs subvolumes "root","home","boot" and ".snapshots"

Original vda layout setup via Anaconda Blivet GUI installation
=====================================================
boris@fedoraSRV0609:~$ lsblk -f
 
NAME   FSTYPE  FSVER            LABEL              UUID                                 FSAVAIL FSUSE% MOUNTPOINTS
zram0  swap    1                zram0              4f083286-72fc-49fc-807d-d4f9a45b447a                [SWAP]
vda
├─vda1 vfat    FAT32                               1C26-CCBE                            1014.1M     1%                           /boot/efi
└─vda2 btrfs                    fedora-volume      0bdb9d96-5296-4aec-a2a9-e2aceb9f18fd   91.8G     7% /home
                                                                                                                                                                      /boot
                                                                                                                                                                      /.snapshots
                                                                                                                                                                      /
 
Originally created /etc/fstab stays untouched due to Trick Snapper Method
 
boris@fedoraSRV0609:~$ cat /etc/fstab
# /etc/fstab
# Created by anaconda on Mon Jun  8 09:56:27 2026
# Accessible filesystems, by reference, are maintained under '/dev/disk/'.
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
UUID=0bdb9d96-5296-4aec-a2a9-e2aceb9f18fd / btrfs subvol=root,compress=zstd:1 0 0
UUID=0bdb9d96-5296-4aec-a2a9-e2aceb9f18fd /.snapshots btrfs subvol=snapshots,compress=zstd:1 0 0
UUID=0bdb9d96-5296-4aec-a2a9-e2aceb9f18fd /boot btrfs subvol=boot,compress=zstd:1 0 0
UUID=1C26-CCBE /boot/efi vfat umask=0077,shortname=winnt 0 2
UUID=0bdb9d96-5296-4aec-a2a9-e2aceb9f18fd /home btrfs subvol=home,compress=zstd:1 0 0
 
$ sudo dnf install btrfs-assistant snapper gawk inotify-tools libdnf5-plugin-actions git make -y
========================
Trick Snapper Method
========================
$ sudo umount /.snapshots
$ sudo rmdir    /.snapshots
$ sudo snapper -c root create-config  /
$ sudo mkdir   /.snapshots
$ sudo mount  /.snapshots
                                                                                                                                                                     
1. MANUAL GRUB-BTRFS ENHANCEMENT FROM SOURCE
-----------------------------------------------------------------------------------------
$ cd grub-btrfs
$ sudo make install
 
# Modify /etc/default/grub-btrfs/config with these parameters:
GRUB_BTRFS_GRUB_DIRNAME="/boot/grub2"
GRUB_BTRFS_MKCONFIG="grub2-mkconfig"
GRUB_BTRFS_SCRIPT_CHECK="grub2-script-check"
 
$ sudo grub2-mkconfig -o /boot/grub2/grub.cfg
$ sudo systemctl daemon-reload
$ sudo systemctl enable --now grub-btrfsd
 
2. DNF5 TRANSACTION SNAPSHOT AUTOMATION ENGINE
----------------------------------------------------------------------------------------
sudo nano /usr/local/bin/dnf5-snapper-helper
 
#!/bin/bash
case "$1" in
    pre)
        /usr/bin/snapper -c root create -t pre -p -d "DNF Transaction" -c number > /tmp/snapper_pre_id
        ;;
    post)
        if [ -f /tmp/snapper_pre_id ]; then
            PRE_ID=$(cat /tmp/snapper_pre_id)
            /usr/bin/snapper -c root create -t post --pre-num "$PRE_ID" -d "DNF Transaction Complete" -c number
            rm -f /tmp/snapper_pre_id
        fi
        ;;
esac
 
$ sudo chmod +x /usr/local/bin/dnf5-snapper-helper
$ sudo nano /etc/dnf/libdnf5-plugins/actions.d/snapper.actions
 
pre_transaction::::/usr/local/bin/dnf5-snapper-helper pre
post_transaction::::/usr/local/bin/dnf5-snapper-helper post
 
3. HOUSEKEEPING RETENTION MANAGEMENT
---------------------------------------------------------------------------------------
# Modify /etc/snapper/configs/root with these parameters:
NUMBER_MIN_AGE="1800"
NUMBER_LIMIT="10"
NUMBER_LIMIT_IMPORTANT="10"
TIMELINE_LIMIT_HOURLY="0"
TIMELINE_LIMIT_DAILY="0"
TIMELINE_LIMIT_WEEKLY="0"
TIMELINE_LIMIT_MONTHLY="0"
TIMELINE_LIMIT_YEARLY="0"
 
4. RUNTIME LIVE CLI RECOVERY (WRITABLE SESSIONS ONLY)
---------------------------------------------------------------------------------------
$ sudo btrfs-assistant --restore <SNAPSHOT_ID>
$ sudo reboot
 
5. CLEANUP LEFTOVERS AFTER DEPLOYMENT SWAPS
---------------------------------------------------------------------------------------
$ sudo mkdir -p /mnt/btrfs-top
$ sudo mount -o subvolid=5 /dev/vda2 /mnt/btrfs-top
$ sudo btrfs subvolume delete /mnt/btrfs-top/root_dead
$ sudo btrfs subvolume delete /mnt/btrfs-top/root_broken
$ sudo umount /mnt/btrfs-top
$ sudo rmdir /mnt/btrfs-top
 
Device order during normal runtime
 












Device order to recover via mounting /dev/vda2 on /mnt/btrfs-top followed by two commands which resulted looping been issued in read-only instance selected via fedora grub sub-menu. 
 

 
6.BARE-METAL BTRFS LIVE ISO RECOVERY PROTOCOL
----------------------------------------------------------------------------------------
Virtual emulation follows below
Right after crash shutdown instance. Switch order of boot-able devices to F44 ( say KDE Plasma ) Live CD and boot up having both device attached to virt-manager session. Commands below are supposed to run in F44 Live Instance environment see snapshots above. They may be cut from Host and paste into spice console.
As liveuser execute  
$ sudo su -
$ mkdir -p  /mnt/btrfs-top
$ mount -o subvolid=5  /dev/vda2   /mnt/btrfs-top
$ mv /mnt/btrfs-top/root      /mnt/btrfs-top/root_broken
$ btrfs subvolume snapshot   /mnt/btrfs-top/snapshots/<RECOVERY_SNAPSHOT_ID>/snapshot      /mnt/btrfs-top/root
$ umount /mnt/btrfs-top
 
Then shutdown Live instance and switch order of boot-able devices back to vda and attempt to boot up from recovered virtual drive

No comments:

Post a Comment