The grub2 postinst uses `sed -i` (via `apply_conf_tweaks`) to apply
debconf settings to `/etc/default/grub`. `sed -i` works by creating a
temporary file, writing the modified content, and renaming it over the
original. If the system crashes or hangs during this write (as reported
— the machine became unresponsive during unattended-upgrade and required
a hard reboot), the temporary file may be empty or partially written,
and the rename replaces `/etc/default/grub` with this empty file.

This is consistent with the report: two identical NUCs running Ubuntu
26.04, an unattended-upgrade of kernel 7.0.0-14 to 7.0.0-15 involving
the grub2 package, one machine hung requiring a hard reboot, and
`/etc/default/grub` was found at 0 bytes afterwards while the other
machine upgraded fine.

## Proposed Fix (patch attached)

Add a safety check after the ucf merge in the postinst to detect and
recover from a truncated `/etc/default/grub`. If the file exists but is
empty, restore the distribution template from
`/usr/share/grub/default/grub` so the system remains bootable with
sensible defaults.

The check only fires when the file is already hosed — it has zero effect
on normal upgrades. The restored file provides working defaults (quiet
splash, standard timeout) and the user can re-customize afterwards. This
is strictly better than leaving the system with a 0-byte GRUB config
that can prevent booting or cause degraded behavior.

## Affected packages

All grub2 variants use the same ucf / apply_conf_tweaks pattern in their 
postinst:
- grub-efi-amd64
- grub-efi-arm64
- grub-efi-ia32
- grub-pc
- grub-ieee1275

** Attachment added: "launchpad-grub-empty-analysis.txt"
   
https://bugs.launchpad.net/ubuntu/+source/grub2/+bug/2150675/+attachment/5971436/+files/launchpad-grub-empty-analysis.txt

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/2150675

Title:
  /etc/default/grub found empty (0 bytes) after unattended upgrade on
  Ubuntu 26.04 while updating to kernel 7.0.0-15

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/grub2/+bug/2150675/+subscriptions


-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to