Skip to content

Commit

Permalink
mxgrub: add grub.cfg consistency check
Browse files Browse the repository at this point in the history
'check_grub_menu_and_boot_dir' compares the content
of the boot-menu (grub.cfg), and the filesystem content
in /boot.
  • Loading branch information
thomas committed Oct 17, 2017
1 parent a0d8f32 commit 4ac501c
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions mxgrub/mxgrub
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,51 @@ sub check_mbr {

}

sub check_grub_menu_and_boot_dir {
my $distmaster=`distmaster`; chop $distmaster;
my $missing_in_menu=0;
my $missing_in_boot=0;
my $inconsistent = 1;

my @kernels_menu = grep {/menuentry.+?mariux-\d/} split m/\n/, read_file('/boot/grub/grub.cfg');
@kernels_menu = map {/["']mariux-[\d\.]+-(\d+)['"]/; "mariux.$1"} @kernels_menu;

my @tmp = grep {/mariux\.\d+/} scandir('/boot');
my %installed;
for (@tmp) {
$installed{$_} = 0; # filesystem data (should have no dupes).
}

for my $k (@kernels_menu) {
if (defined $installed{$k}) {
$installed{$k}+=1; # mind, the top menu entry occurs twice.
} else {
$missing_in_boot++;
}
}

for my $k (keys %installed) {
$missing_in_menu++ if $installed{$k} < 1;
}

if ($missing_in_boot == 0 and $missing_in_boot == 0) {
$inconsistent = 0;
}

warn << "EOF" if $inconsistent;
Note: GRUB menu and installed kernels differ.
$missing_in_boot Kernel(s) from the menu are missing in '/boot'.
$missing_in_menu Kernel(s) aren't listed in the menu.
Consider a rewrite of grub.cfg (on $distmaster):
$0 --update
EOF
}

sub check_grub_installation {
my $fingerprint='[ab]*.mod'; # this 'scans' just a dozen, and not 200 files.
my $sum_lib = ` cat /usr/lib/grub/i386-pc/$fingerprint | md5sum `;
Expand Down Expand Up @@ -280,6 +325,7 @@ sub cmd_initramfs {
}

check_grub_installation();
check_grub_menu_and_boot_dir();

our ($opt_list,$opt_update,$opt_initramfs,$opt_test);

Expand Down

0 comments on commit 4ac501c

Please sign in to comment.