update-grub fails with 'Syntax error at line 194'

Bug #2051732 reported by Radu Marinescu
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
grub2 (Ubuntu)
New
Undecided
Unassigned

Bug Description

I have followed the tutorial https://openzfs.github.io/openzfs-docs/Getting%20Started/Ubuntu/Ubuntu%2022.04%20Root%20on%20ZFS.html to install Ubuntu Server 22.04 with root on zfs. However, after installing grub-efi-amd64-signed I got a syntax error when running the update-grub command.

The culprit seems to be the following section in /etc/grub.d/10_linux_zfs (lines 861-867):
```
    if [ -n "$boot_devices" ]; then
        for device in ${boot_devices}; do
            echo "${submenu_indentation} if [ "${boot_device}" = "${device}" ]; then"
            echo "$(prepare_grub_to_access_device_cached "${device}" $(( submenu_level +1 )) )"
            echo "${submenu_indentation} fi"
        done
    else
```

In my situation, this section generated an empty 'then' section in /boot/grub/grub.cfg in each menu entry:
```
                if [ ${boot_device} = /dev/mapper/root_zdrive1 ]; then

                fi
```

Adding an `echo ":"` in /etc/grub.d/10_linux_zfs solved the problem:
```
    if [ -n "$boot_devices" ]; then
        for device in ${boot_devices}; do
            echo "${submenu_indentation} if [ "${boot_device}" = "${device}" ]; then"
            echo ":"
            echo "$(prepare_grub_to_access_device_cached "${device}" $(( submenu_level +1 )) )"
            echo "${submenu_indentation} fi"
        done
    else
```

[Environment]

Ubuntu 22.04.3 LTS

grub-efi-amd64-signed:
  Installed: 1.187.6+2.06-2ubuntu14.4
  Candidate: 1.187.6+2.06-2ubuntu14.4
  Version table:
 *** 1.187.6+2.06-2ubuntu14.4 500
        500 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 Packages
        500 http://security.ubuntu.com/ubuntu jammy-security/main amd64 Packages
        100 /var/lib/dpkg/status
     1.180+2.06-2ubuntu7 500
        500 http://archive.ubuntu.com/ubuntu jammy/main amd64 Packages

I hope this helps!
There is a similar bug to this, involving the same file, but that is for 19.03 and the fix and cause of the error seem to be different.

ProblemType: Bug
DistroRelease: Ubuntu 22.04
Package: grub-common 2.06-2ubuntu7.2
ProcVersionSignature: Ubuntu 6.5.0-14.14~22.04.1-generic 6.5.3
Uname: Linux 6.5.0-14-generic x86_64
NonfreeKernelModules: zfs
ApportVersion: 2.20.11-0ubuntu82.5
Architecture: amd64
CasperMD5CheckResult: unknown
Date: Tue Jan 30 20:02:36 2024
ProcEnviron:
 TERM=xterm-256color
 PATH=(custom, no user)
 XDG_RUNTIME_DIR=<set>
 LANG=C.UTF-8
 SHELL=/usr/bin/bash
RebootRequiredPkgs: Error: path contained symlinks.
SourcePackage: grub2
UpgradeStatus: No upgrade log present (probably fresh install)
mtime.conffile..etc.grub.d.10_linux_zfs: 2024-01-30T19:59:34.274482

Revision history for this message
Radu Marinescu (radu-m91) wrote :
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.