Venom1991 / refind-btrfs

Generate rEFInd manual boot stanzas from Btrfs snapshots
GNU General Public License v3.0
144 stars 8 forks source link

Bug: Modifying main refind config in case when manual stanzas are defined in an included file #12

Closed psfloyd closed 3 years ago

psfloyd commented 3 years ago

I think i have found a bug. For the tool to work properly the manual stanza that it searches must be on the main config file (the one specified in /etc/refind-btrfs.conf). If the stanzas are in a file that is included (using refind's include token), then the tool does not generate the necesary files under btrfs-snapshot-stanzas and does not moidify the main config file.

I leave an example of this behavior below. I have created 2 files to isolate the issue refind-main.conf and refind-stanzas.conf in the ESP mount and pointed refind-btrfs to the main file.

Situation 1: stanza in main config file, working properly

In this situation the tool created the files in the btrfs-snapshot-stanzas subdirectory and appended the include btrfs-snapshot-stanzas/kstar-root_vmlinuz-linux.conf line.

Main config:

# refind-main.conf

timeout -1

use_graphics_for linux, windows
scanfor manual,internal,external,optical,netboot,hdbios,biosexternal,cd

include refind-stanzas.conf

# stanza
menuentry "Arch Linux - Stable" {
    icon /EFI/refind/icons/os_arch.png
    volume kstar-root
    loader /vmlinuz-linux
    initrd /initramfs-linux.img
    options "root=/dev/mapper/kstar-root rw add_efi_memmap rootflags=subvol=@ initrd=\intel-ucode.img"
    submenuentry "Boot - fallback" {
        initrd /initramfs-linux-fallback.img
    }
    submenuentry "Boot - terminal" {
        add_options "systemd.unit=multi-user.target"
    }
}

Included config:

# refind-stanzas.conf

Output of refind-btrfs

Initializing the block devices using lsblk.
Initializing the physical partition table for device '/dev/nvme0n1' using lsblk.
Initializing the live partition table for device '/dev/nvme0n1' using findmnt.
Found the ESP mounted at '/efi' on '/dev/nvme0n1p1'.
Found the root partition on '/dev/mapper/kstar-root'.
Found a separate boot partition on '/dev/nvme0n1p2'.
Searching for snapshots of the '@' subvolume in the '/.snapshots' directory.
Found subvolume '@' mounted as the root partition.
Found 58 snapshots of the '@' subvolume.
Searching for the 'refind-main.conf' file on '/dev/nvme0n1p1'.
Analyzing the 'refind-main.conf' file.
Found 1 boot stanza matched with the root partition.
Initializing the static partition table for subvolume '@snapshots/68/snapshot' from its fstab file.
Found 1 snapshot for addition.
Found 1 snapshot for removal.
Creating a new writable snapshot from the read-only '@snapshots/68/snapshot' snapshot at '/root/.refind-btrfs/rwsnap_2021-08-01_11-54-02_ID587'.
Modifying the '/root/.refind-btrfs/rwsnap_2021-08-01_11-54-02_ID587/etc/fstab' file.
Deleting the '@/root/.refind-btrfs/rwsnap_2021-08-01_11-53-22_ID585' snapshot.
Writing to the 'btrfs-snapshot-stanzas/kstar-root_vmlinuz-linux.conf' file.
Appending 1 'include' directive to the 'refind-main.conf' file.

Situation 2: stanza is in an included config file, not working

In this situation the tool did not create any files or subdirectories and did not add any lines to the main config file.

Main config:

# refind-main.conf

timeout -1

use_graphics_for linux, windows
scanfor manual,internal,external,optical,netboot,hdbios,biosexternal,cd

include refind-stanzas.conf

Included config:

# refind-stanzas.conf

# stanza
menuentry "Arch Linux - Stable" {
    icon /EFI/refind/icons/os_arch.png
    volume kstar-root
    loader /vmlinuz-linux
    initrd /initramfs-linux.img
    options "root=/dev/mapper/kstar-root rw add_efi_memmap rootflags=subvol=@ initrd=\intel-ucode.img"
    submenuentry "Boot - fallback" {
        initrd /initramfs-linux-fallback.img
    }
    submenuentry "Boot - terminal" {
        add_options "systemd.unit=multi-user.target"
    }
}

Output of refind-btrfs

Initializing the block devices using lsblk.
Initializing the physical partition table for device '/dev/nvme0n1' using lsblk.
Initializing the live partition table for device '/dev/nvme0n1' using findmnt.
Found the ESP mounted at '/efi' on '/dev/nvme0n1p1'.
Found the root partition on '/dev/mapper/kstar-root'.
Found a separate boot partition on '/dev/nvme0n1p2'.
Searching for snapshots of the '@' subvolume in the '/.snapshots' directory.
Found subvolume '@' mounted as the root partition.
Found 59 snapshots of the '@' subvolume.
Searching for the 'refind-main.conf' file on '/dev/nvme0n1p1'.
Analyzing the 'refind-main.conf' file.
Analyzing the 'refind-stanzas.conf' file.
Found 1 boot stanza matched with the root partition.
Initializing the static partition table for subvolume '@snapshots/69/snapshot' from its fstab file.
Found 1 snapshot for addition.
Found 1 snapshot for removal.
Creating a new writable snapshot from the read-only '@snapshots/69/snapshot' snapshot at '/root/.refind-btrfs/rwsnap_2021-08-01_11-56-02_ID589'.
Modifying the '/root/.refind-btrfs/rwsnap_2021-08-01_11-56-02_ID589/etc/fstab' file.
Deleting the '@/root/.refind-btrfs/rwsnap_2021-08-01_11-54-02_ID587' snapshot.
Venom1991 commented 3 years ago

So, it did generate a new snapshot, modify its fstab file but it did not create a new config file for the generated boot stanza nor did it include that file in the refind-main.conf file? Alright, I'll have to reproduce that locally and debug it, I guess.
What's interesting is that the output simply stops after the "Deleting the..." line without an error or something.

I remember that this scenario worked well, initially, but later changes might have broken that functionality (that is, included config support).

Venom1991 commented 3 years ago

Fix in the following commit, pending release.