From 4ec03ae87333c36f24ed91d1fe99e89c955ffb9f Mon Sep 17 00:00:00 2001 From: thomas Date: Tue, 17 Oct 2017 09:44:48 +0200 Subject: [PATCH 1/4] mxgrub: function call fixup Adding the semicolon makes the code easier to maintain. --- mxgrub/mxgrub | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mxgrub/mxgrub b/mxgrub/mxgrub index d22c3c3..c82b7d4 100755 --- a/mxgrub/mxgrub +++ b/mxgrub/mxgrub @@ -279,7 +279,7 @@ sub cmd_initramfs { sys('bash','-c','cd /project/admin/initramfs;find .|cpio -H newc -o | gzip > /boot/grub/initramfs.igz'); } -check_grub_installation +check_grub_installation(); our ($opt_list,$opt_update,$opt_initramfs,$opt_test); From a0d8f3237bcb05df8ddfcca8c3f5378e18e9371d Mon Sep 17 00:00:00 2001 From: thomas Date: Tue, 17 Oct 2017 10:30:01 +0200 Subject: [PATCH 2/4] mxgrub: fix scandir routine Use the handle, not the name. --- mxgrub/mxgrub | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mxgrub/mxgrub b/mxgrub/mxgrub index c82b7d4..91bee3c 100755 --- a/mxgrub/mxgrub +++ b/mxgrub/mxgrub @@ -131,7 +131,7 @@ sub root_dev { sub scandir { my ($dir)=@_; opendir my $d,$dir or die "$dir: $!\n"; - return grep !/^\.\.?$/,readdir $dir; + return grep !/^\.\.?$/,readdir $d; } our @MARIUX; # ( 'mariux-3.14.51-69','mariux-3.14.51-68',...) From 4ac501c0aff45254b0155ef5477f78ceb3ad71e2 Mon Sep 17 00:00:00 2001 From: thomas Date: Tue, 17 Oct 2017 11:01:00 +0200 Subject: [PATCH 3/4] mxgrub: add grub.cfg consistency check 'check_grub_menu_and_boot_dir' compares the content of the boot-menu (grub.cfg), and the filesystem content in /boot. --- mxgrub/mxgrub | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/mxgrub/mxgrub b/mxgrub/mxgrub index 91bee3c..fc33b0c 100755 --- a/mxgrub/mxgrub +++ b/mxgrub/mxgrub @@ -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 `; @@ -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); From 8b6508296ed584e398fed4817ec8cb42b6a9bc65 Mon Sep 17 00:00:00 2001 From: thomas Date: Tue, 17 Oct 2017 11:38:56 +0200 Subject: [PATCH 4/4] mxgrub: make notifications a bit clearer --- mxgrub/mxgrub | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mxgrub/mxgrub b/mxgrub/mxgrub index fc33b0c..b847157 100755 --- a/mxgrub/mxgrub +++ b/mxgrub/mxgrub @@ -78,9 +78,9 @@ sub check_grub_menu_and_boot_dir { 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. + $missing_in_menu Kernel(s) installed aren't listed in the menu. - Consider a rewrite of grub.cfg (on $distmaster): + Consider a rewrite of grub.cfg (and mind $distmaster): $0 --update