Skip to content

Commit

Permalink
mxgrub: Add --reboot
Browse files Browse the repository at this point in the history
Add a new command `mxgrub --reboot` which reboots to the selected kernel
via kexec.

Notes:

    * Do a sync before triggering the reboot, so that services are still
    available while the bulk of dirty pages is written, which can take
    a relevant time on big machines.

    * kexec (without -l, -p, -e, or -f) loads the kernel and than calls
    shutdown, which is handled by systemd. So this is a full shutdown ;
    systemd will stop services, unmount filesystems and sync all disks
    (again). It just recognizes the loaded kernel and calls the
    equivalent of (`kexec -e` instead of `reboot -f`) in the very last
    step. We just avoid the EFI/BIOS initialization and grub and kernel
    loading.

    * When an nfs server restarts, clients currently get 90 seconds to
    renew their leases. Some nfs file operations from the clients are
    blocked during this time, so this adds to the time, a workstation
    appears to be frozen to the user. We can consider to reduce this
    lease_time of our servers to a lower value. The disadvantage is,
    that the clients need to send more RENEW request (2/3 of the lease
    time, so every minute currently) and might lose lock state if the
    network is interrupted for a longer time.

    * Strictly speaking, kexec() has not much to do with grub. However,
    in our implementation of the grub based boot it is related because
    the record of which kernel to boot next (the selected kernel)
    is kept in the grub environment file. So if we want the kexec based
    reboot to start the same kernel as a reboot sequence over grub
    would do, we need to read the grub environment file. This should be
    enough excude to implement the command in mxgrub.

    * Loading of the new kernel might fail on machines where not enough
    continuous physical memory is availble because of fragmentation.

Timings:

    * reboot theinernet (to lightdm login prompt) :  47 ->  22 seconds
    * reboot claptrap (to console login prompt)   : 160 ->  59 seconds
    * reboot claptrap (to NFS server available)   : 165 ->  43 seconds
    * reboot claptrap (to locks available)        : 262 -> 141 seconds
  • Loading branch information
donald committed May 8, 2019
1 parent f85e6ad commit 7a55311
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion mxgrub/mxgrub
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ sub USAGE { return <<"EOF" }
$0 --update : only scan /boot and rewrite grub.cfg
$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
EOF

sub sys {
Expand Down Expand Up @@ -352,16 +353,26 @@ sub cmd_initramfs {
sys('bash','-c','cd /project/admin/initramfs;find .|cpio -H newc -o | gzip > /boot/grub/initramfs.igz');
}

sub cmd_reboot {
my $chosen=get_chosen();
my $image=label_to_image($chosen);
-e "/boot/$image" or die "/boot/$image: no such file\n";
sys('sync');
sys('kexec',"/boot/$image",'--reuse-cmdline','--initrd=/boot/grub/initramfs.igz');
}

umask 022;
check_grub_installation();

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

GetOptions(
'list' => \$opt_list,
'update' => \$opt_update,
'initramfs' => \$opt_initramfs,
'test' => \$opt_test,
'reboot' => \$opt_reboot,

) or die USAGE;

$opt_list && $opt_update and die USAGE;
Expand Down Expand Up @@ -391,6 +402,9 @@ if ($opt_list) {
} else {
print "System booted using UEFI: no\n";
}
} elsif ($opt_reboot) {
@ARGV==0 or die USAGE;
cmd_reboot();
} else {
@ARGV==1 or die USAGE;
cmd_install($ARGV[0]);
Expand Down

0 comments on commit 7a55311

Please sign in to comment.