install-grub.pl: improve initrd-secrets error messages

The build of initrd-secrets can routinely fail for old boot entries
if the secrets have been removed or renamed in a later generation.
This always happens for generation 1, because it's built from the
NixOS installer and the paths differs by the mount point (i.e. /mnt).

The error is very confusing because it fails to mention it's about
an older generation and that it's somewhat harmless.

This commit turns the error into a warning for all generations but the
current, adds the name of the failed entry to the message and a note
explaining why it can happen.
This commit is contained in:
rnhmjoj 2023-01-15 02:31:15 +01:00
parent 6fecd5a257
commit eccc1e5bf4
No known key found for this signature in database
GPG key ID: BFBAF4C975F76450

View file

@ -442,7 +442,7 @@ sub copyToKernelsDir {
}
sub addEntry {
my ($name, $path, $options) = @_;
my ($name, $path, $options, $current) = @_;
return unless -e "$path/kernel" && -e "$path/initrd";
my $kernel = copyToKernelsDir(Cwd::abs_path("$path/kernel"));
@ -458,7 +458,14 @@ sub addEntry {
# Make sure initrd is not world readable (won't work if /boot is FAT)
umask 0137;
my $initrdSecretsPathTemp = File::Temp::mktemp("$initrdSecretsPath.XXXXXXXX");
system("$path/append-initrd-secrets", $initrdSecretsPathTemp) == 0 or die "failed to create initrd secrets: $!\n";
if (system("$path/append-initrd-secrets", $initrdSecretsPathTemp) != 0) {
if ($current) {
die "failed to create initrd secrets $!\n";
} else {
say STDERR "warning: failed to create initrd secrets for \"$name\", an older generation";
say STDERR "note: this is normal after having removed or renamed a file in `boot.initrd.secrets`";
}
}
# Check whether any secrets were actually added
if (-e $initrdSecretsPathTemp && ! -z _) {
rename $initrdSecretsPathTemp, $initrdSecretsPath or die "failed to move initrd secrets into place: $!\n";
@ -491,7 +498,7 @@ sub addEntry {
}
$conf .= "\n";
} else {
$conf .= "menuentry \"$name\" " . ($options||"") . " {\n";
$conf .= "menuentry \"$name\" " . $options . " {\n";
if ($saveDefault) {
$conf .= " savedefault\n";
}
@ -511,7 +518,7 @@ sub addEntry {
# Add default entries.
$conf .= "$extraEntries\n" if $extraEntriesBeforeNixOS;
addEntry("@distroName@ - Default", $defaultConfig, $entryOptions);
addEntry("@distroName@ - Default", $defaultConfig, $entryOptions, 1);
$conf .= "$extraEntries\n" unless $extraEntriesBeforeNixOS;
@ -536,7 +543,7 @@ foreach my $link (@links) {
my $linkname = basename($link);
$entryName = "($linkname - $date - $version)";
}
addEntry("@distroName@ - $entryName", $link);
addEntry("@distroName@ - $entryName", $link, "", 1);
}
my $grubBootPath = $grubBoot->path;
@ -568,7 +575,7 @@ sub addProfile {
-e "$link/nixos-version"
? readFile("$link/nixos-version")
: basename((glob(dirname(Cwd::abs_path("$link/kernel")) . "/lib/modules/*"))[0]);
addEntry("@distroName@ - Configuration " . nrFromGen($link) . " ($date - $version)", $link, $subEntryOptions);
addEntry("@distroName@ - Configuration " . nrFromGen($link) . " ($date - $version)", $link, $subEntryOptions, 0);
}
$conf .= "}\n" if $grubVersion == 2;