[Libguestfs] [PATCH] GuestOS: Fix augeas grub configuration

Matthew Booth mbooth at redhat.com
Thu Apr 29 13:05:13 UTC 2010


Augeas now configures the Grub lens for /boot/grub/menu.lst by default. The code
which was checking this was broken in the case where there was more than 1
included path.

We now check if /boot/grub/menu.lst is included. If it is, we don't reload. If
it isn't, we add it, but don't remove any other config first.

This fixes RHBZ#586822
---
 lib/Sys/VirtV2V/GuestOS/RedHat.pm |   25 +++++++++++++++++--------
 1 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/lib/Sys/VirtV2V/GuestOS/RedHat.pm b/lib/Sys/VirtV2V/GuestOS/RedHat.pm
index 6dc4c95..a4680c5 100644
--- a/lib/Sys/VirtV2V/GuestOS/RedHat.pm
+++ b/lib/Sys/VirtV2V/GuestOS/RedHat.pm
@@ -87,7 +87,7 @@ sub new
     bless($self, $class);
 
     $self->_init_selinux();
-    $self->_init_augeas_modprobe();
+    $self->_init_augeas();
 
     return $self;
 }
@@ -107,7 +107,7 @@ sub _init_selinux
     $g->touch('/.autorelabel');
 }
 
-sub _init_augeas_modprobe
+sub _init_augeas
 {
     my $self = shift;
 
@@ -158,15 +158,24 @@ sub _init_augeas_modprobe
             }
         }
 
-        # Remove all includes for the Grub lens, and add only
-        # /boot/grub/menu.lst
+        # Check if /boot/grub/menu.lst is included by the Grub lens
+        my $found = 0;
         foreach my $incl ($g->aug_match("/augeas/load/Grub/incl")) {
-            $g->aug_rm($incl);
+            if ($g->aug_get($incl) eq '/boot/grub/menu.lst') {
+                $found = 1;
+                last;
+            }
+        }
+
+        # If it wasn't there, add it
+        unless ($found) {
+            $g->aug_set("/augeas/load/Grub/incl[last()+1]",
+                        "/boot/grub/menu.lst");
+
+            # Make augeas pick up the new configuration
+            $g->aug_load();
         }
-        $g->aug_set("/augeas/load/Grub/incl[last()+1]", "/boot/grub/menu.lst");
 
-        # Make augeas pick up the new configuration
-        $g->aug_load();
     };
 
     # The augeas calls will die() on any error.
-- 
1.6.6.1




More information about the Libguestfs mailing list