Venom1991 / refind-btrfs

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

Boot stanza with second "volume" value causes refind-btrfs to error #45

Open BluishHumility opened 1 year ago

BluishHumility commented 1 year ago

Hello,

I am sure this is a bit of an edge case, but I have a boot stanza with a submenu entry that specifies a different value for "volume", which appears to be causing an issue with the refind-btrfs script.

This is the boot stanza:

 menuentry "Garuda Gnome" {                                                                                                                                                                                               
    icon    /EFI/refind/gnome_logo.png                                                                                                                                                                                    
    volume  Btrfs                                                                                                                                                                                                         
    loader  /gnome/boot/vmlinuz-linux-zen                                                                                                                                                                                 
    initrd  /gnome/boot/initramfs-linux-zen.img                                                                                                                                                                           
    graphics on                                                                                                                                                                                                           
    options "root=UUID=5fa54f34-b5fc-40be-8092-8ba34ced9eba rw rootflags=subvol=gnome quiet quiet splash rd.udev.log_priority=3 vt.global_cursor_default=0 loglevel=3 nvme.noacpi=1 nowatchdog"                           
    submenuentry "Zen fallback" {                                                                                                                                                                                         
        initrd /gnome/boot/initramfs-linux-zen-fallback.img                                                                                                                                                               
        options "root=UUID=5fa54f34-b5fc-40be-8092-8ba34ced9eba rw rootflags=subvol=gnome nvme.noacpi=1 nowatchdog"                                                                                                       
    }                                                                                                                                                                                                                     
    submenuentry "LTS kernel" {                                                                                                                                                                                           
        loader /gnome/boot/vmlinuz-linux-lts                                                                                                                                                                              
        initrd /gnome/boot/initramfs-linux-lts.img                                                                                                                                                                        
    }                                                                                                                                                                                                                     
    submenuentry "LTS fallback" {                                                                                                                                                                                         
        loader /gnome/boot/vmlinuz-linux-lts                                                                                                                                                                              
        initrd /gnome/boot/initramfs-linux-lts-fallback.img                                                                                                                                                               
    }                                                                                                                                                                                                                     
    submenuentry Grub {                                                                                                                                                                                                   
        volume EFI                                                                                                                                                                                                        
        loader /EFI/Gnome/grubx64.efi                                                                                                                                                                                     
    }                                                                                                                                                                                                                     
}

The last submenu entry (Grub) is the one causing an issue, specifically the volume line. This submenu entry allows booting to Grub from the rEFInd boot options menu.

image

The "volume" line needs to be specified because the value is different than the one in the main body of the stanza--because, of course, the Grub loader is not on the Btrfs partition, it is on the EFI partition. The submenu entry itself works perfectly fine, but appears to cause an issue when running refind-btrfs:

 sudo refind-btrfs
[sudo] password for jeremy: 
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 '/boot/efi' on '/dev/nvme0n1p1'.
Found the root partition on '/dev/nvme0n1p2'.
Searching for snapshots of the 'sway' subvolume in the '/.snapshots' directory.
Found subvolume 'sway' mounted as the root partition.
Found 2 snapshots of the 'sway' subvolume.
Searching for the 'refind.conf' file on '/dev/nvme0n1p1'.
Analyzing the 'refind.conf' file.
ERROR (refind_btrfs.boot.file_refind_config_provider/file_refind_config_provider.py/_read_config_from): Error while parsing the 'refind.conf' file!
Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/refind_btrfs/boot/antlr4/RefindConfigParser.py", line 938, in sub_menu
    self._errHandler.sync(self)
  File "/usr/lib/python3.10/site-packages/antlr4/error/ErrorStrategy.py", line 231, in sync
    raise InputMismatchException(recognizer)
antlr4.error.Errors.InputMismatchException: None

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/refind_btrfs/boot/file_refind_config_provider.py", line 246, in _read_config_from
    refind_context = parser.refind()
  File "/usr/lib/python3.10/site-packages/refind_btrfs/boot/antlr4/RefindConfigParser.py", line 183, in refind
    self.config_option()
  File "/usr/lib/python3.10/site-packages/refind_btrfs/boot/antlr4/RefindConfigParser.py", line 237, in config_option
    self.boot_stanza()
  File "/usr/lib/python3.10/site-packages/refind_btrfs/boot/antlr4/RefindConfigParser.py", line 308, in boot_stanza
    self.main_option()
  File "/usr/lib/python3.10/site-packages/refind_btrfs/boot/antlr4/RefindConfigParser.py", line 485, in main_option
    self.sub_menu()
  File "/usr/lib/python3.10/site-packages/refind_btrfs/boot/antlr4/RefindConfigParser.py", line 953, in sub_menu
    self._errHandler.reportError(self, re)
  File "/usr/lib/python3.10/site-packages/antlr4/error/ErrorStrategy.py", line 128, in reportError
    self.reportInputMismatch(recognizer, e)
  File "/usr/lib/python3.10/site-packages/antlr4/error/ErrorStrategy.py", line 275, in reportInputMismatch
    recognizer.notifyErrorListeners(msg, e.offendingToken, e)
  File "/usr/lib/python3.10/site-packages/antlr4/Parser.py", line 322, in notifyErrorListeners
    listener.syntaxError(self, offendingToken, line, column, msg, e)
  File "/usr/lib/python3.10/site-packages/antlr4/error/ErrorListener.py", line 60, in syntaxError
    delegate.syntaxError(recognizer, offendingSymbol, line, column, msg, e)
  File "/usr/lib/python3.10/site-packages/refind_btrfs/boot/refind_listeners.py", line 32, in syntaxError
    raise RefindSyntaxError(line, column, msg)
refind_btrfs.common.exceptions.RefindSyntaxError: RefindSyntaxError: line - 628, column - 2, message - 'mismatched input 'volume' expecting {'loader', 'initrd', GRAPHICS, 'options', 'add_options', 'disabled'}'
ERROR (refind_btrfs.state_management.refind_btrfs_machine/refind_btrfs_machine.py/run): Could not load rEFInd configuration from file!

Line 628 is the volume EFI line in the Grub submenu.

Interestingly, this "Garuda Gnome" stanza with the Grub boot option that is causing an issue is not even related to the installation where I am trying to run refind-btrfs. I am trying to set up refind-btrfs on a Sway installation that doesn't even have Grub installed.

Disabling the stanza does not prevent refind-btrfs from erroring out, even when I added the disabled line above the problematic volume entry. It seems the script is still trying to make sense of this line for some reason, even when the stanza should be getting ignored.

After explicitly commenting out the four lines related to the Grub submenu entry, the script succeeds.

Since there is a pretty simple workaround, I would consider this a pretty low priority for fixing--especially since, as I mentioned, this is almost certainly an edge case. Still, I figured I would mention it in case you would like to take a look.

Venom1991 commented 1 year ago

This feature is not even documented which is the reason refind-btrfs is complaining (it cannot parse the file, to be exact, which is why the "disabled" option isn't helpful in this case) about the unexpected "volume" token in the context of a sub-menu. You could try playing around with the "loader" option, instead. Perhaps it could work, although I'm somewhat skeptical (quote from the documentation):

Note that the loader is read from whatever filesystem is specified by the main stanza's volume option, provided that option precedes the submenu definition.

BluishHumility commented 1 year ago

This feature is not even documented

I see what you mean! Now that you mention it, adding the volume line in the submenu entry was more of a solution I stumbled onto (rather than seeing it suggested in the documentation, etc).

I had initially tried using the loader option to point to Grub with the submenu entry, but no matter how I set it I couldn't get it to work. Although the EFI partition logically has a mount point that is relative to the Btrfs partition (through /boot/efi/EFI), the fact that it was on a different partition seemed to be a deal breaker.

At some point, it occurred to me that often the submenu options are used as a "re-do" for the values specified in the main body of the stanza, so why not the volume option? I'm not sure if it was intentional to allow volume to be re-specified in a submenu entry, but it works just fine.

In any case, like I mentioned it seems very unlikely other folks will be running into this issue--and if they do, the workaround is easy as pie: if you need to run the refind-btrfs script, just open refind.conf and comment out the submenu entry first, then uncomment the lines after the script finishes and all is well.