grub: Add support for forcing devices to be identified with labels or UUIDs
This commit is contained in:
parent
c5bdb469ce
commit
fba9f641a8
@ -26,11 +26,11 @@ let
|
|||||||
inherit (cfg)
|
inherit (cfg)
|
||||||
version extraConfig extraPerEntryConfig extraEntries
|
version extraConfig extraPerEntryConfig extraEntries
|
||||||
extraEntriesBeforeNixOS extraPrepareConfig configurationLimit copyKernels timeout
|
extraEntriesBeforeNixOS extraPrepareConfig configurationLimit copyKernels timeout
|
||||||
default devices;
|
default devices fsIdentifier;
|
||||||
path = (makeSearchPath "bin" [
|
path = (makeSearchPath "bin" [
|
||||||
pkgs.coreutils pkgs.gnused pkgs.gnugrep pkgs.findutils pkgs.diffutils
|
pkgs.coreutils pkgs.gnused pkgs.gnugrep pkgs.findutils pkgs.diffutils
|
||||||
]) + ":" + (makeSearchPath "sbin" [
|
]) + ":" + (makeSearchPath "sbin" [
|
||||||
pkgs.mdadm
|
pkgs.mdadm pkgs.utillinux
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -210,6 +210,21 @@ in
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
fsIdentifier = mkOption {
|
||||||
|
default = "uuid";
|
||||||
|
type = types.addCheck types.string
|
||||||
|
(type: type == "uuid" || type == "label" || type = "provided");
|
||||||
|
description = ''
|
||||||
|
Determines how grub will identify devices when generating the
|
||||||
|
configuration file. A value of uuid / label signifies that grub
|
||||||
|
will always resolve the uuid or label of the device before using
|
||||||
|
it in the configuration. A value of provided means that grub will
|
||||||
|
use the device name as show in <command>df</command> or
|
||||||
|
<command>mount</command>. Note, zfs zpools / datasets are ignored
|
||||||
|
and will always be mounted using their labels.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
zfsSupport = mkOption {
|
zfsSupport = mkOption {
|
||||||
default = false;
|
default = false;
|
||||||
type = types.bool;
|
type = types.bool;
|
||||||
|
@ -8,6 +8,7 @@ use File::stat;
|
|||||||
use File::Copy;
|
use File::Copy;
|
||||||
use POSIX;
|
use POSIX;
|
||||||
use Cwd;
|
use Cwd;
|
||||||
|
use Switch;
|
||||||
|
|
||||||
my $defaultConfig = $ARGV[1] or die;
|
my $defaultConfig = $ARGV[1] or die;
|
||||||
|
|
||||||
@ -40,6 +41,7 @@ my $configurationLimit = int(get("configurationLimit"));
|
|||||||
my $copyKernels = get("copyKernels") eq "true";
|
my $copyKernels = get("copyKernels") eq "true";
|
||||||
my $timeout = int(get("timeout"));
|
my $timeout = int(get("timeout"));
|
||||||
my $defaultEntry = int(get("default"));
|
my $defaultEntry = int(get("default"));
|
||||||
|
my $fsIdentifier = get("fsIdentifier");
|
||||||
$ENV{'PATH'} = get("path");
|
$ENV{'PATH'} = get("path");
|
||||||
|
|
||||||
die "unsupported GRUB version\n" if $grubVersion != 1 && $grubVersion != 2;
|
die "unsupported GRUB version\n" if $grubVersion != 1 && $grubVersion != 2;
|
||||||
@ -87,6 +89,15 @@ sub GrubFs {
|
|||||||
$path = "/" . substr($fs->device, $sid) . "/@" . $path;
|
$path = "/" . substr($fs->device, $sid) . "/@" . $path;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
my $idCmd = "\$(blkid -o export $fs->device) 2>/dev/null; echo"
|
||||||
|
switch ($fsIdentifier) {
|
||||||
|
case "uuid" {
|
||||||
|
$search = "--fs-uuid " . `$idCmd \$UUID`;
|
||||||
|
}
|
||||||
|
case "label" {
|
||||||
|
$search = "--label " . `$idCmd \$LABEL`;
|
||||||
|
}
|
||||||
|
case "provided" {
|
||||||
my $lbl = "/dev/disk/by-label/";
|
my $lbl = "/dev/disk/by-label/";
|
||||||
if (index($fs->device, $lbl) == 0) {
|
if (index($fs->device, $lbl) == 0) {
|
||||||
$search = "--label " . substr($fs->device, length($lbl));
|
$search = "--label " . substr($fs->device, length($lbl));
|
||||||
@ -96,6 +107,11 @@ sub GrubFs {
|
|||||||
$search = "--fs-uuid " . substr($fs->device, length($uuid));
|
$search = "--fs-uuid " . substr($fs->device, length($uuid));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
die "invalid fs identifier type\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if (not $search eq "") {
|
if (not $search eq "") {
|
||||||
$search = "search --set=drive$driveid " . $search;
|
$search = "search --set=drive$driveid " . $search;
|
||||||
$path = "(\$drive$driveid)" . $path;
|
$path = "(\$drive$driveid)" . $path;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user