SHA256
1
0
forked from pool/grub2
grub2/grub2-once
Andrei Borzenkov 9bc71d03db Accepting request 295632 from home:michael-chang:sle-12-merge
- Merge changes from SLE12
- Do not pass root= when root is on nfs (bnc#894374) 
  * modified grub2-pass-corret-root-for-nfsroot.patch
  * modified grub2-secureboot-provide-linuxefi-config.patch
  * modified grub2-secureboot-use-linuxefi-on-uefi.patch
- Fix xen pvops kernel not appear on menu (bnc#895286)
  * modified grub2-fix-menu-in-xen-host-server.patch 
- Workaround grub2-once (bnc#892358)
  * added grub2-btrfs-workaround-grub2-once.patch
  * added grub2-once.service
  * modified grub2-once
- Fix busy-loop and hang while network booting (bnc#870613)
  * added grub2-netboot-hang.patch
- Add warning in grubenv file about editing it directly (bnc#887008)
  * added grub2-editenv-add-warning-message.patch
- Fix broken graphics with efifb on QEMU/KVM and nomodeset (bnc#884558)
  * added grub2-efi-disable-video-cirrus-and-bochus.patch 
- Disable video support on Power (bnc#877142) 
  * added grub2-ppc64le-disable-video.patch
- Track occupied memory so it can be released on exit (bnc#885026)
  * added grub2-ppc64le-memory-map.patch
- Fix grub.xen config searching path on boot partition (bnc#884828)
- Add linux16 and initrd16 to grub.xen (bnc#884830)
  * added grub2-xen-linux16.patch
- VLAN tag support (fate#315753)
  * added 0001-Add-bootargs-parser-for-open-firmware.patch
  * added 0002-Add-Virtual-LAN-support.patch
- Use chainloader to boot xen.efi under UEFI (bnc#871857)
  * added grub2-efi-xen-chainload.patch
- Use device part of chainloader target, if present (bnc#871857)

OBS-URL: https://build.opensuse.org/request/show/295632
OBS-URL: https://build.opensuse.org/package/show/Base:System/grub2?expand=0&rev=148
2015-04-13 17:58:16 +00:00

145 lines
2.8 KiB
Perl

#!/usr/bin/perl
#
# (C) 2014 mchang@suse.com
#
# 2014-02-20 jw@suse.de
use strict;
my $grub2_dir;
my $grub2_reboot;
my $show_mapped;
my $id_name;
my @menuentry;
sub parse_menuentry {
my ($parent, $menu) = @_;
my @m = $menu =~ /(submenu|menuentry) \s+ '([^']*)' .*? ( \{ (?: [^{}]* | (?3))* \} )/sxg;
for (my $i = 0; $i <= $#m; $i += 3) {
my $type = $m[$i];
my $title = $m[$i+1];
my $data = $m[$i+2];
my $name = ($parent) ? "$parent>$title" : "$title";
if ($type eq "menuentry") {
push @menuentry, $name;
} elsif ($type eq "submenu") {
&parse_menuentry ($name, $data);
}
}
}
# Enable restore grubenv service (bnc#892358)
# Restore grubenv settings for booting default entry to workaround the grub2-once cannot
# work and function properly on lvm, md and s390.
sub enable_restore_grubenv_service {
my $systemctl="/usr/bin/systemctl";
if (-x $systemctl) {
system "$systemctl --no-reload enable grub2-once >/dev/null 2>&1";
}
}
$id_name = "";
if (@ARGV == 2 && ($ARGV[0] eq "--show-mapped")) {
$show_mapped = 1;
$id_name = $ARGV[1];
} elsif (@ARGV == 1) {
$show_mapped = 0;
$id_name = $ARGV[0];
}
die "wrong command line options, try --help\n" if ($id_name eq "");
open(SYSCONF, "</etc/sysconfig/bootloader") || die "cannot read bootloader sysconfig: $!\n";
$grub2_dir = "";
while (<SYSCONF>) {
if (/LOADER_TYPE="(.*)"/) {
my $bl = $1;
if ($bl eq "grub2" || $bl eq "grub2-efi") {
$grub2_dir = "/boot/grub2";
$grub2_reboot = "/usr/sbin/grub2-reboot";
}
last;
}
}
close (SYSCONF);
if ($id_name eq "--help" or $id_name eq "-h")
{
print "Usage: grub2-once [--show-mapped ID | --list | ID | NAME_SUBSTRING ]\n";
system "$grub2_reboot \"--help\"";
exit 0;
}
die "no grub2_dir" if ($grub2_dir eq "");
open(MENU, "<$grub2_dir/grub.cfg") || die "cannot read grub.cfg in $grub2_dir: $!\n";
undef $/;
while (<MENU>) {
&parse_menuentry ("", $_);
}
close (MENU);
my $ret = "";
my $name = "";
my $id = -1;
if ($id_name eq '--list')
{
my $c = 0;
foreach my $e (@menuentry)
{
printf "%6d %s\n", $c, $e;
$c++;
}
exit 0;
}
if ($id_name =~ m!^[0-9]+$!) {
if ($id_name < @menuentry) {
$id = $id_name;
$name = $menuentry[$id];
$ret = $name;
}
} else {
my $i = -1;
my $c = 0;
$name = $id_name;
foreach my $e (@menuentry) {
if ($e =~ qr!\Q$name\E!) {
$i = $c;
last;
}
} continue {
++$c;
}
if ($i >= 0) {
$id = $i;
$name = $menuentry[$id];
$ret = "$id";
}
}
if ($show_mapped > 0) {
print $ret;
} else {
system "$grub2_reboot \"$name\"";
enable_restore_grubenv_service;
}