diff --git a/mxgrub/mxgrub b/mxgrub/mxgrub index ec0f0be..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 { @@ -322,18 +323,18 @@ sub cmd_install { update_grub_cfg(); if (has_esp) { - sys 'mount','-L','ESP','/boot/efi' and exit 1; + sys 'mount','-L','ESP','/boot/efi'; if (-d '/boot/efi/EFI/grub/grubx64.efi') { print "GRUB for UEFI is already installed.\n"; } else { - sys 'grub-install','--target=x86_64-efi','--no-nvram',$root_disk and exit 1; + sys 'grub-install','--target=x86_64-efi','--no-nvram',$root_disk; } - sys 'umount','/boot/efi' and exit 1; + sys 'umount','/boot/efi'; } if ($mbr_type ne 'GRUB') { - sys 'grub-install','--target=i386-pc',$root_disk and exit 1; + sys 'grub-install','--target=i386-pc',$root_disk; } else { print "GRUB is already installed in MBR.\n"; } @@ -352,7 +353,7 @@ sub cmd_update { } sub cmd_initramfs { - sys('bash','-c','cd /project/admin/initramfs;find .|cpio -H newc -o | gzip > /boot/grub/initramfs.igz'); + sys('bash','-c','cd /project/admin/initramfs ; find . -name ".git*" -prune -or -print | cpio -H newc -o | gzip > /boot/grub/initramfs.igz'); } sub cmd_reboot { @@ -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]);