summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--NEWS1
-rw-r--r--rebootin35
2 files changed, 35 insertions, 1 deletions
diff --git a/NEWS b/NEWS
new file mode 100644
index 0000000..151cda9
--- /dev/null
+++ b/NEWS
@@ -0,0 +1 @@
+- rebootin: add support for GRUB2
diff --git a/rebootin b/rebootin
index 9222bfb..1304b6e 100644
--- a/rebootin
+++ b/rebootin
@@ -12,10 +12,13 @@
# Reboot once on a specified image for grub or lilo
use strict;
+use MDK::Common;
my $lilo_conf = "/etc/lilo.conf";
my $grub_menu = "/boot/grub/menu.lst";
+my $grub2_menu = "/boot/grub2/grub.cfg";
+my $grub2_cfg = "/etc/default/grub";
my ($fastboot, $noreboot, $list, $menu);
while ($ARGV[0] =~ /^-/) {
@@ -41,7 +44,9 @@ my ($wanted_entry) = @ARGV;
my $bootloader = `/usr/sbin/detectloader -q` or die "Can't detect your bootloader\n";chomp $bootloader;
my @entries;
-if ($bootloader =~ /GRUB/) {
+if ($bootloader =~ /GRUB2/) {
+ grub2_conf();
+} elsif ($bootloader =~ /GRUB/) {
grub_conf();
} elsif ($bootloader =~ /LILO/) {
lilo_conf();
@@ -79,6 +84,34 @@ sub lilo_conf() {
system("lilo -R $wanted_entry"); die "error while wanting to reboot on $wanted_entry\n" if $?;
}
+sub grub2_conf() {
+ open(my $F, $grub2_menu) or die "grub2 is not installed ($grub2_menu is missing)\n";
+
+ # Update menu if needed:
+ if (cat_($grub2_cfg) !~ /^GRUB_DEFAULT="saved"/sm) {
+ append_to_file($grub2_cfg, qq(GRUB_DEFAULT="saved"\n));
+ system('updates-grub2');
+ }
+
+ foreach (<$F>) {
+ if (/^[^#]*menuentry\s+'([^']*)/) {
+ push @entries, $1;
+ }
+ }
+ list_entries() if $list;
+ $wanted_entry = select_entry() if $menu;
+ @entries > 0 or die "bad menu.lst (no entry found)\n";
+
+ if (member($wanted_entry, @entries)) {
+ system('grub2-reboot', $wanted_entry);
+ write_fast_boot() if $fastboot;
+ return;
+ }
+
+ print STDERR "$wanted_entry not found\n";
+ usage(); # not found
+}
+
sub grub_conf() {
open(my $F, $grub_menu) or die "grub is not installed ($grub_menu is missing)\n";
my @short_entries;