On Tue, 2010-10-12 at 11:32 -0300, Lucas Meneghel Rodrigues wrote:
> 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.

Ok, just found out that:

 * The method I've proposed doesn't work under debian.
 * For opensuse, it doesn't either. Apparently you're supposed to call
'grubonce' to set the once boot kernel.
 * Recent Ubuntu uses grub2 so anyone using autotest under recent ubuntu
to test kernels is out of luck, since boottool doesn't support grub2.

What a nightmare.

So for a short term solution, what about in the wrapper class of
boottool, in the method boot_once(), verify what is the os vendor, if it
is Red Hat or Fedora we execute

echo "savedefault --default=$entry_to_boot_once --once" | grub --batch

on the wrapper class itself, without resorting to calling boottool to do
the actual work? This way we'd support both Red Hat and other distros,
since for non-red hat systems boottool would be executed.

Of course, a more appropriate solution would be to rewrite boottool in
python and make it support grub2 already since we are at it, but this
would be too much work for now.

> 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/)//'`;


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

Reply via email to