| 1 | package Linux::Bootloader::Lilo; | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | Linux::Bootloader::Lilo - Parse and modify LILO configuration files. | ||
| 6 | |||
| 7 | =head1 SYNOPSIS | ||
| 8 | |||
| 9 | use Linux::Bootloader; | ||
| 10 | use Linux::Bootloader::Lilo; | ||
| 11 | |||
| 12 | my $bootloader = Linux::Bootloader::Lilo->new(); | ||
| 13 | my $config_file='/etc/lilo.conf'; | ||
| 14 | |||
| 15 | $bootloader->read($config_file) | ||
| 16 | |||
| 17 | # add a kernel | ||
| 18 | $bootloader->add(%hash) | ||
| 19 | |||
| 20 | # remove a kernel | ||
| 21 | $bootloader->remove(2) | ||
| 22 | |||
| 23 | # set new default | ||
| 24 | $bootloader->set_default(1) | ||
| 25 | |||
| 26 | $bootloader->write($config_file) | ||
| 27 | |||
| 28 | |||
| 29 | =head1 DESCRIPTION | ||
| 30 | |||
| 31 | This module provides functions for working with LILO configuration files. | ||
| 32 | |||
| 33 | Adding a kernel: | ||
| 34 | - add kernel at start, end, or any index position. | ||
| 35 | - kernel path and title are required. | ||
| 36 | - root, kernel args, initrd are optional. | ||
| 37 | - any options not specified are copied from default. | ||
| 38 | - remove any conflicting kernels if force is specified. | ||
| 39 | |||
| 40 | Removing a kernel: | ||
| 41 | - remove by index position | ||
| 42 | - or by title/label | ||
| 43 | |||
| 44 | |||
| 45 | =head1 FUNCTIONS | ||
| 46 | |||
| 47 | Also see L<Linux::Bootloader> for functions available from the base class. | ||
| 48 | |||
| 49 | =head2 new() | ||
| 50 | |||
| 51 | Creates a new Linux::Bootloader::Lilo object. | ||
| 52 | |||
| 53 | =head2 install() | ||
| 54 | |||
| 55 | Attempts to install bootloader. | ||
| 56 | Takes: nothing. | ||
| 57 | Returns: undef on error. | ||
| 58 | |||
| 59 | =head2 boot-once() | ||
| 60 | |||
| 61 | Attempts to set a kernel as default for one boot only. | ||
| 62 | Takes: string. | ||
| 63 | Returns: undef on error. | ||
| 64 | |||
| 65 | =cut | ||
| 66 | |||
| 67 | |||
| 68 | use strict; | ||
| 69 | use warnings; | ||
| 70 | use Linux::Bootloader | ||
| 71 | |||
| 72 | @Linux::Bootloader::Lilo::ISA = qw(Linux::Bootloader); | ||
| 73 | use base 'Linux::Bootloader'; | ||
| 74 | |||
| 75 | |||
| 76 | use vars qw( $VERSION ); | ||
| 77 | our $VERSION = '1.2'; | ||
| 78 | |||
| 79 | |||
| 80 | sub new { | ||
| 81 | my $this = shift; | ||
| 82 | my $class = ref($this) || $this; | ||
| 83 | my $self = bless({}, $class); | ||
| 84 | |||
| 85 | $self->SUPER::new(); | ||
| 86 | |||
| 87 | return $self; | ||
| 88 | } | ||
| 89 | |||
| 90 | sub _set_config_file { | ||
| 91 | my $self=shift; | ||
| 92 | $self->{'config_file'}='/etc/lilo.conf'; | ||
| 93 | } | ||
| 94 | |||
| 95 | |||
| 96 | |||
| 97 | ### LILO functions ### | ||
| 98 | |||
| 99 | |||
| 100 | # Run command to install bootloader | ||
| 101 | |||
| 102 | sub install { | ||
| 103 | my $self=shift; | ||
| 104 | |||
| 105 | system("/sbin/lilo"); | ||
| 106 | if ($? != 0) { | ||
| 107 | warn ("ERROR: Failed to run lilo.\n") && return undef; | ||
| 108 | } | ||
| 109 | return 1; | ||
| 110 | } | ||
| 111 | |||
| 112 | |||
| 113 | # Set kernel to be booted once | ||
| 114 | |||
| 115 | sub boot_once { | ||
| 116 | my $self=shift; | ||
| 117 | my $label=shift; | ||
| 118 | |||
| 119 | return undef unless defined $label; | ||
| 120 | |||
| 121 | if (system("/sbin/lilo","-R","$label")) { | ||
| 122 | warn ("ERROR: Failed to set boot-once.\n") && return undef; | ||
| 123 | } | ||
| 124 | return 1; | ||
| 125 | } | ||
| 126 | |||
| 127 | |||
| 128 | 1; | ||
| 129 | |||
| 130 | |||
| 131 | =head1 AUTHOR | ||
| 132 | |||
| 133 | Open Source Development Labs, Engineering Department <eng@osdl.org> | ||
| 134 | |||
| 135 | =head1 COPYRIGHT | ||
| 136 | |||
| 137 | Copyright (C) 2006 Open Source Development Labs | ||
| 138 | All Rights Reserved. | ||
| 139 | |||
| 140 | This script is free software; you can redistribute it and/or modify it | ||
| 141 | under the same terms as Perl itself. | ||
| 142 | |||
| 143 | =head1 SEE ALSO | ||
| 144 | |||
| 145 | L<Linux::Bootloader> | ||
| 146 | |||
| 147 | =cut | ||
| 148 |