diff --git a/nixos/modules/system/boot/loader/grub/install-grub.pl b/nixos/modules/system/boot/loader/grub/install-grub.pl index 2725cea59960..3c84fccac34c 100644 --- a/nixos/modules/system/boot/loader/grub/install-grub.pl +++ b/nixos/modules/system/boot/loader/grub/install-grub.pl @@ -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" diff --git a/nixos/tests/installer.nix b/nixos/tests/installer.nix index d15c43d29bbe..0eb67eaa813e 100644 --- a/nixos/tests/installer.nix +++ b/nixos/tests/installer.nix @@ -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",