From 8892188532c336b3d5b7f3533fa8e802fba78fdb Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Tue, 20 Aug 2019 09:43:31 +0200 Subject: [PATCH] mxgrub: Add --set-default to switch default kernel Add new command `mxgrub --set-default {label}` which sets the default kernel. It is not automatically selected for the next boot. Note, that the designation of the default kernel is via the symlink /boot/bzImage.x86_64, which is distributed by the distmaster. Resolves #74 --- mxgrub/mxgrub | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/mxgrub/mxgrub b/mxgrub/mxgrub index 18bb491..a5fe017 100755 --- a/mxgrub/mxgrub +++ b/mxgrub/mxgrub @@ -12,6 +12,7 @@ sub USAGE { return <<"EOF" } $0 --initramfs : update /boot/grub/initramfs.igz from /project/admin/initramfs $0 --test : perform miscellaneous tests (VX50 board) $0 --reboot : attempt kexec reboot of selected kernel + $0 --set-default {label} : select this kernel as the default kernel EOF sub sys { @@ -363,10 +364,19 @@ sub cmd_reboot { sys('kexec',"/boot/$image",'--initrd=/boot/grub/initramfs.igz',"--command-line=root=LABEL=root $KERNEL_PARAMETER"); } +sub cmd_set_default { + my ($label)=@_; + my $image=label_to_image($label); + -e "/boot/$image" or die "/boot/$image: no such file\n"; + sys 'ln','-sf',$image,'/boot/bzImage.x86_64'; + scan_mariux(0); + update_grub_cfg(); +} + umask 022; check_grub_installation(); -our ($opt_list,$opt_update,$opt_initramfs,$opt_test,$opt_reboot); +our ($opt_list,$opt_update,$opt_initramfs,$opt_test,$opt_reboot,$opt_set_default); GetOptions( 'list' => \$opt_list, @@ -374,6 +384,7 @@ GetOptions( 'initramfs' => \$opt_initramfs, 'test' => \$opt_test, 'reboot' => \$opt_reboot, + 'set-default' => \$opt_set_default, ) or die USAGE; @@ -407,6 +418,9 @@ if ($opt_list) { } elsif ($opt_reboot) { @ARGV==0 or die USAGE; cmd_reboot(); +} elsif ($opt_set_default) { + @ARGV==1 or die USAGE; + cmd_set_default($ARGV[0]); } else { @ARGV==1 or die USAGE; cmd_install($ARGV[0]);