Updates lilo.conf.5 manpage
[rrq/maintain_lilo.git] / debian / scripts / lilo-uuid-diskid
index 5b79f9f2a71ca5e8708971c4edecab24c896f41f..ab03744ade7667fe80525a48ea1e8496eb45a7e6 100644 (file)
@@ -1,9 +1,9 @@
 #!/usr/bin/perl -w
 
-#       lilo-uuid-diskid - convert boot / root options to diskid and 
-#                          uuid in lilo.conf
+#       lilo-uuid-diskid - convert boot and root options to diskid
+#                          and uuid in /etc/lilo.conf
 #
-#       Copyright 2010 Joachim Wiedorn <ad_debian at joonet.de>
+#       Copyright 2010-2011 Joachim Wiedorn <ad_debian at joonet.de>
 #       
 #       This program is free software; you can redistribute it and/or modify
 #       it under the terms of the GNU General Public License as published by
@@ -27,10 +27,11 @@ use Getopt::Std;
 use Pod::Usage;
 use File::Copy;
 
+
 #---- global variables
 my $prog = $0;
 $prog =~ s#.*/##;
-my $version = "0.1";
+my $version = "0.3";
 
 #---- parameter check
 our $opt_h = 0;
@@ -45,6 +46,7 @@ our $liloconfold = '';
 our $fstabconf = "/etc/fstab";
 our $idpath = "/dev/disk/by-id";
 our $uuidpath = "/dev/disk/by-uuid";
+our $labpath = "/dev/disk/by-label";
 
 our $bootready = 0;
 our $boot_id = '';
@@ -160,7 +162,9 @@ sub detect_boot_device {
        }
 
        if (-b $boot_disk) {
-               if($boot_disk =~ /$idpath/ or $boot_disk =~ /$uuidpath/) {
+               if($boot_disk =~ /$idpath/ 
+                               or $boot_disk =~ /$uuidpath/
+                               or $boot_disk =~ /$labpath/) {
                        print "boot option is already updated to $boot_disk\n";
                        $bootready = 1; $exit = 1;
                }
@@ -183,7 +187,6 @@ sub detect_boot_device {
        return $exit;
 }
 
-
 sub read_fstab {
        
        my $ffile = $_[0];
@@ -201,11 +204,11 @@ sub read_fstab {
        }
        # check if the found partition is a raid volume
        if($root_part =~ /\/dev\/md/) {
-               $root_part = check_raid($root_part);
        }
-       # now find the right block device name
-       $root_part =~ s/\d+$//;
-       $root_part =~ s/part$/disc/;
+       unless ($root_part =~ /^UUID/) {
+               # now find the right block device name
+               $root_part =~ s/\d+$//;
+       }
 
        return $root_part;
 }
@@ -213,14 +216,13 @@ sub read_fstab {
 sub check_raid {
        
        my $part = $_[0];
-
+       my $mdname;
+       my $md;
+       my @devices;
+       
        # check if the found partition is a raid volume
        if($part =~ /\/dev\/md/)
        {
-               my $mdname;
-               my $md;
-               my @devices;
-       
                $mdname = $part;
                $mdname =~ s/\/dev\///;
                $mdname =~ s/\///;
@@ -239,11 +241,12 @@ sub detect_root_device {
        
        my $root_line = $_[0];
        my $root_disk = '';
+       my $root_link = '';
        my $exit = 0;
 
        if (not $exit) {
                # extract the root device name
-               $root_disk = ($root_line =~ /^\t?root *= *(\/dev\/.*)/) ? ($1) : ();
+               $root_disk = ( $root_line =~ /^\t?root *= *(.*)/ ) ? ($1) : ();
                chomp $root_disk;
 
                # check if the found partition is a raid volume
@@ -251,22 +254,23 @@ sub detect_root_device {
                        $root_disk = check_raid($root_disk);
                }
        }
-       
-       if (-b $root_disk) {
 
-               if($root_disk =~ /$uuidpath/) {
-                       print "$root_disk is already updated - nothing to do\n";
-               }
-               else {
-                       if($opt_v) { print "convert root option $root_disk into new UUID\n"; }
-
-                       $root_id = find_id_link($root_disk,$uuidpath);
-                       if (not -l "$uuidpath/$root_id") { $exit = 1; }
-               }
+       # check if root device exist / also for raid volume
+       if (-b $root_disk) {
+               if($opt_v) { print "convert root option $root_disk into new UUID\n"; }
+               $root_id = find_id_link($root_disk,$uuidpath);
+               if (not -l "$uuidpath/$root_id") { $exit = 1; }
        }
        else {
-               if($opt_v) { print "cannot read $root_disk: link does not exist!\n"; }
+               # nothing to do but perhaps give a message
                $exit = 1;
+               $root_link = $root_disk;
+               $root_link =~ s{\"}{}g;
+               $root_link =~ s{^LABEL=}{/dev/disk/by-label/};
+               $root_link =~ s{^UUID=}{/dev/disk/by-uuid/};
+               if (not -l $root_link) {
+                       if($opt_v) { print "cannot check $root_link: link does not exist!\n"; }
+               }
        }
        return $exit;
 }
@@ -282,13 +286,12 @@ sub find_id_link {
        my $ok = 0;
 
        opendir(MYDH, "$path_id") or die("cannot open $path_id: $! \n");
-
        @sellinks = grep(!/\-part\d\d?$/, grep(!/^\.\.?$/, readdir(MYDH)));
-       foreach $_idlink (@sellinks) {
-               
-               if(not $_idlink =~ /^usb/ and not $_idlink =~ /^scsi/
-                               and length($_idlink) > 10 and $ok == 0) {
+       @sellinks = sort(@sellinks);
+       closedir(MYDH);
 
+       foreach $_idlink (@sellinks) {
+               if(not $_idlink =~ /^usb/ and length($_idlink) > 10 and $ok == 0) {
                        $_actlink = readlink("$path_id/$_idlink");
                        $_actlink =~ s/^\.\.\/\.\.\//\/dev\//;
                        if($opt_v) { print "** try: $_actlink => $_idlink \n"; }
@@ -301,7 +304,6 @@ sub find_id_link {
                        }
                }
        }
-       closedir(MYDH);
 
        if($opt_v and not $ok) { print "$olddev not converted: link not useful\n\n"; }
        
@@ -322,6 +324,7 @@ sub write_boot_option {
                @status = stat($liloconf);
                move ($liloconf, $liloconfold);
                utime ($status[9],$status[9],$liloconfold);
+               chmod (0600,$liloconfold);
 
                # copy all lines from lilo.conf_old into
                # new lilo.conf and add 'boot=' line
@@ -375,6 +378,7 @@ sub write_boot_option {
                }
                close(MYFH_OLD);
                close(MYFH_NEW);
+               chmod (0600,$liloconf);
        }
        else {
                print "file $liloconf does not exist: nothing changed\n";
@@ -440,7 +444,7 @@ Lines in the configuration file /etc/lilo.conf:
   boot = /dev/disk/by-id/ata-SAMSUNG_SV1604N_S01FJ10X999999
 
   #root = /dev/sda1
-  root = "UUID=/dev/disk/by-uuid/18843936-00f9-4df0-a373-000d05a5dd44"
+  root = "UUID=18843936-00f9-4df0-a373-000d05a5dd44"
 
 =head1 OPTIONS