Imported Upstream version 24.1
[rrq/maintain_lilo.git] / scripts / liloconfig
1 #!/usr/bin/perl -w
2
3 #       liloconfig -  creating a new lilo.conf file
4 #       
5 #       
6 #       Copyright 2011-2014 Joachim Wiedorn <joodevel at joonet.de>
7 #       
8 #       This program is free software; you can redistribute it and/or modify
9 #       it under the terms of the GNU General Public License as published by
10 #       the Free Software Foundation; either version 2 of the License, or
11 #       (at your option) any later version.
12 #       
13 #       This program is distributed in the hope that it will be useful,
14 #       but WITHOUT ANY WARRANTY; without even the implied warranty of
15 #       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 #       GNU General Public License for more details.
17 #       
18 #       You should have received a copy of the GNU General Public License
19 #       along with this program; if not, write to the Free Software
20 #       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21 #       MA 02110-1301, USA.
22
23 #---- some modules
24 use strict;
25 use warnings;
26 use Getopt::Std;
27 use Pod::Usage;
28 use File::Copy;
29
30
31 #---- global variables
32 my $prog = $0;
33 $prog =~ s#.*/##;
34 my $version = "0.4";
35
36 #---- parameter check
37 # h: help, v: verbose, f: force
38 our $opt_h = 0;
39 our $opt_v = 0;
40 our $opt_f = 0;
41 our $opt_u = 0;
42 getopts('hvfu');
43 # define perldoc usage
44 pod2usage(1) if $opt_h;
45
46 #---- other variables
47 our $liloconf  = "/etc/lilo.conf";
48 our $conftmp_1 = "/tmp/lilotmp1";
49 our $conftmp_2 = "/tmp/lilotmp2";
50 our $liloconfold = $liloconf . ".old";
51 our $liloconfnew = $liloconf . ".new";
52 our $fstabconf = "/etc/fstab";
53
54 our $idpath = "/dev/disk/by-id";
55 our $uuidpath = "/dev/disk/by-uuid";
56 our $lblpath = "/dev/disk/by-label";
57 our $template = "/usr/share/doc/lilo/examples/lilo.example.conf.gz";
58
59 our $rootpart;    # found root part
60 our $root_dev;    # /dev/hdX9, /dev/sdX9, /dev/md/*
61 our $root_id;     # UUID, LABEL, ID
62 our $boot_dev;    # /dev/hdX, /dev/sdX, /dev/md
63 our $boot_id;     # DISK-ID
64
65 #-------------------- main program --------------------
66
67 sub main {
68
69         my $exit = 0;
70
71         if (@ARGV == 1) {
72                 $liloconf = "$ARGV[0]";
73                 $liloconfold = $liloconf . ".old";
74                 $liloconfnew = $liloconf . ".new";
75         }
76         if (-f $liloconf and not $opt_f and not $opt_u) {
77                 print $prog .": " . $liloconf .
78                   " already exist! Please force overwriting with '-f' or '-u'.\n";
79                 $exit = 1;
80         }
81         else {
82                 $exit = create_lilo_conf();
83         }               
84         return $exit;
85 }
86
87 #-------------------- subroutines --------------------
88
89 sub create_lilo_conf {
90         
91         my $found = 0;
92         my $exit = 1;
93
94         # search for root device in fstab and convert it
95         $found = detect_root_device();
96
97         # convert root device to boot device
98         if ($found) { $found = convert_boot_device(); }
99
100         # finally write new lilo.conf file
101         if ($found) {
102           if ($opt_u) { $exit = update_lilo_conf(); }
103           else        { $exit = write_lilo_conf(); }
104         }
105
106         return $exit;
107 }
108
109 sub detect_root_device {
110         
111         # read fstab and find root device; 
112         my $found = read_fstab();
113
114         # identify root device: root_dev and root_id
115         if ($found) { $found = convert_root_device(); }
116         
117         return $found;
118 }
119
120 sub read_fstab {
121         
122         my $root_part;
123         my $mountpoint;
124         my $broken_fstab = 1;
125         my $base_fstab = 0;
126         my $found = 1;
127
128         # check fstab for root device
129         if (-f $fstabconf) {
130                 # Parsing fstab for the root partition
131                 open(FSTAB, "<$fstabconf") or die "$prog: couldn't open $fstabconf: $!\n";
132
133                 while (<FSTAB>) {
134                         # Search magic string which indicates a base filesystem
135                         $base_fstab = 1 if /^# UNCONFIGURED FSTAB FOR BASE SYSTEM/;
136                         next if /^#/;     # ignore comment lines
137
138                         s/^[ \t]+//;      # remove space or tab at begin of the line
139                         ($root_part,$mountpoint) = split(/[ \t]+/);
140                         next unless defined $mountpoint;    # ignore empty lines too
141
142                         # stop if we found the root device...
143                         if ($mountpoint eq '/') {
144                                 $broken_fstab = 0;
145                                 last;
146                         }
147                 }
148                 close(FSTAB) or die "$prog: couldn't close $fstabconf: $!\n";
149         }
150
151         if ($base_fstab) {
152                 print "E: It seems you want configure the base filesystem \n" .
153                       "and I'm therefore simply going to exit successfully \n" .
154                       "without trying to actually configure LILO properly. \n";
155                 $found = 0;
156         }
157         if ($broken_fstab) {
158                 print "E: It seems the file /etc/fstab is not properly \n" .
159                       "configured: no root partition '/' found! \n";
160                 $found = 0;
161         }
162         # save the found root device
163         $rootpart = $root_part;
164
165         return $found;
166 }
167
168 sub convert_root_device {
169         
170         my $found = 1;
171         my $root_disk = '';
172         my $root_link;
173         # global variables: $root_dev, $root_id
174
175         if ($rootpart =~ /\/dev\//) {
176                 $root_disk = $rootpart;
177
178                 if (-b $root_disk) {
179                         $root_dev = $root_disk;
180                         if($opt_v) { print "Convert root option $root_disk into UUID\n"; }
181                         $root_id = find_id_link($root_disk,$uuidpath);
182
183                         if (not -l "$uuidpath/$root_id") {
184                                 if($opt_v) { print "W: could not find UUID for $root_disk!\n"; }
185                                 ## than we want use root_dev in lilo.conf
186                                 #$found = 0;
187                         }
188                         else {
189                                 # finally add uuid label
190                                 $root_id = "UUID=" . $root_id;
191                         }
192                 }
193                 else {
194                         if($opt_v) { print "E: cannot check $root_disk: device does not exist!\n"; }
195                         $found = 0;
196                 }
197         }
198         elsif ($rootpart =~ /^UUID/ or $rootpart =~ /^LABEL/) {
199                 $root_link = $rootpart;
200                 $root_link =~ s{\"}{}g;
201                 $root_link =~ s{^LABEL=}{/dev/disk/by-label/};
202                 $root_link =~ s{^UUID=}{/dev/disk/by-uuid/};
203
204                 if (-l $root_link) {
205                         $root_id = $rootpart;
206                         $root_disk = readlink($root_link);
207                         $root_disk =~ s{\.\./\.\./}{/dev/};
208
209                         if (-b $root_disk) { $root_dev = $root_disk; }
210                         else {
211                                 if($opt_v) { print "E: cannot check $root_link: link does not exist!\n"; }
212                                 $found = 0;
213                         }
214                 }
215                 else {
216                         print "E: cannot check $root_link: link does not exist!\n";
217                         $found = 0;
218                 }
219         }
220         else {
221                 print "E: cannot use uncommon $rootpart found as root device!\n";
222                 $found = 0;
223         }
224
225         return $found;
226 }
227
228 sub find_id_link {
229         
230         my $olddev = $_[0];
231         my $path_id = $_[1];
232         my @sellinks;
233         my $_idlink;
234         my $_actlink;
235         my $newdevid = '';
236
237         opendir(MYDH, "$path_id") or die("cannot open $path_id: $! \n");
238         @sellinks = grep(!/\-part\d\d?$/, grep(!/^\.\.?$/, readdir(MYDH)));
239         @sellinks = sort(@sellinks);
240         closedir(MYDH);
241
242         foreach $_idlink (@sellinks) {
243                 chomp $_idlink;
244                 if(not $_idlink =~ /^usb/ and length($_idlink) > 10) {
245                         $_actlink = readlink("$path_id/$_idlink");
246                         $_actlink =~ s{\.\./\.\./}{/dev/};
247                         if($opt_v) { print "** try: $_actlink => $_idlink \n"; }
248                         
249                         # stop if we find the right link...
250                         if($_actlink eq $olddev) {
251                                 $newdevid = $_idlink;
252                                 if($opt_v) { print "** convert: $_actlink => $path_id/$_idlink \n\n"; }
253                                 last;
254                         }
255                 }
256         }
257
258         if(not $newdevid) {
259                 if($opt_v) { print "W: $olddev not converted: link not useful\n\n"; }
260         }
261         
262         return ($newdevid);
263 }
264
265 sub convert_boot_device {
266
267         my $found = 1;
268         my $boot_disk = '';
269         my $boot_link;
270         # global variables: $boot_dev, $boot_id
271         
272         if (-b $root_dev) {
273                 if ($root_dev =~ /\/dev\/md/) {
274                         # search if the found partition is a raid volume
275                         $boot_disk = check_raid($root_dev);
276                 }
277                 else {
278                         # find the right block device name
279                         $boot_disk = $root_dev;
280                         $boot_disk =~ s/\d+$//;
281                 }
282
283                 if (-b $boot_disk) {
284                         # set global variable boot_dev
285                         $boot_dev = $boot_disk;
286                 }
287                 else { 
288                         print "E: boot device $boot_disk does not exist! \n";
289                         $found = 0;
290                 }
291         }
292         else {
293                 print "E: could not find root device $root_dev! \n";
294                 $found = 0;
295         }
296         
297         if ($found) {
298                 if($opt_v) { print "Convert boot option $boot_disk into DISK ID\n"; }
299                 $boot_id = $idpath . "/" . find_id_link($boot_disk,$idpath);
300
301                 if(not -l "$boot_id") {
302                         if($opt_v) { print "W: could not find DISK ID for $boot_disk!\n"; }
303                         ## not so important, than using boot_dev in lilo.conf
304                         #$found = 0;
305                 }
306         }
307         
308         return $found;
309 }
310
311 sub check_raid {
312         
313         my $part = $_[0];
314         my $mdname;
315         my $md;
316         my @devices;
317         
318         # check if the found partition is a raid volume
319         if($part =~ /\/dev\/md/)
320         {
321                 $mdname = $part;
322                 $mdname =~ s/\/dev\///;
323                 $mdname =~ s/\///;
324                 $md = `grep $mdname /proc/mdstat`;
325         
326                 @devices = split(" ", $md);
327                 @devices = sort(@devices[4..$#devices]);
328                 $part = "/dev/" . $devices[0];
329                 $part =~ s/\[.*$//;
330         }
331         
332         return $part;
333 }
334
335 sub write_lilo_conf {
336         
337         my @status;
338         my $exit = copy_template();
339
340         if (not $exit) {
341                 # create lilo.conf.new
342                 write_bootroot_option();
343                 if ( not write_image_config() ) {
344                         if ( not write_imagelinks_config() ) {
345                                 print "E: Cannot find any images or image symlinks!\n";
346                                 $exit = 1;
347                         }
348                 }
349         }
350
351         if (-f $liloconf and not -f $liloconfold) {
352                 # move old lilo.conf to lilo.conf.old
353                 @status = stat($liloconf);
354                 move ($liloconf, $liloconfold) or die "Cannot rename file: $!\n";
355                 utime ($status[9],$status[9],$liloconfold);
356                 chmod (0600,$liloconfold);
357                 print "Old file moved to: $liloconfold \n";
358         }
359         if (-f $liloconfnew) {
360                 move ($liloconfnew, $liloconf) or die "Cannot move file: $!\n";
361                 chmod (0600,$liloconf);
362                 print "New file created as: $liloconf \n";
363                 print "Now you must execute '/sbin/lilo' to " . 
364                       "activate this new configuation!\n\n";
365         }
366         else {
367                 print "E: Cannot find temporary file $conftmp_1!\n";
368                 $exit = 1;
369         }
370         
371         return $exit;
372 }
373
374 sub copy_template {
375
376         my $endreached = 0;
377         my $exit = 0;
378         
379         # copy template config
380         if (-f $template) {
381                 system("gzip -d -c $template >$conftmp_1") if ($template =~ /\.gz$/);
382                 system("cat $template >$conftmp_1") if ($template =~ /\.conf$/);
383
384                 open(CONFTMP1, "<$conftmp_1") or die "$prog: couldn't open $conftmp_1: $!\n";
385                 open(CONFTMP2, ">$conftmp_2") or die "$prog: couldn't open $conftmp_2: $!\n";
386
387                 while (<CONFTMP1>) {
388                         if (/first\ example/) {
389                                 $endreached = 1;
390                         }
391                         unless ($endreached) {
392                                 print CONFTMP2 $_;
393                         }
394                 }
395                 close(CONFTMP1) or die "$prog: couldn't close $conftmp_1: $!\n";;
396                 close(CONFTMP2) or die "$prog: couldn't close $conftmp_2: $!\n";;
397         }
398         else {
399                 open(CONFTMP2, ">$conftmp_2") or die "$prog: couldn't open $conftmp_2: $!\n";
400                 print CONFTMP2 "# /etc/lilo.conf
401
402 ### LILO global section ###
403
404 #large-memory
405 lba32
406 boot = /dev/sda
407 root = /dev/sda1
408 map = /boot/map
409 install = menu
410 menu-scheme = Wb:Yr:Wb:Wb
411 prompt
412 timeout = 100
413 vga = normal
414 #default = Linux
415
416 ### LILO per-image section ###
417
418 "; 
419                 close(CONFTMP2) or die "$prog: couldn't close $conftmp_2: $!\n";;
420         }
421         
422         return $exit;
423 }
424
425 sub update_lilo_conf {
426
427         my @status;
428         my $exit = 0;
429
430         if (-f $liloconf) {
431                 # copy old config
432                 system("cat $liloconf >$conftmp_2");
433                 
434                 # create lilo.conf.new
435                 update_bootroot_option();
436         }
437         
438         if (-f $liloconf and not -f $liloconfold) {
439                 # move old lilo.conf to lilo.conf.old
440                 @status = stat($liloconf);
441                 move ($liloconf, $liloconfold) or die "Cannot rename file: $!\n";
442                 utime ($status[9],$status[9],$liloconfold);
443                 chmod (0600,$liloconfold);
444                 print "Old file moved to: $liloconfold \n";
445         }
446         if (-f $liloconfnew) {
447                 move ($liloconfnew, $liloconf) or die "Cannot move file: $!\n";
448                 chmod (0600,$liloconf);
449                 print "New file created as: $liloconf \n";
450                 print "Now you must execute '/sbin/lilo' to " . 
451                       "activate this new configuation!\n\n";
452         }
453         else {
454                 print "E: Cannot find temporary file $conftmp_1!\n";
455                 $exit = 1;
456         }
457         
458         return $exit;
459 }
460
461 sub write_bootroot_option {
462         
463         my $oldline = '';
464         my $newline = '';
465         my $ok = 0;
466
467         open(MYFH_NEW, "> $liloconfnew") or die "Cannot open file: $!";
468         open(MYFH_TMP, "< $conftmp_2") or die "Cannot read file: $!";
469
470         while (<MYFH_TMP>) {
471                 # line read from MYFH_TMP
472                 $oldline = $_;
473
474                 # lines beginning direct with boot option
475                 if (/^boot/ and $ok == 0) {
476                         if ($boot_id) {
477                                 $newline = "#boot = " . $boot_dev . "\n";
478                                 print MYFH_NEW $newline;
479                                 if($opt_v) { print $newline; }
480                                 $newline = "boot = " . $boot_id . "\n";
481                         }
482                         else {
483                                 $newline = "boot = " . $boot_dev . "\n";
484                         }
485                         print MYFH_NEW $newline;
486                         if($opt_v) { print $newline; print "\n";}
487                         # convert only one time
488                         $ok = 1;
489                 }
490                 # lines beginning direct with root option
491                 elsif (/^root\ =/) {
492                         if ($root_id) {
493                                 $newline = '#root = ' . $root_dev . "\n";
494                                 print MYFH_NEW $newline;
495                                 if($opt_v) { print $newline; }
496                                 $newline = 'root = "' . $root_id . '"' . "\n";
497                         }
498                         else {
499                                 $newline = 'root = ' . $root_dev . "\n";
500                         }
501                         print MYFH_NEW $newline;
502                         if($opt_v) { print $newline; print "\n";}
503                 }
504                 # print the rest into file, but not old commented root lines
505                 elsif ( not (/^\#boot\ =/ or /^\#root\ =/) ) {
506                         print MYFH_NEW $oldline;
507                 }
508         }
509         close(MYFH_TMP);
510         close(MYFH_NEW);
511 }
512
513 sub update_bootroot_option {
514         
515         my $oldline = '';
516         my $newline = '';
517         my $ok = 0;
518         
519         open(MYFH_NEW, "> $liloconfnew") or die "Cannot open file: $!";
520         open(MYFH_TMP, "< $conftmp_2") or die "Cannot read file: $!";
521         
522         while (<MYFH_TMP>) {
523                 # read (old) line from MYFH_TMP
524                 $oldline = $_;
525
526                 # lines beginning direct with boot option
527                 if (/^boot/ and $ok == 0) {
528                         if ($boot_id) {
529                                 $newline = "#boot = " . $boot_dev . "\n";
530                                 print MYFH_NEW $newline;
531                                 if($opt_v) { print $newline; }
532                                 $newline = "boot = " . $boot_id . "\n";
533                         }
534                         else {
535                                 $newline = "boot = " . $boot_dev . "\n";
536                         }
537                         print MYFH_NEW $newline;
538                         if($opt_v) { print $newline; print "\n";}
539                         # convert only one time
540                         $ok = 1;
541                 }
542                 # lines beginning direct with root option
543                 elsif (/^root\ =/) {
544                         if ($root_id) {
545                                 $newline = '#root = ' . $root_dev . "\n";
546                                 print MYFH_NEW $newline;
547                                 if($opt_v) { print $newline; }
548                                 $newline = 'root = "' . $root_id . '"' . "\n";
549                         }
550                         else {
551                                 $newline = 'root = ' . $root_dev . "\n";
552                         }
553                         print MYFH_NEW $newline;
554                         if($opt_v) { print $newline; print "\n";}
555                 }
556                 # lines beginning with one tabulator or with two - eight spaces
557                 elsif (/^\troot\ =/ or /^\ {2,8}root\ =/) {
558                         if ($root_id) {
559                                 $newline = "\t" . '#root = ' . $root_dev . "\n";
560                                 print MYFH_NEW $newline;
561                                 if($opt_v) { print $newline; }
562                                 $newline = "\t" . 'root = "' . $root_id . '"' . "\n";
563                         }
564                         else {
565                                 $newline = "\t" . 'root = ' . $root_dev . "\n";
566                         }
567                         print MYFH_NEW $newline;
568                         if($opt_v) { print $newline; print "\n";}
569                 }
570                 # print the rest into file, but not old commented root lines
571                 elsif ( not (/^\#boot\ =/ or /^\#root\ =/ or /^\t\#root\ =/ or /^\ {2,8}\#root\ =/) ) {
572                         print MYFH_NEW $oldline;
573                 }
574         }
575         close(MYFH_TMP);
576         close(MYFH_NEW);
577 }
578
579 sub write_image_config {
580
581         my $image;
582         my $initrd;
583         my $initrd2;
584         my $nr;
585         my $nr2;
586
587         # append to new lilo.conf
588         open(MYFH_NEW, ">> $liloconfnew") or die "Cannot open file: $!";
589
590         # search for kernel image files
591         my @vmlinuz = readpipe("/bin/ls -t -1 /boot/vmlinuz* 2>/dev/null");
592
593         # create some lines for each kernel image
594         $nr = 0;
595         foreach $image (@vmlinuz) {
596                 # search for kernel initrd file
597                 chomp $image;
598                 $initrd = $image;
599                 $initrd =~ s/vmlinuz/initrd\.img/;
600                 $initrd2 = $initrd;
601                 $initrd2 =~ s/\.img//;
602                 $nr2 = $nr + 1;
603
604                 print MYFH_NEW     'image = ' . $image . "\n";
605                 if($opt_v) { print 'image = ' . $image . "\n"; }
606
607                 if ($nr == 0) {
608                         print MYFH_NEW     "\t"  . 'label = "Linux"' . "\n";
609                         if($opt_v) { print "\t"  . 'label = "Linux"' . "\n"; }
610                 }
611                 elsif ($nr == 1) {
612                         print MYFH_NEW     "\t"  . 'label = "Linux Old"' . "\n";
613                         if($opt_v) { print "\t"  . 'label = "Linux Old"' . "\n"; }
614                 }
615
616                 print MYFH_NEW     "\t"  . 'read-only' . "\n";
617                 if($opt_v) { print "\t"  . 'read-only' . "\n"; }
618                 print MYFH_NEW     "#\t" . 'restricted' . "\n";
619                 if($opt_v) { print "#\t" . 'restricted' . "\n"; }
620                 print MYFH_NEW     "#\t" . 'alias = ' . "$nr2" . "\n";
621                 if($opt_v) { print "#\t" . 'alias = ' . "$nr2" . "\n"; }
622                 print MYFH_NEW     "#\t" . 'optional' . "\n";
623                 if($opt_v) { print "#\t" . 'optional' . "\n"; }
624
625                 if (-e $initrd) {
626                         print MYFH_NEW     "\t"  . 'initrd = ' . $initrd . "\n";
627                         if($opt_v) { print "\t"  . 'initrd = ' . $initrd . "\n"; }
628                 }
629                 elsif (-e $initrd2) {
630                         print MYFH_NEW     "\t"  . 'initrd = ' . $initrd2 . "\n";
631                         if($opt_v) { print "\t"  . 'initrd = ' . $initrd2 . "\n"; }
632                 }
633                 else {
634                         if($opt_v) { print "W: initrd $initrd could not be found!\n" }
635                 }
636
637                 print MYFH_NEW     "\n";
638                 if($opt_v) { print "\n"; }
639
640                 $nr++;
641                 last if ($nr > 1);
642         }
643
644         close(MYFH_NEW);
645
646         if ($nr == 0) {
647                 print "No images '/boot/vmlinuz*' found!\n"; 
648                 if($opt_v) { print "\n"; }
649         }
650         elsif( not $opt_v ) {
651                 print "$nr images '/boot/vmlinuz*' found.\n"; 
652         }
653         return ($nr > 0);     # if =0 this is an error
654 }               
655
656 sub write_imagelinks_config {
657
658         my $image;
659         my $initrd;
660         my $nr;
661         my $nr2;
662
663         # append to new lilo.conf
664         open(MYFH_NEW, ">> $liloconfnew") or die "Cannot open file: $!";
665
666         # search for kernel image files
667         my @vmlinuz = readpipe("/bin/ls -t -1 /vmlinuz /vmlinuz.old 2>/dev/null");
668
669         # create some lines for each kernel image
670         $nr = 0;
671         foreach $image (@vmlinuz) {
672                 # search for kernel initrd file
673                 chomp $image;
674                 $initrd = $image;
675                 $initrd =~ s/vmlinuz/initrd\.img/;
676                 $nr2 = $nr + 1;
677
678                 print MYFH_NEW     'image = ' . $image . "\n";
679                 if($opt_v) { print 'image = ' . $image . "\n"; }
680
681                 if ($nr == 0) {
682                         print MYFH_NEW     "\t"  . 'label = "Linux"' . "\n";
683                         if($opt_v) { print "\t"  . 'label = "Linux"' . "\n"; }
684                 }
685                 elsif ($nr == 1) {
686                         print MYFH_NEW     "\t"  . 'label = "Linux Old"' . "\n";
687                         if($opt_v) { print "\t"  . 'label = "Linux Old"' . "\n"; }
688                 }
689
690                 if ($root_id) {
691                         print MYFH_NEW     "\t"  . '#root = ' . $root_dev . "\n";
692                         if($opt_v) { print "\t"  . '#root = ' . $root_dev . "\n"; }
693                         print MYFH_NEW     "\t"  . 'root = "' . $root_id . '"' . "\n";
694                         if($opt_v) { print "\t"  . 'root = "' . $root_id . '"' . "\n"; }
695                 }
696                 else {
697                         print MYFH_NEW     "\t"  . 'root = ' . $root_dev . "\n";
698                         if($opt_v) { print "\t"  . 'root = ' . $root_dev . "\n"; }
699                 }
700
701                 print MYFH_NEW     "\t"  . 'read-only' . "\n";
702                 if($opt_v) { print "\t"  . 'read-only' . "\n"; }
703                 print MYFH_NEW     "#\t" . 'restricted' . "\n";
704                 if($opt_v) { print "#\t" . 'restricted' . "\n"; }
705                 print MYFH_NEW     "#\t" . 'alias = ' . "$nr2" . "\n";
706                 if($opt_v) { print "#\t" . 'alias = ' . "$nr2" . "\n"; }
707                 print MYFH_NEW     "#\t" . 'optional' . "\n";
708                 if($opt_v) { print "#\t" . 'optional' . "\n"; }
709
710                 if (-e $initrd) {
711                         print MYFH_NEW     "\t"  . 'initrd = ' . $initrd . "\n";
712                         if($opt_v) { print "\t"  . 'initrd = ' . $initrd . "\n"; }
713                 }
714                 else {
715                         if($opt_v) { print "W: initrd $initrd could not be found!\n" }
716                 }
717
718                 print MYFH_NEW     "\n";
719                 if($opt_v) { print "\n"; }
720
721                 $nr++;
722                 last if ($nr > 1);
723         }
724
725         close(MYFH_NEW);
726
727         if ($nr == 0) {
728                 print "No image symlinks '/vmlinuz*' found!\n"; 
729                 if($opt_v) { print "\n"; }
730         }
731         elsif( not $opt_v ) {
732                 print "$nr image symlinks '/vmlinuz*' found.\n"; 
733         }
734         return ($nr > 0);     # if =0 this is an error
735 }
736
737 main();
738
739 __END__
740
741
742 =head1 NAME
743
744 liloconfig - create new lilo.conf file (with diskid and uuid)
745
746 =head1 SYNOPSIS
747
748 B<liloconfig> [B<-h>] [B<-v>] [B<-f>] [B<-u>] [B<lilo.conf>]
749
750 =head1 DESCRIPTION
751
752 liloconfig is an simple program for creating a new lilo.conf file.
753 After creating the new configuration file you must execute '/sbin/lilo'.
754
755 liloconfig use the lilo.example.conf file as template. In the final
756 lilo.conf file you find many useful comments for custom changes.
757
758 Please pay attention about error messages if liloconfig cannot find
759 any images (/boot/vmlinuz*) oder image symlinks (/vmlinuz, /vmlinu.old).
760 Then you need to search for images by ourself and make some changes
761 in the '/etc/lilo.conf' file. Otherwise no bootloader can be installed
762 with '/sbin/lilo'.
763
764 =head1 OPTIONS
765
766 =over 4
767
768 =item B<-h>
769
770 Print a brief help.
771
772 =item B<-v>
773
774 Print verbose messages.
775
776 =item B<-f>
777
778 Force overriding existing lilo.conf.
779
780 =item B<-u>
781
782 Force overriding/update of boot line in lilo.conf.
783
784 =back
785
786 =head1 EXAMPLES
787
788 Lines in the configuration file /etc/lilo.conf:
789
790   ### LILO global section ###
791
792   #large-memory
793   lba32
794   boot = /dev/sda
795   #root = /dev/sda1
796   root = "UUID=18843936-00f9-4df0-a373-000d05a5dd44"
797   map = /boot/map
798   install = menu
799   menu-scheme = Wb:Yr:Wb:Wb
800   prompt
801   timeout = 100
802   vga = normal
803   #default = Linux
804
805   ### LILO per-image section ###
806
807   #boot = /dev/sda
808   boot = /dev/disk/by-id/ata-SAMSUNG_SV1604N_S01FJ10X999999
809
810   image = /boot/vmlinuz-3.5.0-trunk-686
811       label = "Linux"
812       #root = /dev/sda1
813       #root = "UUID=18843936-00f9-4df0-a373-000d05a5dd44"
814       read-only
815   #   restricted
816   #   alias = 1
817   #   optional
818       initrd = /boot/initrd.img-3.5.0-trunk-686
819
820   image = /boot/vmlinuz-3.2.0-4-686
821       label = "Linux Old"
822       #root = /dev/sda1
823       #root = "UUID=18843936-00f9-4df0-a373-000d05a5dd44"
824       read-only
825   #   restricted
826   #   alias = 2
827   #   optional
828       initrd = /boot/initrd.img-3.2.0-4-686
829
830 =head1 COPYRIGHT and LICENSE
831
832 Copyright (C) 2011-2014 Joachim Wiedorn
833
834 This script is free software; you can redistribute it and/or modify
835 it under the terms of the GNU General Public License as published by 
836 the Free Software Foundation; either version 2 of the License, or 
837 (at your option) any later version.
838
839 =head1 AUTHOR
840
841 B<liloconfig> was written by Joachim Wiedorn.
842
843 This manual page was written by Joachim Wiedorn <joodevel at joonet.de>.
844
845 =head1 SEE ALSO
846
847 B<lilo>(8), B<update-lilo>(8), B<lilo-uuid-diskid>(8)
848
849 =cut