Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #100 from mariux64/update-mxgrub
Update mxgrub
  • Loading branch information
pmenzel committed Sep 2, 2019
2 parents d6da335 + 8892188 commit 42f232a
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions mxgrub/mxgrub
Expand Up @@ -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 {
Expand Down Expand Up @@ -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";
}
Expand All @@ -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 {
Expand All @@ -363,17 +364,27 @@ 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,
'update' => \$opt_update,
'initramfs' => \$opt_initramfs,
'test' => \$opt_test,
'reboot' => \$opt_reboot,
'set-default' => \$opt_set_default,

) or die USAGE;

Expand Down Expand Up @@ -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]);
Expand Down

0 comments on commit 42f232a

Please sign in to comment.