The method used to set boot once with grub doesn't work for some
distros, such as Red Hat based ones. After some research, discovered
a method that is expected to work with grub from version 0.97 forward
even for Red Hat based systems.

TODO: I still need to test this method with other Linux distros
such as Debian/Ubuntu. It *should*, but you never know. I am sending
it anyway so the idea can be evaluated.

Signed-off-by: Lucas Meneghel Rodrigues <[email protected]>
---
 client/tools/boottool |   38 +++++++-------------------------------
 1 files changed, 7 insertions(+), 31 deletions(-)

diff --git a/client/tools/boottool b/client/tools/boottool
index 4dafbab..00e071f 100755
--- a/client/tools/boottool
+++ b/client/tools/boottool
@@ -1598,46 +1598,22 @@ sub boot_once {
 
   unless ( $entry_to_boot_once ) { print "No kernel\n"; return undef;}
   $self->read();
-  my $default=$self->get_default();
 
-  if ( $default == $self->_lookup($entry_to_boot_once)){
-     warn "The default and once-boot kernels are the same.  No action taken.  
\nSet default to something else, then re-try.\n";
-     return undef;
-  }
   if ( $self->_get_bootloader_version() < 0.97 ){
      warn "This function works for grub version 0.97 and up.  No action taken. 
 \nUpgrade, then re-try.\n";
      return undef;
   }
 
-  $self->set_default('saved');
-  if ( ! -f '/boot/grub/default' ){
-     open FH, '>/boot/grub/default'; 
-     my $file_contents="default
-#
-#
-#
-#
-#
-#
-#
-#
-#
-#
-# WARNING: If you want to edit this file directly, do not remove any line
-# from this file, including this warning. Using `grub-set-default\' is
-# strongly recommended.
-";
-    print FH $file_contents;
-    close FH;
-  }
-  $self->set_default( "$entry_to_boot_once" );
-  $self->update( 'option'=>'','fallback' => $default );
-  $self->update( 
'update-kernel'=>"$entry_to_boot_once",'option'=>'','savedefault' => 'fallback' 
);
-  $self->update( 'update-kernel'=>"$default",'option'=>'', 'savedefault' => '' 
);
-  $self->write();
-  
+  # if not a number, do title lookup
+  if ( $entry_to_boot_once !~ /^\d+$/ ) {
+    $entry_to_boot_once = $self->_lookup($entry_to_boot_once);
+    return undef unless ( defined $entry_to_boot_once );
+  }
+
+  return `echo "savedefault --default=$entry_to_boot_once" --once | grub 
--batch`;
 }
 
+
 sub _get_bootloader_version {
   my $self = shift;
   return `grub --version | sed 's/grub (GNU GRUB //' | sed 's/)//'`;
-- 
1.7.2.3

_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to