From e7aedc3aa7e08f3337c86085c6da10ca83445024 Mon Sep 17 00:00:00 2001 From: Colin Guthrie Date: Mon, 2 Dec 2013 23:40:22 +0000 Subject: rescue: Move files around and introduce proper dep tracking. This moves any perl files into bin and sbin folders which will be directly installed in /usr/bin and /usr/sbin. This is done such that the extract modes in list.xml still work and the files end up in the right places. All other files have been moved into the tree folder in their final destination. --- rescue/Makefile | 2 +- rescue/bin/drvinst | 38 +++ rescue/bin/guessmounts | 145 +++++++++++ rescue/bin/install_bootloader | 72 ++++++ rescue/bin/lsparts | 45 ++++ rescue/bin/rescue-doc | 57 +++++ rescue/bin/restore_ms_boot | 74 ++++++ rescue/diskdrake-resize | 29 --- rescue/drvinst | 38 --- rescue/genpasswd | 13 - rescue/grabjournallogs | 51 ---- rescue/guessmounts | 145 ----------- rescue/install_bootloader | 72 ------ rescue/list.xml | 29 +-- rescue/lsparts | 45 ---- rescue/partimage_whole_disk | 264 -------------------- rescue/rescue-doc | 57 ----- rescue/restore-image-lib.sh | 80 ------ rescue/restore-image.sh | 412 ------------------------------- rescue/restore_ms_boot | 74 ------ rescue/sbin/partimage_whole_disk | 264 ++++++++++++++++++++ rescue/startssh | 27 -- rescue/tree/usr/lib/restore-image-lib.sh | 80 ++++++ rescue/tree/usr/sbin/diskdrake-resize | 29 +++ rescue/tree/usr/sbin/genpasswd | 13 + rescue/tree/usr/sbin/grabjournallogs | 51 ++++ rescue/tree/usr/sbin/restore-image.sh | 412 +++++++++++++++++++++++++++++++ rescue/tree/usr/sbin/startssh | 27 ++ 28 files changed, 1317 insertions(+), 1328 deletions(-) create mode 100755 rescue/bin/drvinst create mode 100755 rescue/bin/guessmounts create mode 100755 rescue/bin/install_bootloader create mode 100755 rescue/bin/lsparts create mode 100755 rescue/bin/rescue-doc create mode 100755 rescue/bin/restore_ms_boot delete mode 100755 rescue/diskdrake-resize delete mode 100755 rescue/drvinst delete mode 100755 rescue/genpasswd delete mode 100755 rescue/grabjournallogs delete mode 100755 rescue/guessmounts delete mode 100755 rescue/install_bootloader delete mode 100755 rescue/lsparts delete mode 100755 rescue/partimage_whole_disk delete mode 100755 rescue/rescue-doc delete mode 100755 rescue/restore-image-lib.sh delete mode 100755 rescue/restore-image.sh delete mode 100755 rescue/restore_ms_boot create mode 100755 rescue/sbin/partimage_whole_disk delete mode 100755 rescue/startssh create mode 100755 rescue/tree/usr/lib/restore-image-lib.sh create mode 100755 rescue/tree/usr/sbin/diskdrake-resize create mode 100755 rescue/tree/usr/sbin/genpasswd create mode 100755 rescue/tree/usr/sbin/grabjournallogs create mode 100755 rescue/tree/usr/sbin/restore-image.sh create mode 100755 rescue/tree/usr/sbin/startssh diff --git a/rescue/Makefile b/rescue/Makefile index 473bdd14a..64e9119e3 100644 --- a/rescue/Makefile +++ b/rescue/Makefile @@ -10,7 +10,7 @@ all: $(RESCUE) install: $(RESCUE) cp -f $< $(STAGE2_DEST) -$(RESCUE): $(wildcard tree/**/*) list.xml drvinst guessmounts lsparts rescue-doc make_rescue_img +$(RESCUE): $(wildcard tree/**/*) $(wildcard bin/*) $(wildcard sbin/*) make_rescue_img list.xml aliases DISTRIB_DESCR=$(DISTRIB_DESCR) ./make_rescue_img dist: tar 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 = ); + 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? "; + =~ /^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. + + +)); + +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 "; + if ( =~ /^(\d+)$/i && $1 >= 1) { + $choice = $choices[$1 - 1]; + } +} + +if ($choice) { + print "I'm going to overwrite bootloader on <$choice->[0]> with +Windows bootloader. + +Ok? "; + =~ /^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 +#- +#- diff --git a/rescue/diskdrake-resize b/rescue/diskdrake-resize deleted file mode 100755 index 88372aac7..000000000 --- a/rescue/diskdrake-resize +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/perl - -use lib qw(/usr/lib/libDrakX); - -use devices; -use log; -use resize_fat::main; -use diskdrake::resize_ntfs; -use diskdrake::resize_ext2; - -my ($device, $fs_type, $size) = @ARGV - or die "usage: $0 \n"; - -my %fs_pkgs = ( - vfat => 'resize_fat::main', - ntfs => 'diskdrake::resize_ntfs', - ext2 => 'diskdrake::resize_ext2', - ext3 => 'diskdrake::resize_ext2', - ext4 => 'diskdrake::resize_ext2', -); - -my $resize_pkg = $fs_pkgs{$fs_type} - or die "no support for $fs_type type\n"; - -log::l("resizing $device to $size"); - -my $resize = $resize_pkg->new($device, devices::make($device)) - or die "unable to initialize resize\n"; -$resize->resize($size); diff --git a/rescue/drvinst b/rescue/drvinst deleted file mode 100755 index 4868b42e0..000000000 --- a/rescue/drvinst +++ /dev/null @@ -1,38 +0,0 @@ -#!/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/genpasswd b/rescue/genpasswd deleted file mode 100755 index 2f129673d..000000000 --- a/rescue/genpasswd +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/perl - -use strict; - -system "stty -echo"; -print STDERR "Give a password for ssh access: "; -chomp(my $word = ); -print STDERR "\n"; -system "stty echo"; - -my @salt = ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]; -print crypt($word, join('', @salt)); -print "\n"; diff --git a/rescue/grabjournallogs b/rescue/grabjournallogs deleted file mode 100755 index ef2ea4a1d..000000000 --- a/rescue/grabjournallogs +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/bash - -if ! mountpoint -q /mnt ; then - echo "I do not seem to see a Mageia install mounted on /mnt. You need to mount it first!" >&2 - exit 1 -fi - -if [ ! -f /mnt/etc/machine-id ]; then - echo "Cannot find machine-id file (/mnt/etc/machine-id)" >&2 - exit 1 -fi - -MID=$(cat /mnt/etc/machine-id) -echo -echo "Found machine-id: $MID" -if [ ! -d /mnt/var/log/journal/$MID ]; then - echo "Cannot find journal log directory (/mnt/var/log/journal/)" >&2 - exit 1 -fi - -TIMEFRAME=24 -if [ -n "$1" ]; then - NEWTIMEFRAME=$(( 0 + $1 )) - if [ $NEWTIMEFRAME -gt 0 ]; then - TIMEFRAME=$NEWTIMEFRAME - fi -fi -SINCE="$(LC_ALL=c date --date=$TIMEFRAME' hours ago' +'%F %T')" -echo "Will collect logs from the last $TIMEFRAME hour(s)" -echo " NB give numeric argument to override capture period" - -TEMPFILE=$(mktemp /tmp/grabjournallogs.XXXXXX) -echo -n "Extracting logs... " -journalctl -D /mnt/var/log/journal/$MID --since "$SINCE" -o short >$TEMPFILE -echo "done" - -if [ $(cat $TEMPFILE | wc -l) -lt 2 ]; then - rm -f $TEMPFILE - echo >&2 - echo "Cannot find any logs. Consider increasing the capture period by passing a" >&2 - echo "numeric argument larger than $TIMEFRAME." >&2 - exit 1 -fi - -echo -n "Compressing logs... " -cat $TEMPFILE | xz >/journallogs.xz -rm -f $TEMPFILE -echo "done" - -echo -echo "Your logs have been extracted to the file 'journallogs.xz'" diff --git a/rescue/guessmounts b/rescue/guessmounts deleted file mode 100755 index 27b920c9d..000000000 --- a/rescue/guessmounts +++ /dev/null @@ -1,145 +0,0 @@ -#!/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/install_bootloader b/rescue/install_bootloader deleted file mode 100755 index 7328de1d2..000000000 --- a/rescue/install_bootloader +++ /dev/null @@ -1,72 +0,0 @@ -#!/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 = ); - 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? "; - =~ /^n/i and exit 0; -} - -run_program::run('mount', '--bind', '/dev', "$::prefix/dev"); -$install->(); -run_program::run('umount', "$::prefix/dev"); diff --git a/rescue/list.xml b/rescue/list.xml index 29139f46d..d4c0adcb4 100644 --- a/rescue/list.xml +++ b/rescue/list.xml @@ -410,15 +410,18 @@ - - rescue-doc drvinst lsparts - guessmounts install_bootloader + + bin/rescue-doc + bin/drvinst + bin/lsparts + bin/guessmounts + bin/install_bootloader - restore_ms_boot + bin/restore_ms_boot - - partimage_whole_disk + + sbin/partimage_whole_disk @@ -439,20 +442,6 @@ dhcp-client - - - diskdrake-resize - genpasswd - startssh - grabjournallogs - - - restore-image.sh - - - restore-image-lib.sh - - dirname diff --git a/rescue/lsparts b/rescue/lsparts deleted file mode 100755 index 8d36a02f4..000000000 --- a/rescue/lsparts +++ /dev/null @@ -1,45 +0,0 @@ -#!/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/partimage_whole_disk b/rescue/partimage_whole_disk deleted file mode 100755 index ed0653a95..000000000 --- a/rescue/partimage_whole_disk +++ /dev/null @@ -1,264 +0,0 @@ -#!/usr/bin/perl - -use lib qw(/usr/lib/libDrakX); -use standalone; -use fsedit; -use fs::format; -use fs::type; -use resize_fat::main; -use diskdrake::resize_ntfs; -use diskdrake::resize_ext2; -use common; -use partition_table::empty; -use Carp::Heavy; - -my %options = ( - save_home_directory => 1, - empty_space_at_end_of_disk => 0, # 300 * 1024 * 2, # 300MB - ask_before_modifying_home => 1, - bzip2 => 1, -); - -my ($server); -if ($ARGV[0] eq '-s') { - (undef, $server, @ARGV) = @ARGV; -} -my $action = shift @ARGV; - -sub usage() { die "partimage_whole_disk [-s ] (save_all | rest_all )\n" } - -$ENV{PATH} = "/sbin:/usr/sbin:$ENV{PATH}"; -$ENV{HOME} = '/'; -log::openLog("/var/log/partimage_whole_disk.log"); -my @partimage_cmd = ('partimage', if_($server, '-s', $server, '-n', '-L')); - -@ARGV == 1 or usage(); - -if ($server && !is_network_configured()) { - run_program::run('drvinst', 'NETWORK'); - run_program::run('dhcp-client'); -} - -run_program::run('drvinst', 'STORAGE_SCSI', 'STORAGE_IDE'); - -my $all_hds = fsedit::get_hds({}); - -if ($action eq 'save_all') { - save_all($ARGV[0]); -} elsif ($action eq 'rest_all') { - rest_all($ARGV[0]); -} - -sub save_all { - my ($dir) = @_; - - my $base_dir = $dir; - for (my $i = 0; read_part_list($dir); $i++) { - #- find a free dir - $dir = sprintf("$base_dir.%03d", $i); - } - - my $hd = $all_hds->{hds}[0] or die "no main hard drive\n"; - log::l("save_all on $hd->{device}"); - my $part_list = [ partition_table::get_normal_parts($hd) ]; - - foreach (@$part_list) { - $_->{saved} = !member($_->{fs_type}, 'ntfs', 'ntfs-3g', 'vfat', 'swap'); - } - - if (!$options{save_home_directory}) { - #- shrink and don't save the last ext3 partition (which is the /home partition) - if (my $part = find { isTrueLocalFS($_) } reverse @$part_list) { - $part->{size} = min($part->{size}, 1024 * 1024 * 2); # not greater than 1GB - $part->{saved} = 0; - } - } - - foreach (grep { $_->{saved} } @$part_list) { - run_or_die(@partimage_cmd, - if_($options{bzip2}, '-z', 2), - '-V', 0, '--nombr', '--nodesc', '--nocheck', '-b', '-o', - 'save', devices::make($_->{device}), "$dir/$_->{device}"); - } - save_part_list($dir, $hd->{geom}, $part_list); -} -sub rest_all { - my ($dir) = @_; - - my ($forced_geom, $part_list) = read_part_list($dir) or error("read_part_list $dir failed"); - - (my $hd) = my @used_hds = uniq(map { - my $part = $_; - find { $part->{device} =~ /^\Q$_->{device}\E./ } fs::get::hds($all_hds) - or error("can't find hard drive for partition $part->{device}"); - } @$part_list); - - @used_hds >= 1 or error("no matching hd"); - @used_hds <= 1 or error("multiple hds: " . join(' ', map { $_->{device} } @used_hds)); - - fs::type::set_fs_type($_, $_->{fs_type}) foreach @$part_list; - put_in_hash($_, partition_table::hd2minimal_part($hd)) foreach @$part_list; - - my ($from_partimage, $other) = partition { $_->{saved} } @$part_list; - my ($from_resize, $created) = partition { member($_->{fs_type}, 'vfat', 'ntfs', 'ntfs-3g') } @$other; - - my $total = sum(map { $_->{size} } @$part_list); - if ($total > $hd->{totalsectors}) { - error("$dir doesn't fit: $total > $hd->{totalsectors}"); - } - - - foreach (@$from_resize) { - #- resize first - my $part = fs::get::device2part($_->{device}, [ fs::get::fstab($all_hds) ]); - if (!$part) { - log::l("partition to resize is missing ($_->{device})"); - $_->{missing} = 1; - next; - } - if ($part->{fs_type} ne $_->{fs_type}) { - log::l("partition $_->{device} doesn't have the right filesystem ($part->{fs_type} != $_->{fs_type})"); - $_->{missing} = 1; - next; - } - - if (@$from_resize == 1) { - my $half_size = int($hd->{totalsectors} / 2) - 2 * $hd->cylinder_size; - my $suggested_total = $total - $_->{size} + $half_size; - log::l("resizing bigger? (size $_->{size}, half_size $half_size, total $total, suggested_total $suggested_total)"); - if ($half_size > $_->{size} && $suggested_total < $hd->{totalsectors}) { - log::l("prefering to resize $_->{device} to size $half_size instead of $_->{size}"); - $_->{size} = $half_size; - } - } - - $_->{start} = $part->{start}; - if ($_->{size} < $part->{size}) { - log::l("resizing $_->{device} to $_->{size} (it is $part->{size})"); - my $resize_pkg = $_->{fs_type} eq 'vfat' ? 'resize_fat::main' : 'diskdrake::resize_ntfs'; - my $resize = $resize_pkg->new($_->{device}, devices::make($_->{device})); - $resize->resize($_->{size}); - } else { - log::l("no need to resize, instead setting $_->{device}'s size to $part->{size} instead of $_->{size}"); - $_->{size} = $part->{size}; - } - } - - put_in_hash($hd->{geom}, $forced_geom); - log::l("totalsectors $hd->{totalsectors} heads $hd->{geom}{heads} sectors $hd->{geom}{sectors}"); - partition_table::raw::compute_nb_cylinders($hd->{geom}, $hd->{totalsectors}); - - #- grow the last ext3 partition - if (my $part = find { isTrueLocalFS($_) } reverse @$part_list) { - $part->{ratio} = 1; - - if ($options{ask_before_modifying_home}) { - print "\nkeep existing /home? (Y/n) "; - if ( !~ /n/i) { - my $l = @$from_partimage > 1 ? $from_partimage : $created; - #- it was meant to be restored or formatted - my $p = pop @$l; - log::l("keeping existing /home: removing $p->{device}"); - } - } - } - - #- write the partition table - partition_table::raw::zero_MBR($hd); - foreach my $part (grep { $_->{rootDevice} eq $hd->{device} } @$part_list) { - next if $part->{missing}; - - my $hole = find { isEmpty($_) && $_->{size} >= $part->{size} } partition_table::get_normal_parts_and_holes($hd) or die "not enough room for $part->{device}"; - $part->{start} = $hole->{start}; - - log::l("handling $part->{device}"); - my $extended = $part->{device} =~ /(\d+)$/ && $1 > 4 && $hd->hasExtended; - - my %wanted_part = %$part; - if ($part->{ratio}) { - $part->{size} = $hole->{size} - ($options{empty_space_at_end_of_disk} || 0); - } else { - $part->{size} += $hd->{geom}{sectors} if $extended; - $part->{size} += $hd->cylinder_size if $part->{start} == 1; - } - log::l("adding $part->{device} with size $part->{size}"); - partition_table::add($hd, $part, $extended ? 'Extended' : 'Primary'); - foreach ('device', if_(!$part->{ratio}, 'size')) { - $part->{$_} eq $wanted_part{$_} or log::l("bad $_ for $part->{device}: $part->{$_} != $wanted_part{$_}"); - } - } - partition_table::write($hd); - - #- restore from partimage - foreach (@$from_partimage) { - run_or_die(@partimage_cmd, 'restore', '-b', devices::make($_->{device}), "$dir/$_->{device}"); - - if ($_->{ratio}) { - my $resize = diskdrake::resize_ext2->new($_->{device}, devices::make($_->{device})); - $resize->resize($_->{size}); - } - } - - foreach (@$created) { - fs::format::part_raw($_, undef); - } - - run_program::run('guessmounts'); - - if (my @missing = grep { $_->{missing} } @$part_list) { - my $missing = join('|', map { quotemeta($_->{device}) } @missing); - log::l("drop missing devices from fstab and lilo.conf: $missing"); - $::prefix = '/mnt'; - substInFile { $_ = '' if m!^/dev/($missing)\s! } "$::prefix/etc/fstab"; - - my $match; - substInFile { - /^\S/ and $match = m!^other=/dev/($missing)$!; - $_ = '' if $match; - } "$::prefix/etc/lilo.conf"; - } - - run_or_die('install_bootloader', '--auto'); - - print "\n", "Your system is ready, press enter to reboot (Y/n) "; - if ( !~ /n/i) { - run_program::run('reboot'); - } -} - -sub lst_fields() { qw(device size fs_type saved) } -sub save_part_list { - my ($dir, $geom, $part_list) = @_; - my @l = map { join(' ', @$_{lst_fields()}) } @$part_list; - log::l("save_part_list $dir: $_") foreach @l; - my $partimage = join(' ', @partimage_cmd); - open(my $F, "| $partimage -z0 -Bfoo=bar -o save_file $dir/lst"); - print $F join("/", $geom->{heads}, $geom->{sectors}), "\n"; - print $F "$_\n" foreach @l; -} -sub read_part_list { - my ($dir) = @_; - my $partimage = join(' ', @partimage_cmd); - open(my $F, "$partimage -z0 -Bfoo=bar rest_file $dir/lst |"); - my $geom_string = <$F> or return; - my %geom; @geom{'heads', 'sectors'} = split('/', chomp_($geom_string)); - my @l = chomp_(cat__($F)); - log::l("read_part_list $dir: $_") foreach @l; - \%geom, [ map { my %l; @l{lst_fields()} = split; \%l } @l ]; -} - -sub run_or_die { - my (@l) = @_; - run_program::raw({ timeout => 4 * 60 * 60 }, @l) or die join(' ', @l) . " failed\n"; -} - -sub error { - my ($msg) = @_; - log::l($msg); - die "$msg\n"; -} - -sub is_network_configured() { - my (undef, @l) = cat_('/proc/net/route'); - find { /^(\S+)/ && $1 ne 'lo' } @l; -} diff --git a/rescue/rescue-doc b/rescue/rescue-doc deleted file mode 100755 index e6514b462..000000000 --- a/rescue/rescue-doc +++ /dev/null @@ -1,57 +0,0 @@ -#!/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. - - -)); - -exec 'less /tmp/rescue-doc-contents'; - diff --git a/rescue/restore-image-lib.sh b/rescue/restore-image-lib.sh deleted file mode 100755 index 3451f7be5..000000000 --- a/rescue/restore-image-lib.sh +++ /dev/null @@ -1,80 +0,0 @@ -#!/bin/bash - -TITLE="%s Installer" -BACKTITLE="%s" -MIN_DISKSIZE=5000000 - -debug="/dev/null" - -function _msgbox() -{ - dialog --timeout 60 --backtitle "$BACKTITLE" --title "$TITLE" --msgbox \ - "$1" 0 0 - - return $? -} - -function _infobox() -{ - dialog --backtitle "$BACKTITLE" --title "$TITLE" --sleep 2 \ - --infobox "$1" 0 0 - - return $? -} - -function _yesno() -{ - dialog --backtitle "$BACKTITLE" --title "$TITLE" \ - --yes-label "Yes" --no-label "No" --yesno "$1" 0 0 - - return $? -} - -function _mount() -{ - mount $1 $2 > $debug 2>&1 - - return $? -} - -function _umount() -{ - umount $1 > $debug 2>&1 - - return $? -} - -function _bind() -{ - mount --bind $1 $2 > $debug 2>&1 - - return $? -} - -function _eject() -{ - eject $1 > $debug 2>&1 - - return $? -} - -function _shutdown() -{ - [ -e /tmp/no-shutdown ] && exit - clear - sync - echo s > /proc/sysrq-trigger - echo o > /proc/sysrq-trigger - exit -} - -function _reboot() -{ - [ -e /tmp/no-shutdown ] && exit - clear - sync - echo s > /proc/sysrq-trigger - echo b > /proc/sysrq-trigger - exit -} - diff --git a/rescue/restore-image.sh b/rescue/restore-image.sh deleted file mode 100755 index f4f904f3f..000000000 --- a/rescue/restore-image.sh +++ /dev/null @@ -1,412 +0,0 @@ -#!/bin/bash - -setterm -powersave off -setterm -blank 0 - -if [ -r ./restore-image-lib.sh ]; then - . ./restore-image-lib.sh -elif [ -r /usr/lib/restore-image-lib.sh ]; then - . /usr/lib/restore-image-lib.sh -fi - -export PATH="/sbin:/bin:/usr/sbin:/usr/bin" - -mnt_dir="/tmp/mnt" -restore_media="/tmp/media" -images_dir="$restore_media/images" -images="$images_dir/list" -images_config="$images_dir/config" -image="" -win32_part_dev= -win32_part_type= -win32_part_new_size= - -function read_config() -{ - if [ -r "$images_config" ]; then - . $images_config - fi -} - -function image_list() -{ - list=$(cat $images | awk -F',' \ - '{ print $1 " " $2 " " $4 }') - - echo $list -} - -function image_file() -{ - country="$1" - - file=$(grep ^$country $images | awk -F',' '{ print $3 }') - - echo $file -} - -function welcome() -{ - while true; do - clear - msg="\n Welcome to $TITLE\n\ -\nThe following images were found, select one:\n " - opcao=$(dialog --backtitle "$BACKTITLE" --title "$TITLE" \ - --stdout --radiolist "$msg" 0 0 0 \ - $(image_list)) - - if [ "$?" != "0" ]; then - _yesno "\nInterrupt installation?\n " - if [ "$?" = "0" ]; then - _shutdown - fi - else - if [ -z "$opcao" ]; then - continue - else - image=$(image_file $opcao) - break - fi - fi - done - - # disable kernel messages in the console - echo "1 4 1 7" > /proc/sys/kernel/printk -} - -function install_warning() -{ - if [ -n "${win32_part_dev}" ]; then - warn_msg="Windows installation detected.\nWe will set it up as dual boot. \ -You may lose some data.\nPlease backup before proceeding." - else - warn_msg="WARNING: This process will erase all data in this machine, \ -do you want to continue?" - fi - - clear - _yesno "\n$warn_msg\n" - if [ "$?" != "0" ]; then - _shutdown - fi -} - -function detect_root() -{ - inst_source_dev=$(awk "\$2 == \"$restore_media\" { print \$1 }" /proc/mounts | sed -e 's/[0-9]$//') - inst_source_dev=${inst_source_dev#/dev/} - devices=$(grep "^ .*[^0-9]$" < /proc/partitions | grep -v ${inst_source_dev} | awk '$3 > '$MIN_DISKSIZE' { print $4,$3 }') - - if [ -z "${devices}" ]; then - exit 1 - fi - - devs_found=$(($(echo $devices | wc -w)/2)) - - root_data=$(detect_win32 ${inst_source_dev}) - - if [ -z "${root_data}" ]; then - if [ "$devs_found" -gt "1" ]; then - if [ -n "${inst_source_dev}" ]; then - opcao=$(dialog --backtitle "$BACKTITLE" --title "$TITLE" --stdout --menu 'Choose one of the detected devices to restore to (check the blocks size column first):' 8 50 0 $devices ) - if [ "$?" != "0" ]; then - _yesno "\nInterrupt installation?\n " - if [ "$?" = "0" ]; then - _shutdown - fi - else - root_data=${opcao} - fi - fi - else - root_data=$(echo ${devices} | cut -d ' ' -f 1) - fi - fi - - echo ${root_data} -} - -function detect_win32() -{ - # from detect_root() - skip_dev=${1} - - # win32 detection won't handle complex layouts - if [ $(fdisk -l | grep "^/dev/" | grep -v ${skip_dev} | wc -l) -gt 1 ]; then - exit - fi - - # get the last created windows partition information - set -f - device=$(fdisk -l | grep "^/dev/" | grep -v ${skip_dev} | grep -e "FAT\|NTFS\|HPFS" | tail -1 | sed 's/ .*$//') - set +f - - if [ -z "${device}" ]; then - exit - fi - - # it might be needed, for safety - device_type=$(blkid -o value -s TYPE ${device}) - modprobe ${device_type} - - # df for that partition - mount ${device} /mnt - size=$(df ${device} | tail -1) - umount /mnt - - # its diskspace - used=$(echo ${size} | awk '{ print $3 }') - left=$(echo ${size} | awk '{ print $4 }') - avail=$((${left}/2)) - - if [ ! ${avail} -lt ${MIN_DISKSIZE} ]; then - win32_part_dev=${device} - win32_part_type=${device_type} - # our install takes half of 'left' - win32_part_new_size=$((${used}+${avail})) - - dev=${win32_part_dev#/dev/} - disk=${dev%[0-9]} - number=${dev#[a-w][a-w][a-w]} - let number++ - echo ${disk}${number} ${win32_part_dev} ${win32_part_type} ${win32_part_new_size} - fi -} - -function resize_win32() -{ - device=${1} - device_type=${2} - new_win32_size=${3} - - dialog --backtitle "$BACKTITLE" --title "$TITLE" --infobox "\nResizing Windows partition...\n" 4 55 - - dev=${device#/dev/} - disk=${dev%[0-9]} - win32_number=${dev#[a-w][a-w][a-w]} - - case ${device_type} in - vfat) device_id=b ;; - ntfs) device_id=7 ;; - hpfs) device_id=87 ;; - esac - - # wrapper around libdrakx by blino - diskdrake-resize ${device} ${device_type} $((${new_win32_size}*2)) &>/dev/null - - # we need some free sector here, rebuilding layout - fdisk /dev/${disk} &>/dev/null </dev/null </dev/null; dd bs=4M of=/dev/${root} >/tmp/backup.out 2>&1>>/tmp/log) & - - sleep 3 - pid=$(ps ax | grep 'dd bs=4M of' | grep -v grep | awk '{ print $1 }') - - while [ true ]; do - ps | grep -q $pid - if [ $? -eq 0 ]; then - /bin/kill -SIGUSR1 $pid - complete=$(tail -n 1 /tmp/backup.out | awk '{ print $1 }') - echo $((complete*100/total)) - sleep 1 - else - break - fi - done | dialog --backtitle "$BACKTITLE" --title "$TITLE" --gauge "\nWriting image..." 8 45 - - in=$(tail -n 3 /tmp/backup.out | grep 'in$' | cut -d' ' -f1) - out=$(tail -n 3 /tmp/backup.out | grep 'out$' | cut -d' ' -f1) - - if [ x"$in" != x"$out" ]; then - _msgbox "\nError writing image!\n" - sleep 24h - fi - - # Now re-read the partition table because 'dd' might have changed it - sfdisk -R /dev/${root} -} - -function grub_setup() -{ - root=${1} - grub_dir=${2} - - # install the bootloader - grub <> ${grub_dir}/menu.lst </dev/null| grep "Filesystem OS type" | awk '{ print $4 }') - if [ "${filesystem_type}" = "Linux" ]; then - dialog --backtitle "$BACKTITLE" --title "$TITLE" --infobox "Finishing Install... Expanding ${root}" 3 40 - disk=/dev/${root%[0-9]} - main_part=/dev/${root} - - # FIXME: absurdly dirty hack - main_part_num=${root:3} - swap_part_num=$((main_part_num+1)) - swap_part=${disk}${swap_part_num} - - main_part_sectors= - if [ -n "$SWAP_BLOCKS" ]; then - if [ -n "$EXPAND_FS" ]; then - total_blocks=$(sfdisk -s $disk) - main_part_blocks=$((total_blocks-SWAP_BLOCKS)) - main_part_sectors=$((main_part_blocks*2)) - else - main_part_sectors=$(sfdisk -d $disk | perl -lne 'm|^'$main_part'\b.*,\s*size\s*=\s*(\d+)\b| and print($1), exit') - fi - fi - if [ -n "$SWAP_BLOCKS" ]; then - parted $disk -- mkpartfs primary linux-swap ${main_part_sectors}s -1s yes - mkswap -L swap $swap_part - fi - if [ -n "$EXPAND_FS" ]; then - e2fsck -fy $main_part - fdisk $disk << EOF -d -$main_part_num -n -p -$main_part_num - - -a -$main_part_num -w -EOF - sfdisk -R $disk - e2fsck -fy $main_part - resize2fs $main_part - fi - mkdir -p $mnt_dir - mount $main_part $mnt_dir - grub_dir="$mnt_dir/boot/grub" - if [ -d "$grub_dir" ]; then - echo "(hd0) $disk" > "$grub_dir/device.map" - if [ -n "$win32_part_dev" ]; then - grub_setup ${root} ${grub_dir} - fi - fi - if [ -n "$MKINITRD" ]; then - mount -t sysfs none "$mnt_dir/sys" - mount -t proc none "$mnt_dir/proc" - chroot $mnt_dir bootloader-config --action rebuild-initrds - umount "$mnt_dir/sys" - umount "$mnt_dir/proc" - fi - umount $mnt_dir - fi -} - -# installation steps -welcome -read_config -detect_device -install_warning -write_image -expand_fs - -# all done! -_msgbox "\nInstallation process finished.\nPress ENTER to shutdown.\n " - -_shutdown - diff --git a/rescue/restore_ms_boot b/rescue/restore_ms_boot deleted file mode 100755 index 1f8cc2907..000000000 --- a/rescue/restore_ms_boot +++ /dev/null @@ -1,74 +0,0 @@ -#!/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 "; - if ( =~ /^(\d+)$/i && $1 >= 1) { - $choice = $choices[$1 - 1]; - } -} - -if ($choice) { - print "I'm going to overwrite bootloader on <$choice->[0]> with -Windows bootloader. - -Ok? "; - =~ /^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 -#- -#- diff --git a/rescue/sbin/partimage_whole_disk b/rescue/sbin/partimage_whole_disk new file mode 100755 index 000000000..ed0653a95 --- /dev/null +++ b/rescue/sbin/partimage_whole_disk @@ -0,0 +1,264 @@ +#!/usr/bin/perl + +use lib qw(/usr/lib/libDrakX); +use standalone; +use fsedit; +use fs::format; +use fs::type; +use resize_fat::main; +use diskdrake::resize_ntfs; +use diskdrake::resize_ext2; +use common; +use partition_table::empty; +use Carp::Heavy; + +my %options = ( + save_home_directory => 1, + empty_space_at_end_of_disk => 0, # 300 * 1024 * 2, # 300MB + ask_before_modifying_home => 1, + bzip2 => 1, +); + +my ($server); +if ($ARGV[0] eq '-s') { + (undef, $server, @ARGV) = @ARGV; +} +my $action = shift @ARGV; + +sub usage() { die "partimage_whole_disk [-s ] (save_all | rest_all )\n" } + +$ENV{PATH} = "/sbin:/usr/sbin:$ENV{PATH}"; +$ENV{HOME} = '/'; +log::openLog("/var/log/partimage_whole_disk.log"); +my @partimage_cmd = ('partimage', if_($server, '-s', $server, '-n', '-L')); + +@ARGV == 1 or usage(); + +if ($server && !is_network_configured()) { + run_program::run('drvinst', 'NETWORK'); + run_program::run('dhcp-client'); +} + +run_program::run('drvinst', 'STORAGE_SCSI', 'STORAGE_IDE'); + +my $all_hds = fsedit::get_hds({}); + +if ($action eq 'save_all') { + save_all($ARGV[0]); +} elsif ($action eq 'rest_all') { + rest_all($ARGV[0]); +} + +sub save_all { + my ($dir) = @_; + + my $base_dir = $dir; + for (my $i = 0; read_part_list($dir); $i++) { + #- find a free dir + $dir = sprintf("$base_dir.%03d", $i); + } + + my $hd = $all_hds->{hds}[0] or die "no main hard drive\n"; + log::l("save_all on $hd->{device}"); + my $part_list = [ partition_table::get_normal_parts($hd) ]; + + foreach (@$part_list) { + $_->{saved} = !member($_->{fs_type}, 'ntfs', 'ntfs-3g', 'vfat', 'swap'); + } + + if (!$options{save_home_directory}) { + #- shrink and don't save the last ext3 partition (which is the /home partition) + if (my $part = find { isTrueLocalFS($_) } reverse @$part_list) { + $part->{size} = min($part->{size}, 1024 * 1024 * 2); # not greater than 1GB + $part->{saved} = 0; + } + } + + foreach (grep { $_->{saved} } @$part_list) { + run_or_die(@partimage_cmd, + if_($options{bzip2}, '-z', 2), + '-V', 0, '--nombr', '--nodesc', '--nocheck', '-b', '-o', + 'save', devices::make($_->{device}), "$dir/$_->{device}"); + } + save_part_list($dir, $hd->{geom}, $part_list); +} +sub rest_all { + my ($dir) = @_; + + my ($forced_geom, $part_list) = read_part_list($dir) or error("read_part_list $dir failed"); + + (my $hd) = my @used_hds = uniq(map { + my $part = $_; + find { $part->{device} =~ /^\Q$_->{device}\E./ } fs::get::hds($all_hds) + or error("can't find hard drive for partition $part->{device}"); + } @$part_list); + + @used_hds >= 1 or error("no matching hd"); + @used_hds <= 1 or error("multiple hds: " . join(' ', map { $_->{device} } @used_hds)); + + fs::type::set_fs_type($_, $_->{fs_type}) foreach @$part_list; + put_in_hash($_, partition_table::hd2minimal_part($hd)) foreach @$part_list; + + my ($from_partimage, $other) = partition { $_->{saved} } @$part_list; + my ($from_resize, $created) = partition { member($_->{fs_type}, 'vfat', 'ntfs', 'ntfs-3g') } @$other; + + my $total = sum(map { $_->{size} } @$part_list); + if ($total > $hd->{totalsectors}) { + error("$dir doesn't fit: $total > $hd->{totalsectors}"); + } + + + foreach (@$from_resize) { + #- resize first + my $part = fs::get::device2part($_->{device}, [ fs::get::fstab($all_hds) ]); + if (!$part) { + log::l("partition to resize is missing ($_->{device})"); + $_->{missing} = 1; + next; + } + if ($part->{fs_type} ne $_->{fs_type}) { + log::l("partition $_->{device} doesn't have the right filesystem ($part->{fs_type} != $_->{fs_type})"); + $_->{missing} = 1; + next; + } + + if (@$from_resize == 1) { + my $half_size = int($hd->{totalsectors} / 2) - 2 * $hd->cylinder_size; + my $suggested_total = $total - $_->{size} + $half_size; + log::l("resizing bigger? (size $_->{size}, half_size $half_size, total $total, suggested_total $suggested_total)"); + if ($half_size > $_->{size} && $suggested_total < $hd->{totalsectors}) { + log::l("prefering to resize $_->{device} to size $half_size instead of $_->{size}"); + $_->{size} = $half_size; + } + } + + $_->{start} = $part->{start}; + if ($_->{size} < $part->{size}) { + log::l("resizing $_->{device} to $_->{size} (it is $part->{size})"); + my $resize_pkg = $_->{fs_type} eq 'vfat' ? 'resize_fat::main' : 'diskdrake::resize_ntfs'; + my $resize = $resize_pkg->new($_->{device}, devices::make($_->{device})); + $resize->resize($_->{size}); + } else { + log::l("no need to resize, instead setting $_->{device}'s size to $part->{size} instead of $_->{size}"); + $_->{size} = $part->{size}; + } + } + + put_in_hash($hd->{geom}, $forced_geom); + log::l("totalsectors $hd->{totalsectors} heads $hd->{geom}{heads} sectors $hd->{geom}{sectors}"); + partition_table::raw::compute_nb_cylinders($hd->{geom}, $hd->{totalsectors}); + + #- grow the last ext3 partition + if (my $part = find { isTrueLocalFS($_) } reverse @$part_list) { + $part->{ratio} = 1; + + if ($options{ask_before_modifying_home}) { + print "\nkeep existing /home? (Y/n) "; + if ( !~ /n/i) { + my $l = @$from_partimage > 1 ? $from_partimage : $created; + #- it was meant to be restored or formatted + my $p = pop @$l; + log::l("keeping existing /home: removing $p->{device}"); + } + } + } + + #- write the partition table + partition_table::raw::zero_MBR($hd); + foreach my $part (grep { $_->{rootDevice} eq $hd->{device} } @$part_list) { + next if $part->{missing}; + + my $hole = find { isEmpty($_) && $_->{size} >= $part->{size} } partition_table::get_normal_parts_and_holes($hd) or die "not enough room for $part->{device}"; + $part->{start} = $hole->{start}; + + log::l("handling $part->{device}"); + my $extended = $part->{device} =~ /(\d+)$/ && $1 > 4 && $hd->hasExtended; + + my %wanted_part = %$part; + if ($part->{ratio}) { + $part->{size} = $hole->{size} - ($options{empty_space_at_end_of_disk} || 0); + } else { + $part->{size} += $hd->{geom}{sectors} if $extended; + $part->{size} += $hd->cylinder_size if $part->{start} == 1; + } + log::l("adding $part->{device} with size $part->{size}"); + partition_table::add($hd, $part, $extended ? 'Extended' : 'Primary'); + foreach ('device', if_(!$part->{ratio}, 'size')) { + $part->{$_} eq $wanted_part{$_} or log::l("bad $_ for $part->{device}: $part->{$_} != $wanted_part{$_}"); + } + } + partition_table::write($hd); + + #- restore from partimage + foreach (@$from_partimage) { + run_or_die(@partimage_cmd, 'restore', '-b', devices::make($_->{device}), "$dir/$_->{device}"); + + if ($_->{ratio}) { + my $resize = diskdrake::resize_ext2->new($_->{device}, devices::make($_->{device})); + $resize->resize($_->{size}); + } + } + + foreach (@$created) { + fs::format::part_raw($_, undef); + } + + run_program::run('guessmounts'); + + if (my @missing = grep { $_->{missing} } @$part_list) { + my $missing = join('|', map { quotemeta($_->{device}) } @missing); + log::l("drop missing devices from fstab and lilo.conf: $missing"); + $::prefix = '/mnt'; + substInFile { $_ = '' if m!^/dev/($missing)\s! } "$::prefix/etc/fstab"; + + my $match; + substInFile { + /^\S/ and $match = m!^other=/dev/($missing)$!; + $_ = '' if $match; + } "$::prefix/etc/lilo.conf"; + } + + run_or_die('install_bootloader', '--auto'); + + print "\n", "Your system is ready, press enter to reboot (Y/n) "; + if ( !~ /n/i) { + run_program::run('reboot'); + } +} + +sub lst_fields() { qw(device size fs_type saved) } +sub save_part_list { + my ($dir, $geom, $part_list) = @_; + my @l = map { join(' ', @$_{lst_fields()}) } @$part_list; + log::l("save_part_list $dir: $_") foreach @l; + my $partimage = join(' ', @partimage_cmd); + open(my $F, "| $partimage -z0 -Bfoo=bar -o save_file $dir/lst"); + print $F join("/", $geom->{heads}, $geom->{sectors}), "\n"; + print $F "$_\n" foreach @l; +} +sub read_part_list { + my ($dir) = @_; + my $partimage = join(' ', @partimage_cmd); + open(my $F, "$partimage -z0 -Bfoo=bar rest_file $dir/lst |"); + my $geom_string = <$F> or return; + my %geom; @geom{'heads', 'sectors'} = split('/', chomp_($geom_string)); + my @l = chomp_(cat__($F)); + log::l("read_part_list $dir: $_") foreach @l; + \%geom, [ map { my %l; @l{lst_fields()} = split; \%l } @l ]; +} + +sub run_or_die { + my (@l) = @_; + run_program::raw({ timeout => 4 * 60 * 60 }, @l) or die join(' ', @l) . " failed\n"; +} + +sub error { + my ($msg) = @_; + log::l($msg); + die "$msg\n"; +} + +sub is_network_configured() { + my (undef, @l) = cat_('/proc/net/route'); + find { /^(\S+)/ && $1 ne 'lo' } @l; +} diff --git a/rescue/startssh b/rescue/startssh deleted file mode 100755 index e14bb10e8..000000000 --- a/rescue/startssh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash - -# test for an up interface != lo -if test "x"`ifconfig | cut -d ' ' -f 1 | grep -v '^$' | grep -v lo` = "x"; then - echo "There is no up interface, you can try to execute 'drvinst' to find drivers and 'dhcp-client' to configure your interface for DHCP." >&2 - exit 5 -fi - -# generate host keys -mkdir -p /etc/dropbear -[[ -f /etc/dropbear/dropbear_dss_host_key ]] || dropbearkey -t dss -f /etc/dropbear/dropbear_dss_host_key >/dev/null || { echo "Can't generate dsa host key" >&2 ; exit 4; } -[[ -f /etc/dropbear/dropbear_rsa_host_key ]] || dropbearkey -t rsa -f /etc/dropbear/dropbear_rsa_host_key >/dev/null || { echo "Can't generate rsa host key" >&2 ; exit 3; } - -# set a password -passwd=`genpasswd` -if (( $? != 0 )); then - reset - exit $? -fi -sed -E -i -e 's/^root:[^:]*:/root:'"${passwd//\//\\/}"':/' /etc/passwd || { echo "Can't set password" >&2 ; exit 2; } - -# test for /dev/pts -grep '^devpts /dev/pts devpts ' /proc/mounts >/dev/null 2>/dev/null || mount -t devpts devpts /dev/pts - -echo "" -echo -n "Starting ssh daemon... " -dropbear -E 2>/var/log/dropbear.log && echo "OK" || { echo "Failed" ; exit 1; } diff --git a/rescue/tree/usr/lib/restore-image-lib.sh b/rescue/tree/usr/lib/restore-image-lib.sh new file mode 100755 index 000000000..3451f7be5 --- /dev/null +++ b/rescue/tree/usr/lib/restore-image-lib.sh @@ -0,0 +1,80 @@ +#!/bin/bash + +TITLE="%s Installer" +BACKTITLE="%s" +MIN_DISKSIZE=5000000 + +debug="/dev/null" + +function _msgbox() +{ + dialog --timeout 60 --backtitle "$BACKTITLE" --title "$TITLE" --msgbox \ + "$1" 0 0 + + return $? +} + +function _infobox() +{ + dialog --backtitle "$BACKTITLE" --title "$TITLE" --sleep 2 \ + --infobox "$1" 0 0 + + return $? +} + +function _yesno() +{ + dialog --backtitle "$BACKTITLE" --title "$TITLE" \ + --yes-label "Yes" --no-label "No" --yesno "$1" 0 0 + + return $? +} + +function _mount() +{ + mount $1 $2 > $debug 2>&1 + + return $? +} + +function _umount() +{ + umount $1 > $debug 2>&1 + + return $? +} + +function _bind() +{ + mount --bind $1 $2 > $debug 2>&1 + + return $? +} + +function _eject() +{ + eject $1 > $debug 2>&1 + + return $? +} + +function _shutdown() +{ + [ -e /tmp/no-shutdown ] && exit + clear + sync + echo s > /proc/sysrq-trigger + echo o > /proc/sysrq-trigger + exit +} + +function _reboot() +{ + [ -e /tmp/no-shutdown ] && exit + clear + sync + echo s > /proc/sysrq-trigger + echo b > /proc/sysrq-trigger + exit +} + diff --git a/rescue/tree/usr/sbin/diskdrake-resize b/rescue/tree/usr/sbin/diskdrake-resize new file mode 100755 index 000000000..88372aac7 --- /dev/null +++ b/rescue/tree/usr/sbin/diskdrake-resize @@ -0,0 +1,29 @@ +#!/usr/bin/perl + +use lib qw(/usr/lib/libDrakX); + +use devices; +use log; +use resize_fat::main; +use diskdrake::resize_ntfs; +use diskdrake::resize_ext2; + +my ($device, $fs_type, $size) = @ARGV + or die "usage: $0 \n"; + +my %fs_pkgs = ( + vfat => 'resize_fat::main', + ntfs => 'diskdrake::resize_ntfs', + ext2 => 'diskdrake::resize_ext2', + ext3 => 'diskdrake::resize_ext2', + ext4 => 'diskdrake::resize_ext2', +); + +my $resize_pkg = $fs_pkgs{$fs_type} + or die "no support for $fs_type type\n"; + +log::l("resizing $device to $size"); + +my $resize = $resize_pkg->new($device, devices::make($device)) + or die "unable to initialize resize\n"; +$resize->resize($size); diff --git a/rescue/tree/usr/sbin/genpasswd b/rescue/tree/usr/sbin/genpasswd new file mode 100755 index 000000000..2f129673d --- /dev/null +++ b/rescue/tree/usr/sbin/genpasswd @@ -0,0 +1,13 @@ +#!/usr/bin/perl + +use strict; + +system "stty -echo"; +print STDERR "Give a password for ssh access: "; +chomp(my $word = ); +print STDERR "\n"; +system "stty echo"; + +my @salt = ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]; +print crypt($word, join('', @salt)); +print "\n"; diff --git a/rescue/tree/usr/sbin/grabjournallogs b/rescue/tree/usr/sbin/grabjournallogs new file mode 100755 index 000000000..ef2ea4a1d --- /dev/null +++ b/rescue/tree/usr/sbin/grabjournallogs @@ -0,0 +1,51 @@ +#!/bin/bash + +if ! mountpoint -q /mnt ; then + echo "I do not seem to see a Mageia install mounted on /mnt. You need to mount it first!" >&2 + exit 1 +fi + +if [ ! -f /mnt/etc/machine-id ]; then + echo "Cannot find machine-id file (/mnt/etc/machine-id)" >&2 + exit 1 +fi + +MID=$(cat /mnt/etc/machine-id) +echo +echo "Found machine-id: $MID" +if [ ! -d /mnt/var/log/journal/$MID ]; then + echo "Cannot find journal log directory (/mnt/var/log/journal/)" >&2 + exit 1 +fi + +TIMEFRAME=24 +if [ -n "$1" ]; then + NEWTIMEFRAME=$(( 0 + $1 )) + if [ $NEWTIMEFRAME -gt 0 ]; then + TIMEFRAME=$NEWTIMEFRAME + fi +fi +SINCE="$(LC_ALL=c date --date=$TIMEFRAME' hours ago' +'%F %T')" +echo "Will collect logs from the last $TIMEFRAME hour(s)" +echo " NB give numeric argument to override capture period" + +TEMPFILE=$(mktemp /tmp/grabjournallogs.XXXXXX) +echo -n "Extracting logs... " +journalctl -D /mnt/var/log/journal/$MID --since "$SINCE" -o short >$TEMPFILE +echo "done" + +if [ $(cat $TEMPFILE | wc -l) -lt 2 ]; then + rm -f $TEMPFILE + echo >&2 + echo "Cannot find any logs. Consider increasing the capture period by passing a" >&2 + echo "numeric argument larger than $TIMEFRAME." >&2 + exit 1 +fi + +echo -n "Compressing logs... " +cat $TEMPFILE | xz >/journallogs.xz +rm -f $TEMPFILE +echo "done" + +echo +echo "Your logs have been extracted to the file 'journallogs.xz'" diff --git a/rescue/tree/usr/sbin/restore-image.sh b/rescue/tree/usr/sbin/restore-image.sh new file mode 100755 index 000000000..f4f904f3f --- /dev/null +++ b/rescue/tree/usr/sbin/restore-image.sh @@ -0,0 +1,412 @@ +#!/bin/bash + +setterm -powersave off +setterm -blank 0 + +if [ -r ./restore-image-lib.sh ]; then + . ./restore-image-lib.sh +elif [ -r /usr/lib/restore-image-lib.sh ]; then + . /usr/lib/restore-image-lib.sh +fi + +export PATH="/sbin:/bin:/usr/sbin:/usr/bin" + +mnt_dir="/tmp/mnt" +restore_media="/tmp/media" +images_dir="$restore_media/images" +images="$images_dir/list" +images_config="$images_dir/config" +image="" +win32_part_dev= +win32_part_type= +win32_part_new_size= + +function read_config() +{ + if [ -r "$images_config" ]; then + . $images_config + fi +} + +function image_list() +{ + list=$(cat $images | awk -F',' \ + '{ print $1 " " $2 " " $4 }') + + echo $list +} + +function image_file() +{ + country="$1" + + file=$(grep ^$country $images | awk -F',' '{ print $3 }') + + echo $file +} + +function welcome() +{ + while true; do + clear + msg="\n Welcome to $TITLE\n\ +\nThe following images were found, select one:\n " + opcao=$(dialog --backtitle "$BACKTITLE" --title "$TITLE" \ + --stdout --radiolist "$msg" 0 0 0 \ + $(image_list)) + + if [ "$?" != "0" ]; then + _yesno "\nInterrupt installation?\n " + if [ "$?" = "0" ]; then + _shutdown + fi + else + if [ -z "$opcao" ]; then + continue + else + image=$(image_file $opcao) + break + fi + fi + done + + # disable kernel messages in the console + echo "1 4 1 7" > /proc/sys/kernel/printk +} + +function install_warning() +{ + if [ -n "${win32_part_dev}" ]; then + warn_msg="Windows installation detected.\nWe will set it up as dual boot. \ +You may lose some data.\nPlease backup before proceeding." + else + warn_msg="WARNING: This process will erase all data in this machine, \ +do you want to continue?" + fi + + clear + _yesno "\n$warn_msg\n" + if [ "$?" != "0" ]; then + _shutdown + fi +} + +function detect_root() +{ + inst_source_dev=$(awk "\$2 == \"$restore_media\" { print \$1 }" /proc/mounts | sed -e 's/[0-9]$//') + inst_source_dev=${inst_source_dev#/dev/} + devices=$(grep "^ .*[^0-9]$" < /proc/partitions | grep -v ${inst_source_dev} | awk '$3 > '$MIN_DISKSIZE' { print $4,$3 }') + + if [ -z "${devices}" ]; then + exit 1 + fi + + devs_found=$(($(echo $devices | wc -w)/2)) + + root_data=$(detect_win32 ${inst_source_dev}) + + if [ -z "${root_data}" ]; then + if [ "$devs_found" -gt "1" ]; then + if [ -n "${inst_source_dev}" ]; then + opcao=$(dialog --backtitle "$BACKTITLE" --title "$TITLE" --stdout --menu 'Choose one of the detected devices to restore to (check the blocks size column first):' 8 50 0 $devices ) + if [ "$?" != "0" ]; then + _yesno "\nInterrupt installation?\n " + if [ "$?" = "0" ]; then + _shutdown + fi + else + root_data=${opcao} + fi + fi + else + root_data=$(echo ${devices} | cut -d ' ' -f 1) + fi + fi + + echo ${root_data} +} + +function detect_win32() +{ + # from detect_root() + skip_dev=${1} + + # win32 detection won't handle complex layouts + if [ $(fdisk -l | grep "^/dev/" | grep -v ${skip_dev} | wc -l) -gt 1 ]; then + exit + fi + + # get the last created windows partition information + set -f + device=$(fdisk -l | grep "^/dev/" | grep -v ${skip_dev} | grep -e "FAT\|NTFS\|HPFS" | tail -1 | sed 's/ .*$//') + set +f + + if [ -z "${device}" ]; then + exit + fi + + # it might be needed, for safety + device_type=$(blkid -o value -s TYPE ${device}) + modprobe ${device_type} + + # df for that partition + mount ${device} /mnt + size=$(df ${device} | tail -1) + umount /mnt + + # its diskspace + used=$(echo ${size} | awk '{ print $3 }') + left=$(echo ${size} | awk '{ print $4 }') + avail=$((${left}/2)) + + if [ ! ${avail} -lt ${MIN_DISKSIZE} ]; then + win32_part_dev=${device} + win32_part_type=${device_type} + # our install takes half of 'left' + win32_part_new_size=$((${used}+${avail})) + + dev=${win32_part_dev#/dev/} + disk=${dev%[0-9]} + number=${dev#[a-w][a-w][a-w]} + let number++ + echo ${disk}${number} ${win32_part_dev} ${win32_part_type} ${win32_part_new_size} + fi +} + +function resize_win32() +{ + device=${1} + device_type=${2} + new_win32_size=${3} + + dialog --backtitle "$BACKTITLE" --title "$TITLE" --infobox "\nResizing Windows partition...\n" 4 55 + + dev=${device#/dev/} + disk=${dev%[0-9]} + win32_number=${dev#[a-w][a-w][a-w]} + + case ${device_type} in + vfat) device_id=b ;; + ntfs) device_id=7 ;; + hpfs) device_id=87 ;; + esac + + # wrapper around libdrakx by blino + diskdrake-resize ${device} ${device_type} $((${new_win32_size}*2)) &>/dev/null + + # we need some free sector here, rebuilding layout + fdisk /dev/${disk} &>/dev/null </dev/null </dev/null; dd bs=4M of=/dev/${root} >/tmp/backup.out 2>&1>>/tmp/log) & + + sleep 3 + pid=$(ps ax | grep 'dd bs=4M of' | grep -v grep | awk '{ print $1 }') + + while [ true ]; do + ps | grep -q $pid + if [ $? -eq 0 ]; then + /bin/kill -SIGUSR1 $pid + complete=$(tail -n 1 /tmp/backup.out | awk '{ print $1 }') + echo $((complete*100/total)) + sleep 1 + else + break + fi + done | dialog --backtitle "$BACKTITLE" --title "$TITLE" --gauge "\nWriting image..." 8 45 + + in=$(tail -n 3 /tmp/backup.out | grep 'in$' | cut -d' ' -f1) + out=$(tail -n 3 /tmp/backup.out | grep 'out$' | cut -d' ' -f1) + + if [ x"$in" != x"$out" ]; then + _msgbox "\nError writing image!\n" + sleep 24h + fi + + # Now re-read the partition table because 'dd' might have changed it + sfdisk -R /dev/${root} +} + +function grub_setup() +{ + root=${1} + grub_dir=${2} + + # install the bootloader + grub <> ${grub_dir}/menu.lst </dev/null| grep "Filesystem OS type" | awk '{ print $4 }') + if [ "${filesystem_type}" = "Linux" ]; then + dialog --backtitle "$BACKTITLE" --title "$TITLE" --infobox "Finishing Install... Expanding ${root}" 3 40 + disk=/dev/${root%[0-9]} + main_part=/dev/${root} + + # FIXME: absurdly dirty hack + main_part_num=${root:3} + swap_part_num=$((main_part_num+1)) + swap_part=${disk}${swap_part_num} + + main_part_sectors= + if [ -n "$SWAP_BLOCKS" ]; then + if [ -n "$EXPAND_FS" ]; then + total_blocks=$(sfdisk -s $disk) + main_part_blocks=$((total_blocks-SWAP_BLOCKS)) + main_part_sectors=$((main_part_blocks*2)) + else + main_part_sectors=$(sfdisk -d $disk | perl -lne 'm|^'$main_part'\b.*,\s*size\s*=\s*(\d+)\b| and print($1), exit') + fi + fi + if [ -n "$SWAP_BLOCKS" ]; then + parted $disk -- mkpartfs primary linux-swap ${main_part_sectors}s -1s yes + mkswap -L swap $swap_part + fi + if [ -n "$EXPAND_FS" ]; then + e2fsck -fy $main_part + fdisk $disk << EOF +d +$main_part_num +n +p +$main_part_num + + +a +$main_part_num +w +EOF + sfdisk -R $disk + e2fsck -fy $main_part + resize2fs $main_part + fi + mkdir -p $mnt_dir + mount $main_part $mnt_dir + grub_dir="$mnt_dir/boot/grub" + if [ -d "$grub_dir" ]; then + echo "(hd0) $disk" > "$grub_dir/device.map" + if [ -n "$win32_part_dev" ]; then + grub_setup ${root} ${grub_dir} + fi + fi + if [ -n "$MKINITRD" ]; then + mount -t sysfs none "$mnt_dir/sys" + mount -t proc none "$mnt_dir/proc" + chroot $mnt_dir bootloader-config --action rebuild-initrds + umount "$mnt_dir/sys" + umount "$mnt_dir/proc" + fi + umount $mnt_dir + fi +} + +# installation steps +welcome +read_config +detect_device +install_warning +write_image +expand_fs + +# all done! +_msgbox "\nInstallation process finished.\nPress ENTER to shutdown.\n " + +_shutdown + diff --git a/rescue/tree/usr/sbin/startssh b/rescue/tree/usr/sbin/startssh new file mode 100755 index 000000000..e14bb10e8 --- /dev/null +++ b/rescue/tree/usr/sbin/startssh @@ -0,0 +1,27 @@ +#!/bin/bash + +# test for an up interface != lo +if test "x"`ifconfig | cut -d ' ' -f 1 | grep -v '^$' | grep -v lo` = "x"; then + echo "There is no up interface, you can try to execute 'drvinst' to find drivers and 'dhcp-client' to configure your interface for DHCP." >&2 + exit 5 +fi + +# generate host keys +mkdir -p /etc/dropbear +[[ -f /etc/dropbear/dropbear_dss_host_key ]] || dropbearkey -t dss -f /etc/dropbear/dropbear_dss_host_key >/dev/null || { echo "Can't generate dsa host key" >&2 ; exit 4; } +[[ -f /etc/dropbear/dropbear_rsa_host_key ]] || dropbearkey -t rsa -f /etc/dropbear/dropbear_rsa_host_key >/dev/null || { echo "Can't generate rsa host key" >&2 ; exit 3; } + +# set a password +passwd=`genpasswd` +if (( $? != 0 )); then + reset + exit $? +fi +sed -E -i -e 's/^root:[^:]*:/root:'"${passwd//\//\\/}"':/' /etc/passwd || { echo "Can't set password" >&2 ; exit 2; } + +# test for /dev/pts +grep '^devpts /dev/pts devpts ' /proc/mounts >/dev/null 2>/dev/null || mount -t devpts devpts /dev/pts + +echo "" +echo -n "Starting ssh daemon... " +dropbear -E 2>/var/log/dropbear.log && echo "OK" || { echo "Failed" ; exit 1; } -- cgit v1.2.1