restructured, fsck, hostname stable
authorHeiko Schlittermann <hs@schlittermann.de>
Wed, 20 Jan 2010 08:41:48 +0100
branchstable
changeset 19 d12753b246fd
parent 18 c9575527c96d
child 20 998ccc03375b
restructured, fsck, hostname
SI/dumper.pm
SI/lvm.pm
SI/ptable.pm
SI/system.pm
si
--- a/SI/dumper.pm	Tue Jan 19 23:51:00 2010 +0100
+++ b/SI/dumper.pm	Wed Jan 20 08:41:48 2010 +0100
@@ -14,9 +14,6 @@
     {
         next if !defined $volume->{type} or $volume->{type} !~ /^ext/i;
 
-        system("fsck -f -C0 $volume->{name}");
-        die "ERR: fsck failed\n" if $? > 2;
-
         verbose("dumping volume $volume->{name}");
         my $dumpdev = $volume->{name};
         my $of = sprintf $file, basename($volume->{name});
--- a/SI/lvm.pm	Tue Jan 19 23:51:00 2010 +0100
+++ b/SI/lvm.pm	Wed Jan 20 08:41:48 2010 +0100
@@ -24,6 +24,8 @@
       grep { $_ ~~ @known } map { s/\s*//; (split /:/)[0] } `pvdisplay -c`;
     @volumegroups = map { (split /:/)[1] } `pvdisplay -c @pvs 2>/dev/null`;
     run("vgchange -ay @volumegroups 2>&1 >/dev/null");
+    # we wait for the /dev/mapper devices to appear
+    run("udevadm settle");	
     return @volumegroups;
 }
 
@@ -41,6 +43,8 @@
     foreach (@lvs) {
         $devs->{volume}{$_} = { origin => "lvm" };
     }
+
+    push @{$devs->{volumes}}, @lvs;
 }
 
 sub vgcfgbackup($\%) {
--- a/SI/ptable.pm	Tue Jan 19 23:51:00 2010 +0100
+++ b/SI/ptable.pm	Wed Jan 20 08:41:48 2010 +0100
@@ -57,6 +57,7 @@
                 origin      => "ptable",
                 ptable_type => $2,
             };
+	    push @{$devs->{volumes}}, $1;
         }
     }
 
--- a/SI/system.pm	Tue Jan 19 23:51:00 2010 +0100
+++ b/SI/system.pm	Wed Jan 20 08:41:48 2010 +0100
@@ -20,25 +20,34 @@
 sub hostname(\%) {
     my $devs = shift;
     my $mnt = tempdir(CLEANUP => 1);
-    my $r;
+    my $h;
 
-    foreach my $fs (
-        grep { $devs->{volume}{$_}{type} =~ /^ext/i }
-        grep { exists $devs->{volume}{$_}{type} }
-        keys %{ $devs->{volume} }
-      )
+    foreach my $fs (grep { exists $devs->{volume}{$_}{type} and $devs->{volume}{$_}{type} =~ /^ext/i } @{$devs->{volumes}})
     {
         run("mount -r $fs $mnt");
         if (-f "$mnt/etc/hostname") {
-            die "ERR: found 2nd hostname" if defined $r;
-            chomp($r = cat("$mnt/etc/hostname"));
+            chomp($h = cat("$mnt/etc/hostname"));
         }
         run("umount $mnt");
+	return $h if defined $h;
     }
 
-    return $r;
+    return $h;
 }
 
+sub fsck(\%) {
+	my $devs = shift;
+
+	foreach my $v ( grep { exists $devs->{volume}{type} } keys %{$devs->{volume}} ) {
+		my $volume = $devs->{volume}{$v};
+		next if $volume->{type} !~ /^ext/i;
+
+		system("fsck -C0 $v");
+		die "ERR: fsck failed\n" if $? > 2;
+	}
+}
+
+
 1;
 
 # vim:sts=4 sw=4 aw ai si:
--- a/si	Tue Jan 19 23:51:00 2010 +0100
+++ b/si	Wed Jan 20 08:41:48 2010 +0100
@@ -25,6 +25,10 @@
 my $opt_dir  = "";
 
 MAIN: {
+    my %id = (
+	    mac => SI::system::id,
+	    name => undef,
+    );
 
     GetOptions(
         "exit=s" => \$opt_exit,
@@ -38,7 +42,7 @@
         $dir = $opt_dir;
     }
     else {
-        $dir = dirname($0) . "/../image-" . SI::system::id();
+        $dir = dirname($0) . "/../image-$id{mac}";
         remove_tree($dir);
         -d $dir or mkdir($dir, 0700) or die "Can't mkdir $dir: $!\n";
     }
@@ -59,17 +63,17 @@
     SI::mbr::save("$dir/mbr/%s", %devices);
     die Dumper \%devices if $opt_exit =~ /mbr/;
 
-    SI::dumper::dump("$dir/dump/%s", %devices);
-
-    my $o = new IO::File ">$dir/devices"
-      or die "ERR: Can't open $dir/devices: $!\n";
-    $o->print(Dumper \%devices);
+    SI::system::fsck(%devices);
+    die Dumper \%devices if $opt_exit =~ /fsck/;
 
-    # we wait until now, since now it's sure that
-    # the filesystems are checked and that we mount the
-    # devices we need
-    my $hostname = SI::system::hostname(%devices);
-    symlink(basename($dir), "../image-$hostname");
+    $id{name} = SI::system::hostname(%devices);
+    unlink("../image-$id{name}") if -l "../image-$id{name}";
+    symlink(basename($dir), "../image-$id{name}");
+
+    print {new IO::File ">$dir/devices"} Dumper \%devices
+      or die "ERR: Can't open $dir/devices: $!\n";
+
+    SI::dumper::dump("$dir/dump/%s", %devices);
 
     exit;