From: Joachim Wiedorn Date: Tue, 18 Jan 2011 23:42:11 +0000 (+0100) Subject: Update script lilo-uuid-diskid X-Git-Tag: debian/23.1-1~9 X-Git-Url: https://git.rrq.au/?a=commitdiff_plain;h=fdb99250f7bb7210c51ed974b88511cfb0dc1149;hp=b4d22db1dfe48725e81ed39410301a5e00a83462;p=rrq%2Fmaintain_lilo.git Update script lilo-uuid-diskid --- diff --git a/debian/scripts/lilo-uuid-diskid b/debian/scripts/lilo-uuid-diskid index 5b79f9f..7f1772f 100644 --- a/debian/scripts/lilo-uuid-diskid +++ b/debian/scripts/lilo-uuid-diskid @@ -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 +# Copyright 2010-2011 Joachim Wiedorn # # 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]; @@ -239,11 +242,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 +255,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 + 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 -b $root_link) { + if($opt_v) { print "cannot check $root_disk: link does not exist!\n"; } + } } return $exit; } @@ -282,13 +287,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 +305,6 @@ sub find_id_link { } } } - closedir(MYDH); if($opt_v and not $ok) { print "$olddev not converted: link not useful\n\n"; }