summaryrefslogtreecommitdiff
path: root/scripts/vyatta-boot-image.pl
diff options
context:
space:
mode:
authorBob Gilligan <gilligan@vyatta.com>2011-10-21 15:08:15 -0700
committerBob Gilligan <gilligan@vyatta.com>2011-10-21 15:08:15 -0700
commita85dfe27f88d18c226a3e7cf7c9e8457806d284a (patch)
treea3113c32b64622f777d00c8cabe1363cb9edb5b1 /scripts/vyatta-boot-image.pl
parent6c88d36a86d2ed3a9674742f467674ca36205072 (diff)
downloadvyatta-op-a85dfe27f88d18c226a3e7cf7c9e8457806d284a.tar.gz
vyatta-op-a85dfe27f88d18c226a3e7cf7c9e8457806d284a.zip
Bugfix 7502: Make "delete system image" work correctly on Xen
Also, improved detection of currently running image in the "rename system image" command.
Diffstat (limited to 'scripts/vyatta-boot-image.pl')
-rwxr-xr-xscripts/vyatta-boot-image.pl47
1 files changed, 36 insertions, 11 deletions
diff --git a/scripts/vyatta-boot-image.pl b/scripts/vyatta-boot-image.pl
index 7c80da7..d2eb3fd 100755
--- a/scripts/vyatta-boot-image.pl
+++ b/scripts/vyatta-boot-image.pl
@@ -59,13 +59,16 @@ sub parseGrubCfg {
my @entries = ();
my $in_entry = 0;
my $idx = 0;
+ my $curver;
my $running_boot_cmd=`cat /proc/cmdline`;
if (! ($running_boot_cmd =~ s/BOOT_IMAGE=//)) {
- # Mis-formatted boot cmd. It might be Xen, which boots with pygrub.
- # We use a symlink in this case to point to the default image.
+ # Mis-formatted boot cmd. Look harder to to find the current
+ # version string.
#
- if (-l $XEN_DEFAULT_IMAGE) {
- $running_boot_cmd = readlink($XEN_DEFAULT_IMAGE);
+ $curver = curVer();
+ if (defined($curver)) {
+ # Only one of $running_boot_cmd or $curver should be defined.
+ undef $running_boot_cmd;
}
}
while (<$fd>) {
@@ -108,10 +111,19 @@ sub parseGrubCfg {
} else {
$ehash{'reset'} = 0;
}
- if (/$running_boot_cmd/) {
- $ehash{'running_vers'} = 1;
- } else {
- $ehash{'running_vers'} = 0;
+ if (defined($running_boot_cmd)) {
+ if (/$running_boot_cmd/) {
+ $ehash{'running_vers'} = 1;
+ } else {
+ $ehash{'running_vers'} = 0;
+ }
+ } elsif (defined($curver)) {
+ my $matchstr = "/boot/$curver/vmlinuz";
+ if (/$matchstr/) {
+ $ehash{'running_vers'} = 1;
+ } else {
+ $ehash{'running_vers'} = 0;
+ }
}
push @entries, \%ehash;
$in_entry++;
@@ -392,9 +404,22 @@ sub curVer {
my $vers = `awk '{print \$1}' /proc/cmdline`;
# In an image-booted system, the image name is the directory name
- # directory under "/boot" in the pathname of the kernel we booted.
- $vers =~ s/BOOT_IMAGE=\/boot\///;
- $vers =~ s/\/?vmlinuz.*\n$//;
+ # under "/boot" in the pathname of the kernel we booted.
+ if ($vers =~ s/BOOT_IMAGE=\/boot\///) {
+ $vers =~ s/\/?vmlinuz.*\n$//;
+ } else {
+ # Boot command line is not formatted as it would be for a system
+ # booted via grub2 with union mounted root filesystem. Another
+ # possibility is that it the system is Xen booted via pygrub.
+ #
+ if (-l $XEN_DEFAULT_IMAGE) {
+ # On Xen/pygrub systems, we figure out the running version by
+ # looking at the bind mount of /boot.
+ $vers = `mount | awk '/on \\/boot / { print \$1 }'`;
+ $vers =~ s/\/live\/image\/boot\///;
+ chomp($vers);
+ }
+ }
# In a non-image system, the kernel resides directly under "/boot".
# No second-level directory means that $vers will be null.