nixos/grub: Simplify detection of labels / uuids for provided device names
This commit is contained in:
parent
c02bc3a9de
commit
4f096c044f
@ -104,28 +104,26 @@ sub GrubFs {
|
|||||||
$path = '/' . substr($fs->device, $sid) . '/@' . $path;
|
$path = '/' . substr($fs->device, $sid) . '/@' . $path;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
my %types = ('uuid' => '--fs-uuid', 'label' => '--label');
|
||||||
|
|
||||||
if ($fsIdentifier eq 'provided') {
|
if ($fsIdentifier eq 'provided') {
|
||||||
# If the provided dev is identifying the partition using a label or uuid,
|
# If the provided dev is identifying the partition using a label or uuid,
|
||||||
# we should get the label / uuid and do a proper search
|
# we should get the label / uuid and do a proper search
|
||||||
my $lbl = '/dev/disk/by-label/';
|
my @matches = $fs->device =~ m/\/dev\/disk\/by-(label|uuid)\/(.*)/;
|
||||||
if (index($fs->device, $lbl) == 0) {
|
if ($#matches > 1) {
|
||||||
$search = '--label ' . substr($fs->device, length($lbl));
|
die "Too many matched devices"
|
||||||
}
|
} elsif ($#matches == 1) {
|
||||||
|
$search = "$types{$matches[0]} $matches[1]"
|
||||||
my $uuid = '/dev/disk/by-uuid/';
|
|
||||||
if (index($fs->device, $uuid) == 0) {
|
|
||||||
$search = '--fs-uuid ' . substr($fs->device, length($uuid));
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
# Determine the identifying type
|
# Determine the identifying type
|
||||||
my %types = ('uuid' => '--fs-uuid', 'label' => '--label');
|
|
||||||
$search = $types{$fsIdentifier} . ' ';
|
$search = $types{$fsIdentifier} . ' ';
|
||||||
|
|
||||||
# Based on the type pull in the identifier from the system
|
# Based on the type pull in the identifier from the system
|
||||||
my ($status, @devInfo) = runCommand("blkid -o export @{[$fs->device]}");
|
my ($status, @devInfo) = runCommand("blkid -o export @{[$fs->device]}");
|
||||||
if ($status != 0) {
|
if ($status != 0) {
|
||||||
die "Failed to get blkid info for @{[$fs->device]}";
|
die "Failed to get blkid info for @{[$fs->device]}";
|
||||||
}
|
}
|
||||||
my @matches = join("", @devInfo) =~ m/@{[uc $fsIdentifier]}=([^\n]*)/;
|
my @matches = join("", @devInfo) =~ m/@{[uc $fsIdentifier]}=([^\n]*)/;
|
||||||
if ($#matches != 0) {
|
if ($#matches != 0) {
|
||||||
die "Couldn't find a $types{$fsIdentifier} for @{[$fs->device]}\n"
|
die "Couldn't find a $types{$fsIdentifier} for @{[$fs->device]}\n"
|
||||||
|
@ -416,7 +416,7 @@ in {
|
|||||||
createPartitions = ''
|
createPartitions = ''
|
||||||
$machine->succeed(
|
$machine->succeed(
|
||||||
"sgdisk -Z /dev/vda",
|
"sgdisk -Z /dev/vda",
|
||||||
"sgdisk -n 1:0:+1M -n 2:0:+1G -n 3:0:+100M -N 4 -t 1:ef02 -t 2:8300 -t 3:8200 -t 4:8300 -c 2:boot -c 4:root /dev/vda",
|
"sgdisk -n 1:0:+1M -n 2:0:+100M -n 3:0:+1G -N 4 -t 1:ef02 -t 2:8300 -t 3:8200 -t 4:8300 -c 2:boot -c 4:root /dev/vda",
|
||||||
"mkswap /dev/vda3 -L swap",
|
"mkswap /dev/vda3 -L swap",
|
||||||
"swapon -L swap",
|
"swapon -L swap",
|
||||||
"mkfs.ext4 -L boot /dev/vda2",
|
"mkfs.ext4 -L boot /dev/vda2",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user