diff options
Diffstat (limited to 'globetrotter')
| -rw-r--r-- | globetrotter/fix-broken-hd.diff | 127 | ||||
| -rwxr-xr-x | globetrotter/make_live | 65 |
2 files changed, 181 insertions, 11 deletions
diff --git a/globetrotter/fix-broken-hd.diff b/globetrotter/fix-broken-hd.diff new file mode 100644 index 000000000..6ae7fa491 --- /dev/null +++ b/globetrotter/fix-broken-hd.diff @@ -0,0 +1,127 @@ +--- make_live 2005-05-25 17:42:35.000000000 +0200 ++++ make_live 2005-05-25 17:46:41.000000000 +0200 +@@ -8,6 +8,7 @@ + use standalone; + use interactive; + use common; ++use detect_devices; + use partition_table; + use fsedit; + use fs; +@@ -321,8 +322,116 @@ + + $::prefix = $ARGV[0] || '/tmp/live_tree'; + ++#=========================================================================== ++# Fix disk if it's a bogus one: ++ ++my @packages2delete = qw( ++ Mandrake/RPMS/uqm-data-0.3-1mdk.noarch.rpm ++ ++ Mandrake/RPMS2/kernel24-tmb-2.4.25-6.tmb.1mdk-1-1mdk.i586.rpm ++ Mandrake/RPMS2/kernel24-tmb-2.4.25-7.tmb.1mdk-1-1mdk.i586.rpm ++ Mandrake/RPMS2/kernel24-tmb-2.4.25-7.tmb.2mdk-1-1mdk.i586.rpm ++ Mandrake/RPMS2/kernel24-tmb-enterprise-2.4.25-6.tmb.1mdk-1-1mdk.i586.rpm ++ Mandrake/RPMS2/kernel24-tmb-enterprise-2.4.25-7.tmb.1mdk-1-1mdk.i586.rpm ++ Mandrake/RPMS2/kernel24-tmb-enterprise-2.4.25-7.tmb.2mdk-1-1mdk.i586.rpm ++ Mandrake/RPMS2/kernel24-tmb-i686-up-4GB-2.4.25-6.tmb.1mdk-1-1mdk.i586.rpm ++ Mandrake/RPMS2/kernel24-tmb-i686-up-4GB-2.4.25-7.tmb.1mdk-1-1mdk.i586.rpm ++ Mandrake/RPMS2/kernel24-tmb-i686-up-4GB-2.4.25-7.tmb.2mdk-1-1mdk.i586.rpm ++ Mandrake/RPMS2/kernel24-tmb-source-2.4.25-7.tmb.2mdk.i586.rpm ++ ++ Mandrake/RPMS2/kernel-tmb-2.6.4-1.tmb.8mdk-1-1mdk.i586.rpm ++ Mandrake/RPMS2/kernel-tmb-enterprise-2.6.4-1.tmb.8mdk-1-1mdk.i586.rpm ++ Mandrake/RPMS2/kernel-tmb-i686-up-4GB-2.6.4-1.tmb.8mdk-1-1mdk.i586.rpm ++ Mandrake/RPMS2/kernel-tmb-source-2.6.4-1.tmb.8mdk.i586.rpm ++ Mandrake/RPMS2/kernel-win4lin-2.4.25.5mdk-3-7mdk.i586.rpm ++ Mandrake/RPMS2/kernel-win4lin-2.6.3.15mdk-3-8mdk.i586.rpm ++ Mandrake/RPMS2/kernel-win4lin-enterprise-2.4.25.5mdk-3-7mdk.i586.rpm ++ Mandrake/RPMS2/kernel-win4lin-enterprise-2.6.3.15mdk-3-8mdk.i586.rpm ++ Mandrake/RPMS2/kernel-win4lin-i686-up-4GB-2.4.25.5mdk-3-7mdk.i586.rpm ++ Mandrake/RPMS2/kernel-win4lin-i686-up-4GB-2.6.3.15mdk-3-8mdk.i586.rpm ++ Mandrake/RPMS2/kernel-win4lin-p3-smp-64GB-2.4.25.5mdk-3-7mdk.i586.rpm ++ Mandrake/RPMS2/kernel-win4lin-p3-smp-64GB-2.6.3.15mdk-3-8mdk.i586.rpm ++ Mandrake/RPMS2/kernel-win4lin-smp-2.4.25.5mdk-3-7mdk.i586.rpm ++ Mandrake/RPMS2/kernel-win4lin-smp-2.6.3.15mdk-3-8mdk.i586.rpm ++ ); ++ ++# misc paths; ++my $pkgs_mount_path = "/mnt/mdk_pkgs"; ++my $rescue_path = "/rescue-glob"; ++my $cd_mount_path = "/mnt/cdrom-glob"; ++ ++# enable to retry fixing partitions if fixing failed: ++my $__need2befixed_mark = "Mandrake/RPMS/NEED_TO_BE_FIXED"; ++my $need2befixed_mark = "$pkgs_mount_path/__need2befixed_mark"; ++ ++{ ++ mkdir_p($pkgs_mount_path); ++ ++ my $cleaner = before_leaving { ++ if (my $err = $@) { ++ print "\n>> an error happened: $err\n"; ++ } ++ print "Cleaning on end of fixing\n"; ++ eval { fs::umount($_) } foreach $pkgs_mount_path, $cd_mount_path; ++ undef $@; # do not propagate fs::umount exceptions ++ }; ++ ++ print "Checking if the packages partition needs to be fixed\n"; ++ # system("mount /dev/$pkg_dev->{device} $pkgs_mount_path"); ++ fs::mount($pkg_dev->{device}, $pkgs_mount_path, 'ext3'); ++ # my $pkgs_mount_path = "/home/qa/broken"; # FIXME: TESTING ++ ++ if (any { -e "$pkgs_mount_path/$_" } @packages2delete, $__need2befixed_mark) { ++ print "Preparing to fixing the partition packages...\n"; ++ touch($need2befixed_mark); ++ ++ # Cleaning the packages so that we get back some free space: ++ unlink("$pkgs_mount_path/$_") foreach @packages2delete; ++ ++ ++ # Lookup rescue CD: ++ ++ my $cdrom_path; ++ ++ my @cdroms = map { $_->{device} } detect_devices::cdroms(); ++ ++ mkdir_p($cd_mount_path); ++ ++ my ($found, $cdrom_dev); ++ ++ foreach my $cdrom (@cdroms) { ++ eval { fs::mount($cdrom, $cd_mount_path, 'iso9660', 1) } or next; # nicely handle empty drives ++ if (-d "$cd_mount_path/$rescue_path") { ++ $cdrom_dev = $cdrom; ++ $found = 1; ++ last; ++ } ++ fs:umount($cd_mount_path); ++ } ++ undef $@; # do not propagate fs::mount exceptions ++ ++ if ($found) { ++ warn "Found rescue CDROM on $cdrom_dev\n"; ++ } else { ++ warn "I failed to found the rescue CDROM\nPress enter to return to the menu"; ++ <STDIN>; ++ # TODO : replace by sg else if merged within make_live ++ exit(0); ++ } ++ ++ ++ print "Fixing the partition packages... in progress\n"; ++ # Copy Mandrake/base with the newly generated hdlists from the old repositery; ++ cp_af($_, "$pkgs_mount_path/Mandrake/base") foreach glob_("$cd_mount_path/$rescue_path/Mandrake/base/*"); ++ cp_af($_, "$pkgs_mount_path/Mandrake/RPMS") foreach glob_("$cd_mount_path/$rescue_path/Mandrake/pkgs/*"); ++ unlink($need2befixed_mark); ++ print "Fixing the partition packages... done\n"; ++ } ++} ++ ++ + #=========================================================================== + # Building the disk: + -d $::prefix or mkdir $::prefix; + print "Making live in $::prefix directory.\n"; + diff --git a/globetrotter/make_live b/globetrotter/make_live index e06960d3f..0752165e7 100755 --- a/globetrotter/make_live +++ b/globetrotter/make_live @@ -59,7 +59,7 @@ sub get_hds() { my $all_hds = fsedit::get_hds(); my $other; ($all_hds->{hds}, $other) = partition { $_->{usb_description} eq 'LaCie|LaCie Hard Drive USB' } @{$all_hds->{hds}}; - die "I did not found any LaCie disk\n" if !$all_hds->{hds}[0]; + my_exit("Your disk cannot be restored because it cannot be found!") if !$all_hds->{hds}[0]; $all_hds, $all_hds->{hds}[0]; # $other } @@ -103,6 +103,21 @@ sub formatdisk { run_program::get_stdout('service', 'usb', 'start'); } +sub my_exit { + my ($msg) = @_; + print "\n\n==============================================================\n\n"; + print $msg; + print "\n\nPress <RETURN> to return back to menu\n\n"; + print "==============================================================\n\n"; + <STDIN>; + exit(0); +} + +sub find_partition { + my ($label, @parts) = @_; + find { member(fs::type2fs($_), qw(ext2 ext3)) && chomp_(`e2label /dev/$_->{device} 2>/dev/root`) eq $label } @parts; +} + my $pkg_dev; if ($rescue) { system("mount -t tmpfs none /tmp"); @@ -116,15 +131,23 @@ if ($rescue) { my ($all_hds, $hd, $other) = get_hds(); print "Looking for the package partition\n"; my @parts = partition_table::get_normal_parts($hd); - my $pkg_dev = find { member(fs::type2fs($_), qw(ext2 ext3)) && chomp_(`e2label /dev/$_->{device} 2>/dev/root`) eq "MDK-PKGS" } @parts; - die "I cannot find the package partition which is needed in order to restore the system!" if is_empty_hash_ref($pkg_dev) || !$pkg_dev->{device}; - my $root = find { member(fs::type2fs($_), qw(ext2 ext3)) && chomp_(`e2label /dev/$_->{device} 2>/dev/root`) eq "MDK-ROOT" } @parts; + $pkg_dev = find_partition("MDK-PKGS", @parts); + #die "I cannot find the package partition which is needed in order to restore the system!" + my_exit("Your disk cannot be restored because there is no more a restore partition!") if is_empty_hash_ref($pkg_dev) || !$pkg_dev->{device}; + print "Packages partition was found on $pkg_dev->{device}\n"; + my $root = find_partition("MDK-ROOT", @parts); $root = find { $_->{device} eq "sda1" } @parts if is_empty_hash_ref($root); - die "I cannot find any hard disk to restore!" if is_empty_hash_ref($root) || !$root->{device}; + #my_exit("I cannot find any hard disk to restore!") if is_empty_hash_ref($root) || !$root->{device}; + my_exit("Your disk cannot be restored because there is no more a root partition!") if is_empty_hash_ref($root) || !$root->{device}; + print "\nPlease wait, disk is being checked, this can take quite some time\n\n"; + run_program::run("e2fsck -C0 -y $_") foreach map { + my $p = find_partition($_, @parts); + if_($p, $p->{device}); # handle lost labels + } "MDK-PKGS", "MDK-HOME"; # MDK-ROOT" print "Please wait, disk reinstallation is in progress, this can take quite some time\n"; print "Formating $root->{device}\n"; system("mkfs.ext2 -j /dev/$root->{device} > /dev/null\n"); - + run_program::run('tune2fs', '-L', "MDK-ROOT", "/dev/$root->{device}"); # prevent lost label if restore aborts before the end } sub installPackages() { @@ -166,8 +189,8 @@ sub installPackages() { #my @l = glob_('/export/Mandrake/RPMS/kernel-enterprise-2.6*'); my @l = glob_('/export/Mandrake/RPMS/kernel-2.6*'); @l >= 1 or die "can't find kernel"; - @l <= 1 or die "too many kernels"; - first(`rpm -qp --qf '%{name}' $l[0]` =~ /kernel-(.*)/); + @l <= 1 or warn "too many kernels"; + first(`rpm -qp --qf '%{name}' $l[-1]` =~ /kernel-(.*)/); }; my $kernel_version = c::kernel_version(); @@ -275,6 +298,27 @@ sub config_X_proprietary_drivers() { substInFile { $_ = '' if $_ eq 'nvidia' } "$::prefix/etc/modules"; } +my $fstab; + +my $cleaner = before_leaving { + if (my $err = $@) { + print "\n>> an error happened: $err\n"; + } + print "Cleaning on exiting\n"; + print "- Umounting partitions:\n"; + print "\tumounting /proc\n"; + eval { fs::umount("$::prefix/proc") }; + # fs::umount("$::prefix/$_") foreach 'mnt/packages', 'mnt/share', 'home', ''; + if ($fstab) { + print "\tumounting everything else\n"; + eval { fs::umount_all($fstab, $::prefix) } or system("umount $::prefix"); + } + print "\tumounting /tmp\n"; + eval { fs::umount("/tmp") } if $rescue; + print "Cleaning done\n"; +}; + + $::prefix = $ARGV[0] || '/tmp/live_tree'; -d $::prefix or mkdir $::prefix; @@ -299,7 +343,7 @@ my ($root) = grep { $_->{mntpoint} eq "/" } @parts; print "Root is $root->{device}\n"; run_program::run('tune2fs', '-L', "MDK-ROOT", "/dev/$root->{device}"); # fs::mount_part($root, $::prefix); -my $fstab = [ fsedit::get_all_fstab($all_hds) ]; +$fstab = [ fsedit::get_all_fstab($all_hds) ]; # we need to mount every fs we want to see into /etc/fstab !!! fs::mount_part($_, $::prefix) foreach sort { $a->{mntpoint} cmp $b->{mntpoint} } @$fstab; @@ -457,5 +501,4 @@ run_program::rooted($::prefix, 'urpmi.addmedia', '-h', 'contrib', 'file:///mnt/p # for fast test replaying: run_program::rooted($::prefix, 'tar', 'cfj', '/root/etc.tar.bz2', '/etc'); -system("umount $::prefix/proc"); -eval { fs::umount_all($fstab, $::prefix) } or system("umount $::prefix"); +my_exit("Your disk was succesfully restored!\nYou can now reboot your machine."); |
