summaryrefslogtreecommitdiffstats
path: root/rescue/bin
diff options
context:
space:
mode:
authorFrancesc Pinyol Margalef <francesc.pinyol.m@gmail.com>2013-12-21 13:37:33 +0100
committerFrancesc Pinyol Margalef <francesc.pinyol.m@gmail.com>2013-12-21 13:37:33 +0100
commit095c6b25885ce3d22eedba8cdb98f1fd7e8708a5 (patch)
tree5bfc768996b3ddec185abeb02b602b48b14d10db /rescue/bin
parentdf60191bdbddfa7c8e5bd11a2578aae6740963c0 (diff)
parentf76dc0931e47338aa9c7db257d28e5015d8a2f47 (diff)
downloaddrakx-095c6b25885ce3d22eedba8cdb98f1fd7e8708a5.tar
drakx-095c6b25885ce3d22eedba8cdb98f1fd7e8708a5.tar.gz
drakx-095c6b25885ce3d22eedba8cdb98f1fd7e8708a5.tar.bz2
drakx-095c6b25885ce3d22eedba8cdb98f1fd7e8708a5.tar.xz
drakx-095c6b25885ce3d22eedba8cdb98f1fd7e8708a5.zip
Merge branch 'master' of git://git.mageia.org/software/drakx
Diffstat (limited to 'rescue/bin')
-rwxr-xr-xrescue/bin/drvinst38
-rwxr-xr-xrescue/bin/guessmounts145
-rwxr-xr-xrescue/bin/install_bootloader72
-rwxr-xr-xrescue/bin/lsparts45
-rwxr-xr-xrescue/bin/rescue-doc57
-rwxr-xr-xrescue/bin/restore_ms_boot74
6 files changed, 431 insertions, 0 deletions
diff --git a/rescue/bin/drvinst b/rescue/bin/drvinst
new file mode 100755
index 000000000..4868b42e0
--- /dev/null
+++ b/rescue/bin/drvinst
@@ -0,0 +1,38 @@
+#!/usr/bin/perl
+#
+# Guillaume Cottenceau
+#
+# Copyright 2000-2005 Mandriva
+#
+# This software may be freely redistributed under the terms of the GNU
+# public license.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+
+use lib qw(/usr/lib/libDrakX);
+use common;
+use detect_devices;
+
+$ARGV[0] =~ /^--?h/ and die "usage: drivers_install [drivertype1 [drivertype2 ...]]\n";
+my @types = @ARGV;
+
+sub install_module {
+ my ($driver, $descr) = @_;
+ print STDERR qq(Installing driver $driver (for "$descr")\n);
+ system("/sbin/modprobe", $driver) and print "\tfailed\n";
+}
+
+#- start
+foreach my $card (detect_devices::pci_probe()) {
+ # ignoring "unknown", "Card:foobar" and the like as well as video cards:
+ $card->{driver} eq 'unknown' || $card->{driver} =~ /:/ and next;
+ $card->{media_type} eq "DISPLAY_VGA" and next;
+
+ # load drivers for selected categories or for everything if no args:
+ if (!@ARGV || find { $card->{media_type} =~ /$_/i } @types) {
+ install_module($card->{driver}, $card->{description});
+ }
+}
diff --git a/rescue/bin/guessmounts b/rescue/bin/guessmounts
new file mode 100755
index 000000000..27b920c9d
--- /dev/null
+++ b/rescue/bin/guessmounts
@@ -0,0 +1,145 @@
+#!/usr/bin/perl
+#
+# Guillaume Cottenceau
+#
+# Copyright 2001-2005 Mandriva
+#
+# This software may be freely redistributed under the terms of the GNU
+# public license.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+
+use lib qw(/usr/lib/libDrakX);
+use common;
+use devices;
+use fs;
+use fs::dmcrypt;
+use fs::proc_partitions;
+use fs::type;
+use lvm;
+use run_program;
+
+my @proc_mounts = fs::read_fstab('', '/proc/mounts');
+
+my $target = '/mnt';
+
+if (fs::get::mntpoint2part($target, \@proc_mounts)) {
+ print STDERR "$target is already mounted (according to /proc/mounts)\n";
+ exit 0;
+}
+
+system('drvinst', 'STORAGE');
+
+print STDERR "\nPlease wait, trying to find your root device...\n";
+
+mkdir_p($target);
+
+{
+ local $::isInstall = 1; # so that detect_during_install() got called by init:
+ lvm::init();
+}
+fs::dmcrypt::init;
+
+my @parts = map {
+ $_->{device} = delete $_->{dev};
+ put_in_hash($_, fs::type::type_subpart_from_magic($_));
+} fs::proc_partitions::read_raw();
+my ($raid_parts, $normal_parts) = partition { isRawRAID($_) } @parts;
+
+if (@$raid_parts) {
+ require raid;
+ raid::detect_during_install(@$raid_parts);
+ my $raids = raid::get_existing(@$raid_parts);
+ push @$normal_parts, @$raids;
+}
+
+my @roots;
+
+my $arch = arch() =~ /i.86/ ? $MDK::Common::System::compat_arch{arch()} : arch();
+foreach (@$normal_parts) {
+ my $dev = devices::make($_->{device});
+
+ my $fs = find {
+ system("mount -t $_ $dev $target 2>/dev/null") == 0;
+ } fs::type::true_local_fs_types() or next;
+
+ if (my $release_file = common::release_file($target)) {
+ my $release = chomp_(cat_("$target$release_file"));
+ print STDERR "=> found a $release root partition on $dev\n=> type $fs, version `\n";
+ my @fstab = fs::read_fstab($target, '/etc/fstab');
+ my $h = common::parse_release_file($target, $release_file, $_);
+ add2hash($h, { dev => $dev, fs => $fs, fstab => \@fstab,
+ pretty_name => "$h->{release} $h->{version} $h->{arch} on $dev" });
+ # Offer to rescue only same arch:
+ $h->{pretty_name} .= " (cannot be rescued: $h->{arch} ne $arch;)" if $h->{arch} ne $arch;
+ push @roots, $h;
+ }
+ system('umount', $target) == 0 or die "error unmounting $target\n";
+}
+
+my ($root, $fs, @fstab);
+
+# Try Mageia first:
+if (@roots) {
+ # Order by release number:
+ @roots = sort { $b->{version} cmp $a->{version} } @roots;
+ # Then pick mga over mdv:
+ @roots = map { @$_ } partition { $_->{release} =~ /Mageia/ } @roots;
+
+ my $selected;
+ if (@roots == 1) {
+ $selected = first(@roots);
+ } else {
+ print "\n\nWhich system do you want to rescue?\n0: Abort\n";
+ each_index { print $::i + 1, ": $_->{pretty_name}\n" } @roots;
+ my $res;
+ while ($res < 1 || $res > @roots) {
+ print "what is your choice (type the number of your selection or C^c to abort)?\n";
+ $res = <>;
+ chomp($res);
+ if ($res eq "0") {
+ print "Aborting\n";
+ exit(1);
+ }
+ }
+ $selected = $roots[$res-1];
+ }
+
+ $root = $selected->{dev};
+ $fs = $selected->{fs};
+ @fstab = @{$selected->{fstab}};
+ print STDERR "=> Selecting $root as root fs\n";
+}
+
+if ($root) {
+ system("mount -t $fs $root $target 2>/dev/null");
+
+ print STDERR "\nMounting other partitions from fstab on $target...\n";
+ foreach (@fstab) {
+ my ($valued_options, $options) = fs::mount_options::unpack($_);
+
+ next if
+ !$_->{fs_type} || $_->{device} eq 'none'
+ || $valued_options->{noauto}
+ || $_->{mntpoint} eq '/'
+ || member($_->{fs_type}, 'swap', 'nfs', 'ntfs', 'ntfs-3g');
+
+ delete $valued_options->{'iocharset='};
+ delete $valued_options->{'codepage='};
+ fs::mount_options::pack($_, $valued_options, $options); #- vfat opts, we don't have the modules in rescue
+
+ my $where = "$target$_->{mntpoint}";
+ my $dev = fs::wild_device::from_part('', $_);
+ mkdir_p($where);
+ print STDERR "\t$dev on $where type $_->{fs_type} options $_->{options}\n";
+ system("mount -t $_->{fs_type} $dev $where -o $_->{options}");
+ }
+ system("mount -t proc proc $target/proc");
+ print STDERR "\nYour system is ready on $target.\n\n";
+} else {
+ die "Could not find your root device :-(.\n";
+}
+
diff --git a/rescue/bin/install_bootloader b/rescue/bin/install_bootloader
new file mode 100755
index 000000000..7328de1d2
--- /dev/null
+++ b/rescue/bin/install_bootloader
@@ -0,0 +1,72 @@
+#!/usr/bin/perl
+#
+# Guillaume Cottenceau
+#
+# Copyright 2001-2005 Mandriva
+#
+# This software may be freely redistributed under the terms of the GNU
+# public license.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+
+use lib qw(/usr/lib/libDrakX);
+use common;
+use bootloader;
+use fs;
+
+my $auto;
+if ($ARGV[0] eq '--auto') {
+ $auto = shift @ARGV;
+}
+
+$::prefix = '/mnt';
+
+my $release = common::mageia_release($::prefix) ||
+ do {
+ system('guessmounts') == 0 or die 'guessmounts failed';
+ common::mageia_release($::prefix);
+ };
+
+if ($release) {
+ $release =~ /Mageia|Mandriva/ or die "release file doesn't contain '%s', exiting.\n";
+} elsif (fs::get::mntpoint2part($::prefix, [ fs::read_fstab('', '/proc/mounts') ])) {
+ die "unknown distribution mounted in $::prefix\n";
+} else {
+ die "Your root device isn't mounted on $::prefix\n";
+}
+
+my @main_methods = bootloader::configured_main_methods();
+
+my $main_method;
+if (@main_methods == 0) {
+ die "Cannot find a configured boot loader\n";
+} elsif (@main_methods == 1) {
+ ($main_method) = @main_methods;
+} else {
+ while (1) {
+ print "Configuration files for Boot Loaders ", join(' and ', @main_methods), " were found.\n";
+ print "Which one one should be installed? ";
+ chomp($main_method = <STDIN>);
+ if (member($main_method, @main_methods)) {
+ last;
+ } else {
+ print "bad choice\n";
+ }
+ }
+}
+
+my $install = $bootloader::{'install_raw_' . $main_method} or die "unknown bootloader method install_raw_$main_method\n";
+
+print "About to re-install Boot Loader $main_method of following %s distribution:\n\t",
+ $release, "\n";
+if (!$auto) {
+ print "=> ok? <press Enter to continue, 'n' and Enter to cancel> ";
+ <STDIN> =~ /^n/i and exit 0;
+}
+
+run_program::run('mount', '--bind', '/dev', "$::prefix/dev");
+$install->();
+run_program::run('umount', "$::prefix/dev");
diff --git a/rescue/bin/lsparts b/rescue/bin/lsparts
new file mode 100755
index 000000000..8d36a02f4
--- /dev/null
+++ b/rescue/bin/lsparts
@@ -0,0 +1,45 @@
+#!/usr/bin/perl
+#
+# Main author Pascal Rigaux (pixel)
+# Put together by Guillaume Cottenceau
+#
+# Copyright 1999-2005 Mandriva
+#
+# This software may be freely redistributed under the terms of the GNU
+# public license.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+#
+# Detects partition types using signatures
+#
+
+use lib qw(/usr/lib/libDrakX);
+use common;
+use fs::type;
+use fs::proc_partitions;
+
+my $params = join '', @ARGV;
+my $verbose = $params =~ /-v/;
+
+$params =~ /-h/ and die "usage: lsparts [-v]\n";
+
+
+foreach (fs::proc_partitions::read_raw()) {
+ if (my $err = $_->{size} <= 1 ?
+ "Skipping <$_->{dev}> because too little blocks ($_->{size})" :
+ $_->{dev} !~ /\d$/ ?
+ "Skipping <$_->{dev}> because doesn't end with a number (e.g. seems to not be a partition)" :
+ $_->{dev} =~ /^loop\d+$/ ?
+ "Skipping <$_->{dev}>" :
+ '') {
+ print STDERR "$err\n" if $verbose;
+ } else {
+ $_->{device} = $_->{dev};
+ if (my $type = fs::type::type_subpart_from_magic($_)) {
+ printf "$_->{dev}: %6s, fs %s (%s)\n", formatXiB($_->{size} * 512), $type->{fs_type}, fs::type::part2type_name($type);
+ }
+ }
+}
diff --git a/rescue/bin/rescue-doc b/rescue/bin/rescue-doc
new file mode 100755
index 000000000..e6514b462
--- /dev/null
+++ b/rescue/bin/rescue-doc
@@ -0,0 +1,57 @@
+#!/usr/bin/perl
+
+# From MDK::Common:
+sub output { my $f = shift; open(my $F, ">$f") or die "output in file $f failed: $!\n"; print $F $_ foreach @_ }
+
+output('/tmp/rescue-doc-contents', q(
+ Information regarding problems not directly addressed
+ by this rescue.
+
+
+Are you certain "rescue mode" is the best tool for your specific
+problem?
+
+The rescue system on this CD is a very basic text-based
+environment for rescuing systems that no longer boot. You will
+not find an easy-to-use graphical environment in this rescue
+system, nor the detection/configuration libraries.
+
+
+The vast majority of problems that can affect a Linux system are
+much easier to repair on a running system than by booting into
+"rescue mode". In fact, there are very few problems which aren't
+easier to resolve in the comfortable environment of a fully
+installed system than in this spartan "rescue system" shell.
+Some of the most common problems include:
+
+- bad or missing X (video display) configuration
+- adding/removing/reconfiguring hardware
+- repairing problems caused by installing third-party software
+ with the "--force" and "--nodeps" options
+
+The general rule of thumb is: "If you can boot into the Linux
+system without using rescue mode or this CD, there is no real
+reason to use the rescue CD".
+
+
+However, if you can no longer boot into the system, the rescue
+system is the right tool. Some common examples include:
+
+- If you previously changed some parameters in the /etc/fstab and
+ the system will no longer boot, fix the offending line while in
+ rescue mode, then try to boot normally into your system.
+
+- If the problem cannot be completely resolved in rescue mode
+ (for example, if you need to reconfigure the video display),
+ just modify what's necessary to boot into a running system,
+ then complete the fix from there.
+
+For more information on troubleshooting your system,
+please consult the official manuals, the documentation on
+wiki.mageia.org or support forum at forum.mageia.org.
+
+<press 'q' (qwerty keyboard) to continue>
+));
+
+exec 'less /tmp/rescue-doc-contents';
+
diff --git a/rescue/bin/restore_ms_boot b/rescue/bin/restore_ms_boot
new file mode 100755
index 000000000..1f8cc2907
--- /dev/null
+++ b/rescue/bin/restore_ms_boot
@@ -0,0 +1,74 @@
+#!/usr/bin/perl
+#
+# Guillaume Cottenceau, Pixel
+#
+# Copyright 2002-2005 Mandriva
+#
+# This software may be freely redistributed under the terms of the GNU
+# public license.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+
+use lib qw(/usr/lib/libDrakX);
+use common;
+use bootloader;
+use fs;
+use fs::proc_partitions;
+use partition_table::raw;
+
+
+my @choices = map {
+ my $type = partition_table::raw::typeOfMBR($_->{dev});
+ if_($type && member($type, bootloader::main_method_choices()) , [ $_->{dev}, $type ]);
+} fs::proc_partitions::read_raw();
+
+my $choice;
+
+if (!@choices) {
+ print "No known Linux bootloader has been found, nothing to do.\n";
+} elsif (@choices == 1) {
+ print "I've found a Linux bootloader only on <$choices[0][0]>.\n\n";
+ $choice = $choices[0];
+} else {
+ print "I've found the following Linux bootloaders:\n",
+ (map_index { "\t" . $::i . ": <$_->[1]> \ton <$_->[0]>\n" } @choices),
+ "\n",
+ "Which disk/partition do you want to overwrite with the Windows bootloader?\n",
+ "\t<enter the number or press 'n' and Enter to cancel> ";
+ if (<STDIN> =~ /^(\d+)$/i && $1 >= 1) {
+ $choice = $choices[$1 - 1];
+ }
+}
+
+if ($choice) {
+ print "I'm going to overwrite bootloader on <$choice->[0]> with
+Windows bootloader.
+
+Ok? <press Enter to continue, 'n' and Enter to cancel> ";
+ <STDIN> =~ /^n/i and exit 0;
+
+ system('dd', 'if=/usr/lib/extipl/aldebaran.bin', "of=/dev/$choice->[0]") == 0
+ or print "\tFailed!\n";
+}
+
+#-------------------------------------------------
+#- $Log$
+#- Revision 1.5 2005/06/13 04:33:50 prigaux
+#- move functions using /proc/partitions out of fsedit to fs::proc_partitions
+#-
+#- Revision 1.4 2005/05/19 08:59:54 prigaux
+#- rewrite using DrakX modules
+#-
+#- Revision 1.3 2005/04/19 12:49:39 prigaux
+#- update copyright
+#-
+#- Revision 1.2 2004/07/20 02:42:12 prigaux
+#- MandrakeSoft -> Mandrakesoft
+#-
+#- Revision 1.1 2002/02/27 13:31:30 gc
+#- add "restore Windows Boot Loader" to rescue
+#-
+#-