#!/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
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;
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 = '';
}
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;
}
return $exit;
}
-
sub read_fstab {
my $ffile = $_[0];
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
$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;
}
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"; }
}
}
}
- closedir(MYDH);
if($opt_v and not $ok) { print "$olddev not converted: link not useful\n\n"; }