diff options
author | William A. Kennington III <william@wkennington.com> | 2014-08-30 15:44:13 -0700 |
---|---|---|
committer | William A. Kennington III <william@wkennington.com> | 2014-09-02 09:16:13 -0700 |
commit | 01ab1d57a3e02d388a8e1903031b273b47c6bb94 (patch) | |
tree | a941e95a9b218dbf419a98083dee0af04d3ad9d3 /nixos/modules/system | |
parent | 7fae42352235b9315021005928fea9a058c516e8 (diff) | |
download | nixlib-01ab1d57a3e02d388a8e1903031b273b47c6bb94.tar nixlib-01ab1d57a3e02d388a8e1903031b273b47c6bb94.tar.gz nixlib-01ab1d57a3e02d388a8e1903031b273b47c6bb94.tar.bz2 nixlib-01ab1d57a3e02d388a8e1903031b273b47c6bb94.tar.lz nixlib-01ab1d57a3e02d388a8e1903031b273b47c6bb94.tar.xz nixlib-01ab1d57a3e02d388a8e1903031b273b47c6bb94.tar.zst nixlib-01ab1d57a3e02d388a8e1903031b273b47c6bb94.zip |
nixos/install-grub: Detect nested btrfs subvolumes
Diffstat (limited to 'nixos/modules/system')
-rw-r--r-- | nixos/modules/system/boot/loader/grub/install-grub.pl | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/nixos/modules/system/boot/loader/grub/install-grub.pl b/nixos/modules/system/boot/loader/grub/install-grub.pl index 9ef1a6977047..f1807f53ff1d 100644 --- a/nixos/modules/system/boot/loader/grub/install-grub.pl +++ b/nixos/modules/system/boot/loader/grub/install-grub.pl @@ -133,15 +133,25 @@ 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 ($status, @info) = runCommand("btrfs subvol show @{[$fs->mount]}"); + my ($status, @id_info) = runCommand("btrfs subvol show @{[$fs->mount]}"); if ($status != 0) { - die "Failed to retreive subvolume info for @{[$fs->mount]}"; + die "Failed to retreive subvolume info for @{[$fs->mount]}\n"; } - my @subvols = join("", @info) =~ m/Name:[ \t\n]*([^ \t\n]*)/; - if ($#subvols > 0) { + my @ids = join("", @id_info) =~ m/Object ID:[ \t\n]*([^ \t\n]*)/; + if ($#ids > 0) { die "Btrfs subvol name for @{[$fs->device]} listed multiple times in mount\n" - } elsif ($#subvols == 0) { - $path = "/$subvols[0]$path"; + } elsif ($#ids == 0) { + my ($status, @path_info) = runCommand("btrfs subvol list @{[$fs->mount]}"); + if ($status != 0) { + die "Failed to find @{[$fs->mount]} subvolume id from btrfs\n"; + } + my @paths = join("", @path_info) =~ m/ID $ids[0] [^\n]* path ([^\n]*)/; + if ($#paths > 0) { + die "Btrfs returned multiple paths for a single subvolume id, mountpoint @{[$fs->mount]}\n"; + } elsif ($#paths != 0) { + die "Btrfs did not return a path for the subvolume at @{[$fs->mount]}\n"; + } + $path = "/$paths[0]$path"; } } } |