update-grub fails to add ZFS menu entries

Bug #1876331 reported by Jim Hunziker
22
This bug affects 4 people
Affects Status Importance Assigned to Milestone
grub2 (Ubuntu)
Confirmed
Undecided
Unassigned

Bug Description

This is for:

Ubuntu 20.04 LTS
grub-common 2.04-1ubuntu26

I don't know how I got into this mess (maybe by removing ZFS @install snapshots?), but update-grub stopped adding any Ubuntu entries to my menu.cfg.

The culprit is the use of \t as a field separator in /etc/grub.d/10_linux_zfs.

There's a line that says:
        echo "${dataset}\t${is_zsys}\t${machine_id}\t${pretty_name}\t${last_used}\t${initrd_device}\t${initrd_list}\t${kernel_list}\t${last_booted_kernel}"

Instead, it should say:
        echo -e "${dataset}\t${is_zsys}\t${machine_id}\t${pretty_name}\t${last_used}\t${initrd_device}\t${initrd_list}\t${kernel_list}\t${last_booted_kernel}"

By default, echo does not interpret the escaped tab sequence, \t. So all of the awk lines that use it as a field separator elsewhere in the script fail.

Adding the above -e flag fixed my problem.

Tags: zfs
Revision history for this message
Matthias Benkard (mulk) wrote :

I have experienced this problem too. Adding the -e flag, substituting printf for echo, or changing the shebang line into #!/bin/dash fixes the issue, as does switching /bin/sh from Bash to Dash by running dpkg-reconfigure dash. My guess is that this is a Dashism, i.e. an incompatibility with systems configured to use Bash as /bin/sh, as the two shells are not 100% compatible.

tags: added: zfs
Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in grub2 (Ubuntu):
status: New → Confirmed
Revision history for this message
Didier Roche-Tolomelli (didrocks) wrote :

Thanks for reporting this bug and help making ubuntu better!

I doubt the issue is due to anything you have made on snapshots.
echo from dash (our default /bin/sh) has no -e option and \t are interpreted as expected.
echo from bash has this -e to interpret special characters.

Can you tell what’s your default /bin/sh, have you changed it?

Revision history for this message
Jim Hunziker (landtuna) wrote :

Ah - that's it! My /bin/sh is symlinked to /bin/bash. I believe following the instructions for installing a GNU Radio SDK is why I made that change:

"On some distributions (e.g. Ubuntu), PyBOMBS can run into shell issues. To avoid those problems, it is recommended to run the following command
before continuing, and choose "no" in the prompted dialogue:
$ sudo dpkg-reconfigure dash"

Is it expected that changing the system's default shell would break scripts?

Revision history for this message
Didier Roche-Tolomelli (didrocks) wrote :

It’s not expected of course, but we tried to stick to POSIX syntax to avoid breakages.

However, reading https://pubs.opengroup.org/onlinepubs/009695399/utilities/echo.html, it seems that escape sequences in echo are not POSIX: "It is not possible to use echo portably across all POSIX systems unless both -n (as the first argument) and escape sequences are omitted." and that we should rather change those echo by printf. We’ll fix it this way, thanks!

Note that changing sh by bash slows down drastically the boot experience and it should rather be PyBOMBS to fix their scripts to either requires bash and be dash compliant.

Revision history for this message
Jim Hunziker (landtuna) wrote :

Thanks - I changed my system back to dash.

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.