nixos/grub: Simplify detection of labels / uuids for provided device names

This commit is contained in:
William A. Kennington III 2014-05-02 02:53:32 -05:00
parent c02bc3a9de
commit 4f096c044f
2 changed files with 11 additions and 13 deletions

View File

@ -104,28 +104,26 @@ sub GrubFs {
$path = '/' . substr($fs->device, $sid) . '/@' . $path;
}
} else {
my %types = ('uuid' => '--fs-uuid', 'label' => '--label');
if ($fsIdentifier eq 'provided') {
# If the provided dev is identifying the partition using a label or uuid,
# we should get the label / uuid and do a proper search
my $lbl = '/dev/disk/by-label/';
if (index($fs->device, $lbl) == 0) {
$search = '--label ' . substr($fs->device, length($lbl));
}
my $uuid = '/dev/disk/by-uuid/';
if (index($fs->device, $uuid) == 0) {
$search = '--fs-uuid ' . substr($fs->device, length($uuid));
my @matches = $fs->device =~ m/\/dev\/disk\/by-(label|uuid)\/(.*)/;
if ($#matches > 1) {
die "Too many matched devices"
} elsif ($#matches == 1) {
$search = "$types{$matches[0]} $matches[1]"
}
} else {
# Determine the identifying type
my %types = ('uuid' => '--fs-uuid', 'label' => '--label');
$search = $types{$fsIdentifier} . ' ';
# Based on the type pull in the identifier from the system
my ($status, @devInfo) = runCommand("blkid -o export @{[$fs->device]}");
if ($status != 0) {
die "Failed to get blkid info for @{[$fs->device]}";
}
if ($status != 0) {
die "Failed to get blkid info for @{[$fs->device]}";
}
my @matches = join("", @devInfo) =~ m/@{[uc $fsIdentifier]}=([^\n]*)/;
if ($#matches != 0) {
die "Couldn't find a $types{$fsIdentifier} for @{[$fs->device]}\n"

View File

@ -416,7 +416,7 @@ in {
createPartitions = ''
$machine->succeed(
"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",
"swapon -L swap",
"mkfs.ext4 -L boot /dev/vda2",