From 87d5e457fe124facb261d13f52e14a7c6e6511af Mon Sep 17 00:00:00 2001 From: "William A. Kennington III" Date: Fri, 2 May 2014 00:44:36 -0500 Subject: [PATCH] nixos/grub: Grub detection is much simpler using subvol show --- .../system/boot/loader/grub/install-grub.pl | 28 +++++-------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/nixos/modules/system/boot/loader/grub/install-grub.pl b/nixos/modules/system/boot/loader/grub/install-grub.pl index 6748a5ca08fa..82809edd6e86 100644 --- a/nixos/modules/system/boot/loader/grub/install-grub.pl +++ b/nixos/modules/system/boot/loader/grub/install-grub.pl @@ -135,35 +135,21 @@ sub GrubFs { # BTRFS is a special case in that we need to fix the referrenced path based on subvolumes if ($fs->type eq 'btrfs') { - my $subvol = ""; - - my ($status, @mounts) = runCommand('mount'); + my ($status, @info) = runCommand("btrfs subvol show @{[$fs->device]}"); if ($status != 0) { - die "Failed to retreive mount info"; + die "Failed to retreive subvolume info for @{[$fs->device]}"; } - my @subvols = join("", @mounts) =~ m/@{[$fs->device]} on [^\n]*subvol=([^,)]*)/; + my @subvols = join("", @info) =~ m/Name:[ \t\n]([^ \t\n]*)/; if ($#subvols > 0) { - die "Btrfs device @{[$fs->device]} listed multiple times in mount\n" + die "Btrfs subvol name for @{[$fs->device]} listed multiple times in mount\n" } elsif ($#subvols == 0) { - $subvol = $subvols[0]; - } else { - my ($status, @btrfsOut) = runCommand("btrfs subvol get-default @{[$fs->mount]}"); - if ($status != 0) { - die "Failed to retrieve btrfs default subvolume" - } - my @results = join("", @btrfsOut) =~ m/path ([^ ]*)/; - if ($#results > 0) { - die "Btrfs device @{[$fs->device]} has multiple default subvolumes\n"; - } elsif ($#results == 1) { - $subvol = $results[0]; - } - } - $path = "/$subvol" . $path; + $path = "/$subvols[0]$path"; + } } } if (not $search eq "") { $search = "search --set=drive$driveid " . $search; - $path = "(\$drive$driveid)" . $path; + $path = "(\$drive$driveid)$path"; $driveid += 1; } }