Skip to content

Instantly share code, notes, and snippets.

@jpritikin
Created October 18, 2019 22:11
Show Gist options
  • Save jpritikin/7f9d3dcdf8bce3e89137cc1925ff7d15 to your computer and use it in GitHub Desktop.
Save jpritikin/7f9d3dcdf8bce3e89137cc1925ff7d15 to your computer and use it in GitHub Desktop.
perl script to select which grub.cfg to load from the EFI partition
#!/usr/bin/perl
use Modern::Perl '2018';
use Fatal qw(open);
die "$0 volume-group logical-volume" if @ARGV != 2;
our $vg=$ARGV[0];
our $lv=$ARGV[1];
die "/dev/$vg/$lv doesn't exist" if ! -e "/dev/$vg/$lv";
sub getBlkUUID() {
my @blk = `blkid |grep $vg-$lv`;
die "$vg-$lv not unique" if @blk != 1;
if ($blk[0] =~ /UUID=\"(\S*)\"/) {
$1;
} else {
die "Can't find UUID in $blk[0]"
}
}
my ($ign, $vgid, $lvid) = split /\s+/, `lvs /dev/$vg/$lv --options vg_uuid,lv_uuid --noheadings`;
open my $fh, ">/boot/efi/EFI/ubuntu/grub.cfg.new";
select $fh;
print "search.fs_uuid ".getBlkUUID()." root lvmid/$vgid/$lvid \n";
print q[set prefix=($root)'/boot/grub'
configfile $prefix/grub.cfg
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment