From 5ac06aa6e9169e2a645361bded8ee675c20e3638 Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Tue, 20 Aug 2019 08:56:20 +0200 Subject: [PATCH 1/3] mxgrub: exclude .git from ramdisk mxgrub --initramfs builds /boot/grub/initramfs.igz from /project/admin/initramf. Exclude ".git*", so we can put the directory under revision control. --- mxgrub/mxgrub | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mxgrub/mxgrub b/mxgrub/mxgrub index ec0f0be..588bfde 100755 --- a/mxgrub/mxgrub +++ b/mxgrub/mxgrub @@ -352,7 +352,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 { From c881fbba94eeb6b814ae1deaca782a78059f49e6 Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Tue, 20 Aug 2019 09:25:46 +0200 Subject: [PATCH 2/3] mxgrub: Remove redundant exit status checks Callers of the function sys() don't need to check the return value, because sys() doesn't return at all if the external command fails. Remove `and exit 1` after sys(). Closes #52 --- mxgrub/mxgrub | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mxgrub/mxgrub b/mxgrub/mxgrub index 588bfde..18bb491 100755 --- a/mxgrub/mxgrub +++ b/mxgrub/mxgrub @@ -322,18 +322,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"; } From 8892188532c336b3d5b7f3533fa8e802fba78fdb Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Tue, 20 Aug 2019 09:43:31 +0200 Subject: [PATCH 3/3] 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]);