Skip to content

Mxgrub: consistency check of config and bootdir #15

Merged
merged 4 commits into from
Oct 25, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 48 additions & 2 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) installed aren't listed in the menu.

Consider a rewrite of grub.cfg (and mind $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 @@ -131,7 +176,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',...)
Expand Down Expand Up @@ -279,7 +324,8 @@ 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();
check_grub_menu_and_boot_dir();

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

Expand Down