Skip to content

Commit

Permalink
install-grub.pl: support bindmounts and btrfs subvolumes
Browse files Browse the repository at this point in the history
Specifically this allows bind-mounting your `/boot` directory with
NixOS impermanence.
  • Loading branch information
kira-bruneau committed Jan 17, 2025
1 parent 5d0935a commit 437f40c
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions nixos/modules/system/boot/loader/grub/install-grub.pl
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,20 @@ sub runCommand {
# Discover information about the location of the bootPath
struct(Fs => {
device => '$',
root => '$',
type => '$',
mount => '$',
});

# Figure out what filesystem is used for the directory with init/initrd/kernel files
sub GetFs {
my ($dir) = @_;
my ($status, @pathInfo) = runCommand("@utillinux@/bin/findmnt", "-n", "-v", "-o", "SOURCE,FSTYPE,TARGET", "-T", @{[$dir]});
my ($status, @pathInfo) = runCommand("@utillinux@/bin/findmnt", "-n", "-v", "-o", "SOURCE,FSROOT,FSTYPE,TARGET", "-T", @{[$dir]});
if ($status != 0 || @pathInfo != 1) {
die "Failed to get file system (returned $status) for @{[$dir]}";
}
my @fields = split /\s+/, $pathInfo[0];
return Fs->new(device => $fields[0], type => $fields[1], mount => $fields[2]);
return Fs->new(device => $fields[0], root => $fields[1], type => $fields[2], mount => $fields[3]);
}
struct (Grub => {
path => '$',
Expand All @@ -132,10 +133,7 @@ sub GetFs {
sub GrubFs {
my ($dir) = @_;
my $fs = GetFs($dir);
my $path = substr($dir, length($fs->mount));
if (substr($path, 0, 1) ne "/") {
$path = "/$path";
}
my $path = $fs->root . substr($dir, length($fs->mount));
my $search = "";

# ZFS is completely separate logic as zpools are always identified by a label
Expand Down

0 comments on commit 437f40c

Please sign in to comment.