diff options
author | Antoine Ginies <aginies@mandriva.com> | 2011-01-19 10:44:49 +0000 |
---|---|---|
committer | Antoine Ginies <aginies@mandriva.com> | 2011-01-19 10:44:49 +0000 |
commit | 530a16ec071db0e24e6e949e265a96848864967c (patch) | |
tree | fe40cacd28d67b98186754c551b7fd339ebc7e17 /rescue | |
download | drakx-backup-do-not-use-530a16ec071db0e24e6e949e265a96848864967c.tar drakx-backup-do-not-use-530a16ec071db0e24e6e949e265a96848864967c.tar.gz drakx-backup-do-not-use-530a16ec071db0e24e6e949e265a96848864967c.tar.bz2 drakx-backup-do-not-use-530a16ec071db0e24e6e949e265a96848864967c.tar.xz drakx-backup-do-not-use-530a16ec071db0e24e6e949e265a96848864967c.zip |
add mes5-2.6.33 branch
Diffstat (limited to 'rescue')
45 files changed, 2958 insertions, 0 deletions
diff --git a/rescue/.perl_checker b/rescue/.perl_checker new file mode 100644 index 000000000..8ad989186 --- /dev/null +++ b/rescue/.perl_checker @@ -0,0 +1,39 @@ +bytes +constant +AutoLoader +Carp::Heavy +Compress::Zlib +Config::IniFiles +Convert::ASN1 +Cwd +Date::Manip +Digest::MD5 +Encode +encoding +feature +File::Basename +File::Find +File::FnMatch +File::GlobMapper +File::Path +File::Temp +Gtk2::Gdk::Keysyms +IO::Compress::Gzip +IO::Handle +IO::Socket::SSL +IO::Socket::UNIX +IO::Uncompress::Gunzip +Net::DBus::Binding::Introspector +Net::DBus::Binding::Iterator +Net::DBus::Test::MockIterator +Net::LDAP +Net::LDAP::Constant +Net::LDAP::Control +Net::LDAP::Filter +Net::LDAP::Schema +Net::LDAP::Util +Scalar::Util +String::ShellQuote +Term::ReadKey +Text::ParseWords +Time::ZoneInfo diff --git a/rescue/Flash/scripts/backup_systemloop b/rescue/Flash/scripts/backup_systemloop new file mode 100755 index 000000000..65c3185e6 --- /dev/null +++ b/rescue/Flash/scripts/backup_systemloop @@ -0,0 +1,106 @@ +#!/bin/bash + +# import functions library +source rescue_common + +tmpdir="/tmp/flash-rescue-root" +rootdir="$tmpdir/pen" + +function prepare() { + + mkdir -p $rootdir + + if ! mount_usbroot $rootdir; then + return 1 + fi + + if [ x"$version" = x"1.0" ]; then + mkdir -p $tmpdir/shared + if ! mount_sharedroot $tmpdir/shared; then + return 1 + fi + fi + + if [ ! -d $dir ]; then + mkdir $dir + fi + + return 0 +} + +function doit() { + + clear + echo + echo -n 'Creating backup file. This can take some time: ' + + bzip2 -c $loop > $target 2> /tmp/rescue-backup.err & + + sleep 2 + + while ps | grep -q bzip2; do + progress + done + + sync + + echo + echo + + errsize=$(ls -la /tmp/rescue-backup.err | cut -d' ' -f5) + if [ $errsize -ne 0 ]; then + echo "Error compressing user files into $target" + return 1 + else + echo 'Backup file created!' + fi + + echo + + return 0 +} + +function cleanup() { + + if [ x"$version" = x"1.0" ]; then + umount $tmpdir/shared > /dev/null 2>&1 + rmdir $tmpdir/shared + fi + + umount $rootdir > /dev/null 2>&1 + rmdir $rootdir $tmpdir 2> /dev/null + + return 0 +} + +clear +trap cleanup SIGINT + +version="" +if ! insert_pendrive; then + exit 1 +fi + +if [ x"$version" = x"1.0" ]; then + dir="$tmpdir/shared/backup" + loop="$rootdir/loopbacks/system.loop" +else + dir="$rootdir/backup" + loop="$rootdir/.loopbacks/system.loop" +fi + +file="backup-$(date +%Y%m%d).bz2" +target="$dir/$file" + +if ! prepare; then + cleanup + exit 1 +fi + +if ! doit; then + cleanup + exit 1 +fi + +cleanup +exit 0 diff --git a/rescue/Flash/scripts/clear_systemloop b/rescue/Flash/scripts/clear_systemloop new file mode 100755 index 000000000..6d7015c84 --- /dev/null +++ b/rescue/Flash/scripts/clear_systemloop @@ -0,0 +1,89 @@ +#!/bin/bash + +# import functions library +source rescue_common + +tmpdir="/tmp/flash-rescue-root" +rootdir="$tmpdir/pen" + +function prepare() { + + mkdir -p $rootdir + + if ! mount_usbroot $rootdir; then + return 1 + fi + + return 0 +} + +function doit() { + + clear + echo + echo "WARNING!" + echo + echo "Mandriva Flash will be reseted to factory defaults!" + echo -n "All user files, customizations and new packages installed " + echo "will be removed." + echo + echo "This process may take a few minutes." + echo + echo -n "Do you want to continue? [N/y] " + read confirm + + if [ x"$confirm" = x"y" -o x"$confirm" = x"Y" ]; then + + if [ ! -f $loop ] || [ x"$version" != x"1.0" ]; then + dd if=/dev/zero of=$loop bs=4000000 count=100 + fi + + if [ x"$version" = x"1.0" ]; then + /sbin/mkfs.ext2 -q -F $loop + fi + + echo + if [ $? -ne 0 ]; then + echo 'Error reseting device to factory defaults' + return 1 + else + echo 'Mandriva Flash was restored to factory defaults!' + fi + fi + + echo + + return 0 +} + +function cleanup() { + + umount $rootdir > /dev/null 2>&1 + rmdir $rootdir $tmpdir 2> /dev/null +} + +clear +trap cleanup SIGINT + +version="" +if ! insert_pendrive; then + exit 1 +fi + +if [ x"$version" = x"1.0" ]; then + loop="$rootdir/loopbacks/system.loop" +else + loop="$rootdir/.loopbacks/system.loop" +fi + +if ! prepare; then + cleanup + exit 1 +fi + +if ! doit; then + cleanup + exit 1 +fi + +cleanup diff --git a/rescue/Flash/scripts/rescue_common b/rescue/Flash/scripts/rescue_common new file mode 100644 index 000000000..e1402cacc --- /dev/null +++ b/rescue/Flash/scripts/rescue_common @@ -0,0 +1,194 @@ +#!/bin/bash + +function detect_version() { + version="" + if has_label Share; then + version="1.0" + elif has_label MDVUSBROOT; then + version="1.05" + elif has_label Mdv_Flash; then + version="2.0" + elif has_label MDV_FLASH; then + version="2.05" + fi + usbroot_device=$_device + source_version_variables + + [ -n "$version" ] +} + +function source_version_variables { + local _version + _version=$1 + [ -z "$_version" ] && _version=$version + if [ "$_version" = "1.0" ]; then + label=MDVUSBROOT + boot_rel="/boot" + loopbacks_rel="/loopbacks" + elif [ "$_version" = "1.05" ]; then + label=MDVUSBROOT + boot_rel="/.boot" + loopbacks_rel="/.loopbacks" + elif [ "$_version" = "2.0" ]; then + label=Mdv_Flash + boot_rel="/.boot" + loopbacks_rel="/.loopbacks" + elif [ "$_version" = "2.05" ]; then + label=MDV_FLASH + boot_rel="/.boot" + loopbacks_rel="/.loopbacks" + fi +} + +function has_label() { + local _label _tmpdir + _label=$1 + + _tmpdir="/tmp/$$" + + mkdir -p $_tmpdir + + nash --force > /dev/null 2>&1 <<EOF +mount -t vfat LABEL=$_label $_tmpdir +EOF + + rc=$? + + _device=`perl -ne 'my @l = split; $l[1] eq "'$_tmpdir'" and print "$l[0]\n"' /proc/mounts` + [ -z "$_device" ] && rc=1 + + umount $_tmpdir 2> /dev/null + rmdir $_tmpdir 2> /dev/null + + return $rc +} + +function check_vendor() { + + # list of supported vendors/models + + # mandriva flash 1.0 (france) + vendors[0]="13fe" + models[0]="1a00" + # mandriva flash 1.0 (brazil) + vendors[1]="0930" + models[1]="653e" + # mandriva flash 4GB (france) + vendors[2]="13fe" + models[2]="1d00" + + rc=1 + + mount -t usbfs none /proc/bus/usb 2> /dev/null + + i=0 + while [ ! -z "${vendors[$i]}" ]; do + + grep "P:" /proc/bus/usb/devices | grep -q \ + "Vendor=${vendors[$i]} ProdID=${models[$i]}" + if [ $? -eq 0 ]; then + rc=0 + break + fi + + let i++ + done + + umount /proc/bus/usb 2> /dev/null + + return $rc +} + +function insert_pendrive() { + + _tmpdir="/tmp/rescue-temp" + mkdir -p $_tmpdir + + modprobe usb-storage > /dev/null 2>&1 + modprobe vfat > /dev/null 2>&1 + + echo + echo -n 'Please insert your Mandriva Flash pen drive and press ENTER when ready: ' + read READY + echo + echo -n 'Detecting pen drive: ' + + for ((i=0; $i <= 15 ; i++)); do + detect_version && nash --force > /dev/null 2>&1 <<EOF +mount -t vfat LABEL=$label $_tmpdir +EOF + if [ $? -ne 0 ]; then + echo -n '.' + sleep 1 + else + echo -n ' found!' + + if ! check_vendor; then + echo + echo "This is not an official Mandriva Flash key!" + echo + fi + + cat /proc/mounts | grep $_tmpdir | cut -d' ' -f1 | \ + sed 's/[0-9]*$//g' > /tmp/rescue-device + umount $_tmpdir + rmdir $_tmpdir 2> /dev/null + + return 0 + fi + done + + rmdir $_tmpdir 2> /dev/null + + echo + echo + echo "Couldn't detect Mandriva Flash pen drive!" + echo + + return 1 +} + +function mount_usbroot() { + + nash --force > /dev/null 2>&1 <<EOF +mount -t vfat LABEL=$label $1 +EOF + if [ $? -ne 0 ]; then + echo "Error mounting device labeled $label" + return 1 + fi + + return 0 +} + +function mount_sharedroot() { + + nash --force > /dev/null 2>&1 <<EOF +mount -t vfat LABEL=Share $1 +EOF + if [ $? -ne 0 ]; then + echo "Error mounting device labeled Share" + return 1 + fi + + return 0 +} + +function progress() { + + echo -ne '\b|' + usleep 100000 + echo -ne '\b/' + usleep 100000 + echo -ne '\b-' + usleep 100000 + echo -ne '\b\\' + usleep 100000 +} + +function lumount() { + local dir=$1 + loop=$(perl -ne '@l = split; if ($l[1] eq "'$dir'") { print $l[0]; exit }' /proc/mounts) + umount $dir + losetup -d $loop +} diff --git a/rescue/Flash/scripts/reset_rootpass b/rescue/Flash/scripts/reset_rootpass new file mode 100755 index 000000000..63b4e8b3a --- /dev/null +++ b/rescue/Flash/scripts/reset_rootpass @@ -0,0 +1,100 @@ +#!/bin/bash + +# import functions library +source rescue_common + +tmpdir="/tmp/flash-rescue-root" +rootdir="$tmpdir/pen" + +function prepare() { + + modprobe unionfs > /dev/null 2>&1 + modprobe squashfs > /dev/null 2>&1 + modprobe loop > /dev/null 2>&1 + + mkdir -p $rootdir + mkdir -p $tmpdir/squash + mkdir -p $tmpdir/user + mkdir -p $tmpdir/union + + if ! mount_usbroot $rootdir; then + return 1 + fi + + mount -t squashfs -o loop $sfs_loop $tmpdir/squash > /dev/null 2>&1 + if [ $? -ne 0 ]; then + echo "Error mounting distrib.sqfs" + return 1 + fi + + mount -t ext2 -o loop $sys_loop $tmpdir/user > /dev/null 2>&1 + if [ $? -ne 0 ]; then + echo "Error mounting system.loop" + return 1 + fi + + mount -t unionfs -o dirs=$tmpdir/user=rw:$tmpdir/squash=ro \ + none $tmpdir/union + if [ $? -ne 0 ]; then + echo "Error creating union of distrib.sqfs and system.loop" + return 1 + fi + + chroot $tmpdir/union /etc/init.d/keytable start &> /dev/null + chroot $tmpdir/union /usr/bin/unicode_start + + return 0 +} + +function doit() { + + clear + echo + chroot $tmpdir/union passwd root + echo + echo + + return 0 +} + +function cleanup() { + + chroot $tmpdir/union /usr/bin/unicode_stop + + umount $tmpdir/union > /dev/null 2>&1 + lumount $tmpdir/user > /dev/null 2>&1 + lumount $tmpdir/squash > /dev/null 2>&1 + umount $rootdir > /dev/null 2>&1 + + rmdir $tmpdir/union $tmpdir/user $tmpdir/squash 2> /dev/null + rmdir $rootdir $tmpdir 2> /dev/null +} + +clear +trap cleanup SIGINT + +version="" +if ! insert_pendrive; then + exit 1 +fi + +if [ x"$version" = x"1.0" ]; then + sys_loop="$rootdir/loopbacks/system.loop" + sfs_loop="$rootdir/loopbacks/distrib.sqfs" +else + sys_loop="$rootdir/.loopbacks/system.loop" + sfs_loop="$rootdir/.loopbacks/distrib.sqfs" +fi + +if ! prepare; then + cleanup + exit 1 +fi + +if ! doit; then + cleanup + exit 1 +fi + +cleanup +exit 0 diff --git a/rescue/Flash/scripts/reset_userpass b/rescue/Flash/scripts/reset_userpass new file mode 100755 index 000000000..320457cdc --- /dev/null +++ b/rescue/Flash/scripts/reset_userpass @@ -0,0 +1,111 @@ +#!/bin/bash + +# import functions library +source rescue_common + +tmpdir="/tmp/flash-rescue-root" +rootdir="$tmpdir/pen" + +function prepare() { + + modprobe unionfs > /dev/null 2>&1 + modprobe squashfs > /dev/null 2>&1 + modprobe loop > /dev/null 2>&1 + + mkdir -p $rootdir + mkdir -p $tmpdir/squash + mkdir -p $tmpdir/user + mkdir -p $tmpdir/union + + if ! mount_usbroot $rootdir; then + return 1 + fi + + mount -t squashfs -o loop $sfs_loop $tmpdir/squash > /dev/null 2>&1 + if [ $? -ne 0 ]; then + echo "Error mounting distrib.sqfs" + return 1 + fi + + mount -t ext2 -o loop $sys_loop $tmpdir/user > /dev/null 2>&1 + if [ $? -ne 0 ]; then + echo "Error mounting system.loop" + return 1 + fi + + mount -t unionfs -o dirs=$tmpdir/user=rw:$tmpdir/squash=ro \ + none $tmpdir/union > /dev/null 2>&1 + if [ $? -ne 0 ]; then + echo "Error creating union of distrib.sqfs and system.loop" + return 1 + fi + + chroot $tmpdir/union /etc/init.d/keytable start &> /dev/null + chroot $tmpdir/union /usr/bin/unicode_start + + return 0 +} + +function doit() { + + username=$(tail -1 $tmpdir/union/etc/passwd | cut -d ':' -f1) + + clear + echo + echo -n "What is your username? [$username] " + read name + + if [ -z "$name" ]; then + name="$username" + fi + + echo + echo + chroot $tmpdir/union passwd $name + echo + echo + + return 0 +} + +function cleanup() { + + chroot $tmpdir/union /usr/bin/unicode_stop + + umount $tmpdir/union > /dev/null 2>&1 + lumount $tmpdir/user > /dev/null 2>&1 + lumount $tmpdir/squash > /dev/null 2>&1 + umount $rootdir > /dev/null 2>&1 + + rmdir $tmpdir/union $tmpdir/user $tmpdir/squash 2> /dev/null + rmdir $rootdir $tmpdir 2> /dev/null +} + +clear +trap cleanup SIGINT + +version="" +if ! insert_pendrive; then + exit 1 +fi + +if [ x"$version" = x"1.0" ]; then + sys_loop="$rootdir/loopbacks/system.loop" + sfs_loop="$rootdir/loopbacks/distrib.sqfs" +else + sys_loop="$rootdir/.loopbacks/system.loop" + sfs_loop="$rootdir/.loopbacks/distrib.sqfs" +fi + +if ! prepare; then + cleanup + exit 1 +fi + +if ! doit; then + cleanup + exit 1 +fi + +cleanup +exit 0 diff --git a/rescue/Flash/scripts/restore_systemloop b/rescue/Flash/scripts/restore_systemloop new file mode 100755 index 000000000..39c56e030 --- /dev/null +++ b/rescue/Flash/scripts/restore_systemloop @@ -0,0 +1,167 @@ +#!/bin/bash + +# import functions library +source rescue_common + +tmpdir="/tmp/flash-rescue-root" +rootdir="$tmpdir/pen" + +function prepare() { + + mkdir -p $rootdir + + if ! mount_usbroot $rootdir; then + return 1 + fi + + if [ x"$version" = x"1.0" ]; then + mkdir -p $tmpdir/shared + if ! mount_sharedroot $tmpdir/shared; then + return 1 + fi + fi + + return 0 +} + +function doit() { + + if [ ! -d $dir ]; then + echo + echo "Can't find a backup directory in the Share partition" + echo + return 0 + fi + + cd $dir + i=1 + for file in $(ls -c1 backup-*.bz2 2> /dev/null | sort -r | head -10); do + files[$i]="$file" + let i++ + done + cd - > /dev/null + + if [ $i -eq 1 ]; then + echo + echo 'No backup files found!' + echo + return 0 + fi + + while [ true ]; do + + clear + echo + echo "The following backup files were found:" + echo + + i=1 + while [ -n "${files[$i]}" ]; do + echo "[$i] ${files[$i]}" + let i++ + done + let i-- + echo + echo '[0] Cancel / Return to main menu' + + echo + echo 'Select from the list above, the file that you want to restore.' + echo 'The most recent files come first in the list.' + echo + echo -n "What backup file do you want to restore? [1] " + read option + + if [ -z "$option" ]; then + option=1 + fi + if [ x"$option" = x"0" ]; then + return 0 + fi + + if [ ! -f $dir/${files[$option]} ]; then + echo + echo "Error reading backup file ${files[$option]}!" + echo + echo -n 'Do you want to restore another backup file? [N/y] ' + read confirm + + if [ x"$confirm" = x"y" -o x"$confirm" = x"Y" ]; then + continue + else + return 0 + fi + else + + echo + echo -n 'Restoring backup file. This can take some time: ' + + bunzip2 -c $dir/${files[$option]} > $loop \ + 2> /tmp/rescue-backup.err & + + sleep 2 + + while ps | grep -q bunzip2; do + progress + done + + sync + echo + echo + + errsize=$(ls -la /tmp/rescue-backup.err | cut -d' ' -f5) + if [ $errsize -ne 0 ]; then + echo 'Error restoring user files!' + echo + return 1 + else + echo 'Backup file restored!' + echo + break + fi + fi + done + + return 0 +} + +function cleanup() { + + if [ x"$version" = x"1.0" ]; then + umount $tmpdir/shared > /dev/null 2>&1 + rmdir $tmpdir/shared 2> /dev/null + fi + + umount $rootdir > /dev/null 2>&1 + rmdir $rootdir $tmpdir 2> /dev/null + + return 0 +} + +clear +trap cleanup SIGINT + +version="" +if ! insert_pendrive; then + exit 1 +fi + +if [ x"$version" = x"1.0" ]; then + dir="$tmpdir/shared/backup" + loop="$rootdir/loopbacks/system.loop" +else + dir="$rootdir/backup" + loop="$rootdir/.loopbacks/system.loop" +fi + +if ! prepare; then + cleanup + exit 1 +fi + +if ! doit; then + cleanup + exit 1 +fi + +cleanup +exit 0 diff --git a/rescue/Flash/scripts/test_badblocks b/rescue/Flash/scripts/test_badblocks new file mode 100755 index 000000000..3fb1f34d8 --- /dev/null +++ b/rescue/Flash/scripts/test_badblocks @@ -0,0 +1,69 @@ +#!/bin/bash + +# import functions library +source rescue_common + +tmpdir="/tmp/flash-rescue-root" +rootdir="$tmpdir/pen" + +function prepare() { + + return 0 +} + +function doit() { + + clear + echo + echo "WARNING!" + echo + echo "Searching for bad blocks in Mandriva Flash is a slow process." + echo + echo -n "Do you want to continue? [N/y] " + read confirm + + echo + echo + + device=$(cat /tmp/rescue-device) + + if [ x"$confirm" = x"y" -o x"$confirm" = x"Y" ]; then + + /sbin/badblocks -n -v -s ${device}1 + if [ x"$version" = x"1.0" ]; then + /sbin/badblocks -n -v -s ${device}2 + fi + fi + + echo + echo 'Bad blocks scan completed!' + echo + + return 0 +} + +function cleanup() { + + umount $rootdir > /dev/null 2>&1 + rmdir $rootdir $tmpdir 2> /dev/null +} + +clear +trap cleanup SIGINT + +version="" +if ! insert_pendrive; then + exit 1 +fi + +if ! prepare; then + cleanup + exit 1 +fi + +if ! doit; then + cleanup + exit 1 +fi + +cleanup diff --git a/rescue/Flash/scripts/upgrade b/rescue/Flash/scripts/upgrade new file mode 100755 index 000000000..9d5dba227 --- /dev/null +++ b/rescue/Flash/scripts/upgrade @@ -0,0 +1,250 @@ +#!/bin/bash + +# import functions library +source rescue_common + +tmpdir="/tmp/flash-rescue-root" +rootdir="$tmpdir/pen" + +media_dir="/tmp/media" +upgrade_dir="$media_dir/upgrade" + + +config_files_network_scripts="etc/sysconfig/network-scripts/ifcfg-* \ + etc/sysconfig/network-scripts/cellular.d \ + etc/sysconfig/network-scripts/vpn.d \ + etc/sysconfig/network-scripts/wireless.d" + +config_files_users="etc/passwd etc/shadow etc/group etc/gshadow" +config_files_time="etc/localtime etc/ntp etc/ntp.conf" +config_files="etc/sysconfig/* $config_files_users $config_files_time \ + etc/wpa_supplicant.conf etc/shorewall etc/kde \ + etc/udev/rules.d/61-*_config.rules" + +config_files_to_remove="etc/sysconfig/harddrake2" + +function prepare() { + + echo "Mounting Mandriva Flash key..." + echo + + modprobe unionfs > /dev/null 2>&1 + modprobe squashfs > /dev/null 2>&1 + modprobe loop > /dev/null 2>&1 + + mkdir -p $rootdir + mkdir -p $tmpdir/squash + mkdir -p $tmpdir/user + mkdir -p $tmpdir/union + + if ! mount_usbroot $rootdir; then + return 1 + fi + + mount -t ext2 -o loop $sys_loop $tmpdir/user > /dev/null 2>&1 + if [ $? -ne 0 ]; then + echo "Error mounting system.loop" + return 1 + fi + + return 0 +} + +function get_existing_rpms() { + + echo "Getting list of installed packages..." + echo + + mount -t squashfs -o loop $sfs_loop $tmpdir/squash > /dev/null 2>&1 + if [ $? -ne 0 ]; then + echo "Error mounting distrib.sqfs" + return 1 + fi + + mount -t unionfs -o dirs=$tmpdir/user=rw:$tmpdir/squash=ro \ + none $tmpdir/union + if [ $? -ne 0 ]; then + echo "Error creating union of distrib.sqfs and system.loop" + return 1 + fi + + chroot $tmpdir/squash rpm -qa | sort > /tmp/previous_rpms.list + if [ $? -ne 0 ]; then + echo "Error getting list of vanilla rpms installed on previous key" + fi + + chroot $tmpdir/union rpm -qa | sort > /tmp/existing_rpms.list + if [ $? -ne 0 ]; then + echo "Error getting list of rpms installed prior to upgrade" + fi + + umount $tmpdir/union > /dev/null 2>&1 + lumount $tmpdir/squash > /dev/null 2>&1 + + mkdir -p $tmpdir/user/root + diff /tmp/previous_rpms.list /tmp/existing_rpms.list | sed -n 's/^> //p' > $tmpdir/user/root/new_existing_rpms.list + + return 0 +} + +function move_files() { + for i in $*; do + if [ -e $i ]; then + dir=`dirname $i` + [ "$dir" = "." ] || mkdir -p ..keep/$dir + mv $i ..keep/$dir || { echo "Error moving $i"; return 1; } + fi + done + + return 0 +} + +function remove_non_user_nor_config_files() { + + echo "Filtering system configuration files and user accounts..." + echo + + cd $tmpdir/user + + rm -rf $config_files_to_remove + + if [ -e ..keep ]; then + mv ..keep ..keep.bak + fi + if [ -e ..keep ]; then + echo "remove_non_user_nor_config_files can't work with existing temp dir" + return 1 + fi + + mkdir ..keep + + move_files $config_files_network_scripts || return 1 + rm -rf etc/sysconfig/network-scripts + + move_files home root $config_files || return 1 + rm -rf * + rm -rf .[^.]* + + mv ..keep/* . + rmdir ..keep + + cd - > /dev/null + + return 0 +} + +function copy_new_version() { + + echo "Copying new Mandriva Flash system..." + + rm -rf $rootdir$boot_rel + rm -f $rootdir$loopbacks_rel/.*sqf + rm -f $rootdir$loopbacks_rel/.*sqfs + [ -d "$modules_dir" ] && rm -rf $modules_dir + + tar c -C $upgrade_dir . | pv -s `du -sb $upgrade_dir | cut -f 1` | tar x -C $rootdir + echo + + chmod -R u+w $rootdir + chmod -R u-w $rootdir$boot_rel $rootdir$loopbacks_rel + + new_label=$(source_version_variables "2.0"; echo $label) + MTOOLS_SKIP_CHECK=1 mlabel -i $usbroot_device ::$new_label + + return 0 +} + +function merge_config_files() { + + echo "Merging user and group accounts in new system..." + echo + + mount -t squashfs -o loop $sfs_loop $tmpdir/squash > /dev/null 2>&1 + if [ $? -ne 0 ]; then + echo "Error mounting distrib.sqfs" + return 1 + fi + + upgrade.merge-users $tmpdir/user/etc $tmpdir/squash/etc + + mount -t unionfs -o dirs=$tmpdir/user=rw:$tmpdir/squash=ro \ + none $tmpdir/union + if [ $? -ne 0 ]; then + echo "Error creating union of distrib.sqfs and system.loop" + return 1 + fi + + #- reapply lang configuration, mostly to rewrite kdeglobals + chroot $tmpdir/union perl -I/usr/lib/libDrakX -Mlang -e "lang::write(lang::read())" &>/dev/null + + #- remove KDE sessions file so that previous compiz usage does not break session + rm -f $tmpdir/union/home/*/.kde/share/config/ksmserverrc &>/dev/null + + #- remove KDE autostart files that should have been migrated by startkde... + rm -f $tmpdir/union/home/*/.kde/Autostart/{alignment-icons,openkmenu}.desktop &>/dev/null + + return 0 +} + +function doit() { + + if [ -d $tmpdir/user/var/lib/rpm/Packages ]; then + get_existing_rpms || return 1 + fi + + remove_non_user_nor_config_files || return 1 + + copy_new_version || return 1 + + merge_config_files || return 1 + + return 0 +} + +function cleanup() { + cd / + + umount $tmpdir/union > /dev/null 2>&1 + lumount $tmpdir/user > /dev/null 2>&1 + lumount $tmpdir/squash > /dev/null 2>&1 + umount $rootdir > /dev/null 2>&1 + + rmdir $tmpdir/union $tmpdir/user $tmpdir/squash 2> /dev/null + rmdir $rootdir $tmpdir 2> /dev/null +} + +clear +trap cleanup SIGINT + +version="" +if ! insert_pendrive; then + exit 1 +fi + +#- works only when upgrading versions with the same layout +sys_loop="$rootdir$loopbacks_rel/system.loop" +sfs_loop="$rootdir$loopbacks_rel/distrib.sqfs" + +modules_dir="$rootdir$loopbacks_rel/modules" + +echo + +if ! prepare; then + cleanup + exit 1 +fi + +if ! doit; then + cleanup + exit 1 +fi + +echo "Please wait, finishing copy to key..." +echo + +cleanup + +echo "Congratulations! Your Mandriva Flash system is now upgraded." +echo + +exit 0 diff --git a/rescue/Flash/scripts/upgrade.merge-users b/rescue/Flash/scripts/upgrade.merge-users new file mode 100755 index 000000000..297960e91 --- /dev/null +++ b/rescue/Flash/scripts/upgrade.merge-users @@ -0,0 +1,52 @@ +#!/usr/bin/perl + +use MDK::Common; + +@ARGV == 2 or die "merge_users <existing files dir> <new files dir>\n"; + +my ($existing_dir, $new_dir) = @ARGV; + +merge('passwd', 'shadow'); +merge('group', 'gshadow'); + +sub merge { + my ($main, $shadow) = @_; + + my @new = cat_("$new_dir/$main"); + my %new_ids = map { (split ':')[2] => $_ } @new; + + my %names_to_have; + foreach (cat_("$existing_dir/$main")) { + my @l = split ':'; + next if $l[0] eq 'nobody' || $l[2] < 500; + if (my $e = $new_ids{$l[2]}) { + $_ eq $e or warn "ERROR: conflicting entries:\n $_ $e"; + } else { + push @new, $_; + $names_to_have{$l[0]} = 1; + } + } + + my @new_shadow = grep { !/^root:/ } cat_("$new_dir/$shadow"); + foreach (cat_("$existing_dir/$shadow")) { + my ($name) = split ':'; + if ($name eq 'root') { + unshift @new_shadow, $_; + } elsif ($names_to_have{$name}) { + push @new_shadow, $_; + } + } + + if (rename "$existing_dir/$main", "$existing_dir/$main.old") { + output("$existing_dir/$main", @new); + } else { + warn "rename $existing_dir/$main failed: $?\n"; + <STDIN>; + } + if (rename "$existing_dir/$shadow", "$existing_dir/$shadow.old") { + output("$existing_dir/$shadow", @new_shadow); + } else { + warn "rename $existing_dir/$shadow failed: $?\n"; + <STDIN>; + } +} diff --git a/rescue/Makefile b/rescue/Makefile new file mode 100644 index 000000000..41884b620 --- /dev/null +++ b/rescue/Makefile @@ -0,0 +1,26 @@ +include ../Makefile.config + +VERSION=1.11 +PRODUCT=drakx-installer-rescue + +RESCUE = rescue.sqfs + +all: $(RESCUE) + +install: $(RESCUE) + cp -f $< $(STAGE2_DEST) + +$(RESCUE): list.xml drvinst guessmounts lsparts rescue-doc make_rescue_img + DISTRIB_DESCR=$(DISTRIB_DESCR) ./make_rescue_img + +tar: + rm -rf $(PRODUCT)*.tar* $(PRODUCT)-$(VERSION) + mkdir -p $(PRODUCT)-$(VERSION)/tools + svn export -q -rBASE . $(PRODUCT)-$(VERSION)/rescue + cp ../Makefile.config $(PRODUCT)-$(VERSION)/ + cp ../tools/install-xml-file-list $(PRODUCT)-$(VERSION)/tools + tar cfj $(PRODUCT)-$(VERSION).tar.bz2 $(PRODUCT)-$(VERSION) + rm -rf $(PRODUCT)-$(VERSION) + +clean: + rm -f $(RESCUE) kernel_read_part diff --git a/rescue/NEWS b/rescue/NEWS new file mode 100644 index 000000000..c1fa20082 --- /dev/null +++ b/rescue/NEWS @@ -0,0 +1,43 @@ +Version 1.11 - 25 September 2008, by Olivier "blino" Blin + +- add image restoration scripts ("restore" command line parameter) + +Version 1.10 - 25 April 2008, by Olivier "blino" Blin + +- fix "Mounting other partitions from fstab" which use UUID=xxx +- fix build with latest file package, which only includes the + precompiled magic file + +Version 1.9 - 10 March 2008, by Olivier "blino" Blin + +- handle ntfs-3g in fstab +- add missing modalias files (#38690) + +Version 1.8 - 28 February 2008, by Olivier "blino" Blin + +- support new modules location (#38207) +- adapt to perl 5.10 +- fix build (fix a workaround in partimage_whole_disk) + +Version 1.7 - 25 September 2007, by Pascal "Pixel" Rigaux + +- add mount.nfs binary (since mount doesn't handle nfs fs anymore) + +Version 1.6 - 8 August 2007, by Pascal "Pixel" Rigaux + +- adapt to new libldetect together with drakx-installer-images 1.13 +- loadkeys file: + o handle new "kbd" rpm which have .map files instead of .kmap + o don't skip fr_CH-latin1 + o handle "fr_CH"-like short names +- remove rescuept (use testdisk instead, which is much nicer) + +Version 1.5 - 9 July 2007, by Pascal "Pixel" Rigaux + +- add /etc/mke2fs.conf in order to format ext3fs with 4k blocks (#27377) +- add "mkfs.ext3" which is no more equivalent to "mkfs.ext2 -J" + (eg: dir_index & resize_inode features) + +Version 1.4 - 4 April 2007, by Pascal "Pixel" Rigaux + +- zcat and gunzip can't be symlinks anymore, they are scripts diff --git a/rescue/aliases b/rescue/aliases new file mode 100644 index 000000000..59c96a124 --- /dev/null +++ b/rescue/aliases @@ -0,0 +1,2 @@ +/bin/vi vim-minimal +/lib/modules /modules diff --git a/rescue/devices.pl b/rescue/devices.pl new file mode 100644 index 000000000..0d4a8f77f --- /dev/null +++ b/rescue/devices.pl @@ -0,0 +1,55 @@ +#!/usr/bin/perl + +@ARGV == 1 && chdir $ARGV[0] or die "usage: devices.pl <dir>\n"; + +foreach (<DATA>) { + chomp; + my ($typ, $maj, $min, @l) = split; + foreach (@l) { + my @l2 = do { + if (my ($prefix, $ini, $end) = /(.*)(\d+)-(\d+)$/) { + map { "$prefix$_" } $ini .. $end; + } else { + $_; + } + }; + foreach (@l2) { + my $cmd = "mknod-m600 $_ $typ $maj " . $min++; + system($cmd) == 0 or die "$cmd failed\n"; + } + } +} + +__DATA__ +c 5 1 console +b 2 0 fd0-1 +c 1 2 kmem +b 7 0 loop0-15 +c 1 1 mem +c 1 3 null +c 1 4 port +b 1 1 ram +b 1 0 ram0-19 +b 1 0 ramdisk +c 1 8 random +b 11 0 scd0-7 +c 0 0 stderr +c 0 0 stdin +c 0 0 stdout +c 5 0 tty +c 4 0 tty0-9 +c 4 64 ttyS0-3 +c 1 9 urandom +c 1 5 zero +b 3 0 hda hda1-16 +b 3 64 hdb hdb1-16 +b 22 0 hdc hdc1-16 +b 22 64 hdd hdd1-16 +b 33 0 hde hde1-16 +b 33 64 hdf hdf1-16 +b 34 0 hdg hdg1-16 +b 34 64 hdh hdh1-16 +b 8 0 sda sda1-15 sdb sdb1-15 sdc sdc1-15 sdd sdd1-15 sde sde1-15 sdf sdf1-15 sdg sdg1-15 sdh sdh1-15 +b 9 0 md0-15 +c 10 144 nvram +c 9 0 st0-15 diff --git a/rescue/dirs b/rescue/dirs new file mode 100644 index 000000000..e6d5a5d47 --- /dev/null +++ b/rescue/dirs @@ -0,0 +1,6 @@ +/lib +/tmp +/modules +/proc +/dev +/dev/pts diff --git a/rescue/drvinst b/rescue/drvinst new file mode 100755 index 000000000..cc7fb4fa2 --- /dev/null +++ b/rescue/drvinst @@ -0,0 +1,47 @@ +#!/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_raw { + my ($driver, $o_descr) = @_; + print STDERR "Installing driver $driver", $o_descr ? " (for \"$o_descr\")" : '', "\n"; + system("/sbin/modprobe", $driver) and print "\tfailed\n"; +} + +my $already_usb; +sub install_module { + my ($driver, $descr) = @_; + install_module_raw($driver, $descr); + if (!$already_usb && $driver =~ /usb/) { + $already_usb = 1; + install_module_raw('usbkbd'); + install_module_raw('keybdev'); + } +} + +#- start +foreach my $card (detect_devices::pci_probe()) { + $card->{driver} eq 'unknown' || $card->{driver} =~ /:/ and next; + $card->{media_type} eq "DISPLAY_VGA" and next; + + if (!@ARGV || find { $card->{media_type} =~ /$_/i } @types) { + install_module($card->{driver}, $card->{description}); + } +} diff --git a/rescue/guessmounts b/rescue/guessmounts new file mode 100755 index 000000000..c755e0743 --- /dev/null +++ b/rescue/guessmounts @@ -0,0 +1,97 @@ +#!/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 fs; +use fs::proc_partitions; +use fs::type; + + +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); + +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_once(@$raid_parts); + my $raids = raid::get_existing(@$raid_parts); + push @$normal_parts, @$raids; +} + +my @fstab; +my $root; + +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)) { + print STDERR "=> found a Mandriva Linux root partition on $dev\n=> type $fs, version `", + chomp_(cat_("$target$release_file")), "'\n"; + @fstab = fs::read_fstab($target, '/etc/fstab'); + $root = $dev; + last; + } else { + system('umount', $target) == 0 or die "error unmounting $target\n"; + } +} + +if ($root) { + 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("cp -f /etc/mtab $target/etc/mtab"); #- to allow a nice chrooted "mount" or "df" + } + 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 new file mode 100755 index 000000000..e8bc04ad8 --- /dev/null +++ b/rescue/install_bootloader @@ -0,0 +1,69 @@ +#!/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; + +if ($ARGV[0] eq '--auto') { + $auto = shift @ARGV; +} + +$::prefix = '/mnt'; + +my $release = common::mandrake_release($::prefix) || + do { + system('guessmounts') == 0 or die 'guessmounts failed'; + common::mandrake_release($::prefix); + }; + +if ($release) { + $release =~ /Mandrake|Mandriva/ or die "release file doesn't contain 'Mandriva', 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 Mandriva Linux distribution:\n\t", + $release, "\n"; +if (!$auto) { + print "=> ok? <press Enter to continue, 'n' and Enter to cancel> "; + <STDIN> =~ /^n/i and exit 0; +} + +$install->(); diff --git a/rescue/list.xml b/rescue/list.xml new file mode 100644 index 000000000..6c035915f --- /dev/null +++ b/rescue/list.xml @@ -0,0 +1,337 @@ +<list no-arch-libraries="on"> + +<from expand="binary"> + bash sh + + false true + pwd reset + + ls + cp ln mkdir mknod mv rm rmdir + chmod chown + dd touch + + cat less + tail head tee + sort split cut + grep + + cmp diff + find + file md5sum + + gzip zcat gunzip + bzip2 bunzip2 bzcat + + df du + + <mode copy="dereference"> + vol_id <!-- needed by libDrakX --> + </mode> + + packdrake parsehdlist + cpio ftp tar + rsync + ssh scp + telnet + host + + date + dmesg + chroot + sleep + sync + + eject + mount mount.nfs umount + + ldconfig + mingetty init + reboot halt shutdown + kill killall5 ps strace + sed tr + + loadkeys tset stty + + ping hostname ifconfig route + + fdformat badblocks + e2fsck fsck.ext2 fsck.ext3 mke2fs mkfs.ext2 mkfs.ext3 resize2fs + mkfs.ext3 mkfs.reiserfs mkfs.xfs mkfs.jfs + debugfs dumpe2fs tune2fs + fsck.xfs xfs_repair + resize_reiserfs reiserfsck + mkswap swapoff swapon + <if ARCH="i.86|x86_64"> + fsck.jfs + strings + </if> + <if ARCH="i.86|x86_64|ia64"> + ntfsresize + mkdosfs + </if> + <if ARCH="ppc"> + hformat + </if> + + <if-not ARCH="ppc"> + fdisk gpart + testdisk + </if-not> + <if-not ARCH="ppc|sparc"> + sfdisk + </if-not> + + <if ARCH="ppc"> + pdisk + </if> + dump dump.ext2 restore restore.ext2 dump.ext3 restore.ext3 dump.xfs restore.xfs + parted partimage + + mdadm lvm2 + <if ARCH="i.86|x86_64|ia64"> + dmraid + </if> + + lsmod + insmod + rmmod + + setserial + mt stinit + + lspci lspcidrake + + rpm + rpm2cpio rpmdb + rpme rpmi rpmu rpmquery rpmverify + + vim-minimal hexedit + + perl + uniq + wget + + awk clear dialog wc + setterm + + <if ARCH="i.86|x86_64|ia64"> + dmidecode + </if> + + <if ARCH="i.86|x86_64"> + grub grub-install + </if> + <if ARCH="ia64"> + efibootmgr + </if> + <if ARCH="ppc"> + ybin + mkofboot ofpath + nvsetenv + </if> + <if ARCH="sparc"> + silo + </if> +</from> + +<from> + /usr/lib/kbd/keymaps/include + <if ARCH="i.86|x86_64"> + /usr/lib/kbd/keymaps/i386/include + /usr/lib/kbd/keymaps/i386/azerty/be-latin1.map.gz <!-- this one is needed by be2-latin1 --> + </if> + /usr/share/misc/file/magic.mgc + /usr/share/terminfo/l/linux + /usr/share/pci.ids + /var/run/utmp + + <if ARCH="i.86|x86_64"> + <from dir="/lib/grub/ARCH-mandriva" expand="glob"> + stage1 + stage2 + *_stage1_5 + </from> + /usr/lib/extipl/aldebaran.bin + </if> + + <if ARCH="ppc"> + /usr/lib/yaboot/ofboot + /usr/lib/yaboot/yaboot + </if> + + <from expand="command"> + perl -Mkeyboard -I/usr/lib/libDrakX -le 'print foreach keyboard::loadkeys_files()' + </from> + + <if set="LANGUAGE_fr_FR"> + /usr/lib/gconv/gconv-modules + /usr/lib/gconv/ISO8859-15.so + /usr/share/locale/ISO-8859-15 + /usr/share/locale/fr_FR + /usr/share/locale/fr/LC_MESSAGES/partimage.mo + </if> + <if set="LANGUAGE_pt_BR"> + /usr/lib/gconv/gconv-modules + /usr/lib/gconv/ISO8859-15.so + /usr/share/locale/ISO-8859-15 + /usr/share/locale/pt_BR + /usr/share/locale/pt/LC_MESSAGES/partimage.mo + </if> + +</from> + +<from dir="/usr/lib/rpm" expand="glob"> + <mode copy="keep-links"> + rpmrc + macros + rpmpopt-* + rpmd rpme rpmi rpmu rpmq rpmv + </mode> +</from> + +<filter subst="/^__END__/ and $_ = '', close ARGV"> +<from expand="main-perl"> + AutoLoader.pm + strict.pm + vars.pm + warnings/register.pm + warnings.pm + Carp.pm + Exporter.pm + File/Path.pm + File/Basename.pm + ARCH-linux-thread-multi/re.pm + ARCH-linux-thread-multi/Cwd.pm + ARCH-linux-thread-multi/auto/Cwd/Cwd.so + ARCH-linux-thread-multi/CORE/libperl.so + ARCH-linux-thread-multi/auto/POSIX/autosplit.ix + ARCH-linux-thread-multi/auto/POSIX/load_imports.al + ARCH-linux-thread-multi/auto/POSIX/POSIX.so + ARCH-linux-thread-multi/POSIX.pm + ARCH-linux-thread-multi/XSLoader.pm + ARCH-linux-thread-multi/lib.pm + ARCH-linux-thread-multi/Socket.pm + ARCH-linux-thread-multi/IO/Socket.pm + ARCH-linux-thread-multi/IO.pm + ARCH-linux-thread-multi/IO/Handle.pm + ARCH-linux-thread-multi/Encode/Symbol.pm + Symbol.pm + SelectSaver.pm + ARCH-linux-thread-multi/auto/DynaLoader/dl_findfile.al + ARCH-linux-thread-multi/DynaLoader.pm + ARCH-linux-thread-multi/auto/IO/IO.so + ARCH-linux-thread-multi/auto/Socket/Socket.so + ARCH-linux-thread-multi/Errno.pm + ARCH-linux-thread-multi/IO/Socket/INET.pm + ARCH-linux-thread-multi/IO/Socket/UNIX.pm +</from> +<from expand="perl"> + packdrake.pm + MDV/Packdrakeng.pm +</from> +</filter> + +<from dir="/etc"> + mke2fs.conf + inputrc + termcap + protocols + services + ssh/ssh_config +</from> + +<filter command="strip"> +<from dir="/LIB"> + libnss_files.so.2 + libnss_dns.so.2 + libresolv.so.2 + ld-linux*.so.2 +</from> +</filter> + +<from dir="/usr/share/ldetect-lst" expand="glob"> + *table.gz + dkms-modules.alias fallback-modules.alias +</from> + +<from dir="/lib/module-init-tools"> + ldetect-lst-modules.alias +</from> + +<filter command="../tools/simplify-drakx-modules"> + <from dir="." expand="collect-perl-files /usr/lib/libDrakX /usr/lib/libDrakX"> + <to dir="/usr/bin"> + rescue-doc drvinst lsparts + guessmounts install_bootloader + <if ARCH="i.86|x86_64"> + restore_ms_boot + </if> + </to> + <to dir="/usr/sbin"> + partimage_whole_disk + </to> + </from> + <from dir="/usr/lib/libDrakX" expand="glob"> + raid.pm <!-- required when needed in guessmounts --> + fs/dmraid.pm <!-- required by fsedit --> + partition_table/*.pm <!-- required by partimage_whole_disk --> + </from> +</filter> + +<from dir="/usr/LIB/drakx-installer-binaries"> + <to dir="/usr/bin"> + rescue-gui + </to> + <to dir="/usr/sbin"> + dhcp-client + </to> +</from> +<from dir="/usr/bin"> + <to dir="/ka"> + bootable_flag.sh + fdisk_to_desc + gen_modprobe_conf.pl + ka-d-client + ka-d-server + ka-d.sh + ka_replication.sh + make_initrd_grub + make_initrd_lilo + prepare_node.sh + send_status.pl + status_node.pl + store_log.sh + </to> +</from> +<from dir="/etc/ka"> + <to dir="/ka"> + replication.conf + </to> +</from> +<from dir="."> + <to dir="/usr/sbin"> + restore-image.sh + </to> + <to dir="/usr/lib"> + restore-image-lib.sh + </to> +</from> +<if set="RESCUE_FLASH"> + <from expand="binary"> + dirname + losetup + mlabel + nash + pv + sed + usleep + </from> + <from dir="Flash/scripts" expand="glob"> + <to dir="/usr/bin"> + * + </to> + </from> +</if> + +</list> diff --git a/rescue/lsparts b/rescue/lsparts new file mode 100755 index 000000000..e1e866db4 --- /dev/null +++ b/rescue/lsparts @@ -0,0 +1,45 @@ +#!/usr/bin/perl +# +# Main author Pascal Rigaux (pixel@mandriva.com) +# 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/make_flash_rescue b/rescue/make_flash_rescue Binary files differnew file mode 100755 index 000000000..66bd6fd19 --- /dev/null +++ b/rescue/make_flash_rescue diff --git a/rescue/make_partimage_save_rest_all b/rescue/make_partimage_save_rest_all new file mode 100755 index 000000000..a7af52130 --- /dev/null +++ b/rescue/make_partimage_save_rest_all @@ -0,0 +1,64 @@ +#!/bin/sh + +[ $# -lt 1 ] && { + echo "usage: make_partimage_save_rest_all <partimage server> [<partimage dir> <data dirs>]" ; + exit 1 +} + +server=$1 ; shift +partimage_dir=$1 ; shift +data_dir=$1 ; shift + +if [ -n "$partimage_dir" ]; then + first_data_dir="$partimage_dir$data_dir" + + [ -d "$first_data_dir" ] || { + echo "can't find $first_data_dir" + exit 1 + } + [ -r "$first_data_dir/lst" ] || { + echo "can't read $first_data_dir/*" + exit 1 + } +fi + +rm -rf .tmp +mkdir -p .tmp/isolinux +cp -f /usr/lib/syslinux/isolinux.bin ../images/isolinux/alt0/* .tmp/isolinux + +DISTRIB_DESCR="partimage save/restore all" ./make_rescue_img || exit 1 +mkdir -p .tmp/install/stage2 +mv -f rescue.sqfs .tmp/install/stage2 + +common_para="rescue automatic=method:cdrom" +# hda=4864,255,63 acpi=ht + +for action in save_all rest_all; do + + cat <<EOF > .tmp/isolinux/isolinux.cfg +default $action +prompt 1 +timeout 150 + +label save_all + kernel vmlinuz + append initrd=all.rdz $common_para save_all pserver=$server +label rest_all + kernel vmlinuz + append initrd=all.rdz $common_para rest_all keepmounted BOX=$data_dir pserver=$server +label rescue + kernel vmlinuz + append initrd=all.rdz $common_para +EOF + + if [ $action = rest_all -a -n "$partimage_dir" ]; then + dir=`dirname $data_dir` + mkdir -p .tmp$dir + ln -s $partimage_dir$data_dir .tmp$dir + fi + + genisoimage -f -o part_$action.iso -r -J -hide-rr-moved -nobak -cache-inodes -publisher Mandriva -V 'mdk part save/rest' -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table .tmp + mkcd --addmd5 part_$action.iso +done + +rm -rf .tmp diff --git a/rescue/make_rescue_img b/rescue/make_rescue_img new file mode 100755 index 000000000..cf8c2f7e9 --- /dev/null +++ b/rescue/make_rescue_img @@ -0,0 +1,61 @@ +#!/usr/bin/perl + +use MDK::Common; +use lib "/usr/lib/libDrakX"; +use keyboard; + +my $tmp = "/tmp/rescue_tmp"; +my $rescue = "rescue.sqfs"; + +if ($>) { + $ENV{PATH} = "/sbin:/usr/sbin:$ENV{PATH}"; +} + +BEGIN { undef *_ } +sub __ { print @_, "\n"; system(@_) } +sub _ { __ @_; $? and die } + +_ "rm -rf $tmp" if -e $tmp; +_ "mkdir $tmp"; +_ 'find . -name "*~" | xargs rm -f'; +mkdir_p($tmp . chomp_($_)) foreach cat_("dirs"); +_ "cp -a tree/* $tmp"; +_ "find $tmp -name .svn | xargs rm -rf"; +_ "perl devices.pl $tmp/dev"; +_ "mkfifo $tmp/dev/initctl"; +substInFile { s/DISTRIB_DESCR/$ENV{DISTRIB_DESCR}/ } "$tmp/etc/issue"; + +_ "../tools/install-xml-file-list list.xml $tmp"; + +my %keytable_conflicts; +my @less_important_keytables = qw(am_old am_phonetic no-dvorak); +foreach (keyboard::loadkeys_files()) { + my ($dir, $fname) = (dirname($_), basename($_)); + my ($name) = $fname =~ /(.*)\.map\.gz/ or next; + next if member($name, @less_important_keytables); + if (my ($short2, $short) = $name =~ m|((.+?)[\W_][^\W_]*)|) { + $keytable_conflicts{$short} && $short2 ne $name and $short = $short2; + $keytable_conflicts{$short} and warn("conflict between $keytable_conflicts{$short} and $name for short name $short (choosing the first)\n"), next; + $keytable_conflicts{$short} = $name; + # create the short name based on the long one + symlinkf($fname, "$tmp$dir/$short.map.gz"); + } +} + +foreach (cat_("aliases")) { + chomp; my ($f, $dest) = split; + symlink $dest, "$tmp$f"; +} + + +if (my ($LANGUAGE) = map { if_(/LANGUAGE_(.*)/, $1) } keys %ENV) { + substInFile { + $_ = "export LANGUAGE=$LANGUAGE\n" . "export LC_ALL=$LANGUAGE\n" if /^#LANGUAGE/; + } "$tmp/etc/rc.sysinit"; +} + +exit 0 if $ARGV[0]; + +_ "mksquashfs $tmp $rescue -all-root -noappend >/dev/null"; +_ "chmod 755 $rescue"; +_ "rm -rf $tmp"; diff --git a/rescue/partimage_whole_disk b/rescue/partimage_whole_disk new file mode 100755 index 000000000..ed0653a95 --- /dev/null +++ b/rescue/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 <server>] (save_all <dir> | rest_all <dir>)\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 (<STDIN> !~ /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 (<STDIN> !~ /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 new file mode 100755 index 000000000..fa03d1be3 --- /dev/null +++ b/rescue/rescue-doc @@ -0,0 +1,60 @@ +#!/usr/bin/perl + +sub output { my $f = shift; local *F; open 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 Mandriva 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 Mandriva Linux 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. + +In case you have found a new problem which should be handled by +"rescue mode" but currently isn't, please report it to +<pixel@mandriva.com>. + +For more information on troubleshooting a Mandriva Linux system, +please consult the official manuals, the documentation on +MandrivaLinux.com, MandrivaClub.org, or the MandrivaExpert.com support forum. + +<press 'q' (qwerty keyboard) to continue> +)); + +exec 'less /tmp/rescue-doc-contents'; + diff --git a/rescue/restore-image-lib.sh b/rescue/restore-image-lib.sh new file mode 100755 index 000000000..b6d31a53a --- /dev/null +++ b/rescue/restore-image-lib.sh @@ -0,0 +1,78 @@ +#!/bin/bash + +TITLE="Mandriva Installer" +BACKTITLE="Mandriva" +MIN_DISKSIZE=800000 + +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() +{ + clear + sync + echo s > /proc/sysrq-trigger + echo o > /proc/sysrq-trigger + exit +} + +function _reboot() +{ + 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 new file mode 100755 index 000000000..5272b18fa --- /dev/null +++ b/rescue/restore-image.sh @@ -0,0 +1,217 @@ +#!/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="" + +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() +{ + clear + _yesno "\nWARNING: This process will erase all data in this machine, \ +do you want to continue?\n " + if [ "$?" != "0" ]; then + _shutdown + fi +} + +function detect_root() +{ + dev=$(sed '\|'$restore_media'|!d;s/[0-9] .*$//;s/^.*\///' /proc/mounts) + devices=$(grep "^ .*[^0-9]$" < /proc/partitions | grep -v ${dev} | awk '$3 > '$MIN_DISKSIZE' { print $4,$3 }') + + devs_found=$(echo $devices | wc -w) + if [ "$devs_found" -gt "2" ]; then + if [ ! -z ${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=$opcao + fi + fi + else + root=$(echo $devices | cut -d ' ' -f 1) + fi + echo "$root" +} + +function write_image() +{ + root=$(detect_root) + if [ -z ${root} ]; then + _msgbox "\nError writing image: disk device not detected.\n" + # so that netbooks using USB sticks as disks can retry (like Gdium) + welcome + root=$(detect_root) + fi + + image=$(cat $images_dir/list | cut -d ',' -f 3) + extension=$(echo $image | cut -d '.' -f 3) + case $extension in + gz) uncomp=zcat ;; + bz2) uncomp=bzcat ;; + *) uncomp=cat ;; + esac + $uncomp $images_dir/$image | dd of=/dev/$root bs=4M > /tmp/backup.out 2>&1 & + + sleep 3 + pid=$(ps ax | grep 'dd of' | grep -v grep | awk '{ print $1 }') + total=1000 + + while [ true ]; do + ps | grep -q $pid + if [ $? -eq 0 ]; then + /bin/kill -SIGUSR1 $pid + unit=$(tail -n 1 /tmp/backup.out | \ + cut -d'(' -f2 | cut -d')' -f1 |\ + awk '{ print $2 }') + + complete=$(tail -n 1 /tmp/backup.out | \ + cut -d'(' -f2 | cut -d')' -f1 | \ + awk '{ print $1 }' | cut -d'.' -f1) + if [ x"$unit" = x"GB" ]; then + complete=$((complete*1000)) + fi + 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 +} + +function expand_fs() +{ + filesystem_type=$(dumpe2fs -h /dev/${root}1 2>/dev/null| grep "Filesystem OS type" | awk '{ print $4 }') + if [ "$filesystem_type" = "Linux" ]; then + dialog --backtitle "$BACKTITLE" --title "$TITLE" --infobox "Installing... Finishing Install..." 3 40 + disk=/dev/$root + main_part=/dev/${root}1 + swap_part=/dev/${root}2 + 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 "$EXPAND_FS" ]; then + sfdisk -d $disk | sed -e "\|$main_part| s/size=.*,/size= $main_part_sectors,/" | sfdisk -f $disk + e2fsck -fy $main_part + resize2fs $main_part + fi + if [ -n "$SWAP_BLOCKS" ]; then + parted $disk -- mkpartfs primary linux-swap ${main_part_sectors}s -1s yes + mkswap -L swap $swap_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" + fi + if [ -n "$MKINITRD" ]; then + mount -t sysfs none "$mnt_dir/sys" + mount -t proc none "$mnt_dir/proc" + echo > /proc/sys/kernel/modprobe # rescue's modprobe does not handle modprobe -q and aliases + 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 +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 new file mode 100755 index 000000000..1f8cc2907 --- /dev/null +++ b/rescue/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 +#- +#- diff --git a/rescue/tree/bin/insmod b/rescue/tree/bin/insmod new file mode 100755 index 000000000..49b298142 --- /dev/null +++ b/rescue/tree/bin/insmod @@ -0,0 +1,2 @@ +#!/bin/sh +echo "Use modprobe instead" diff --git a/rescue/tree/bin/login b/rescue/tree/bin/login new file mode 100755 index 000000000..4b2816926 --- /dev/null +++ b/rescue/tree/bin/login @@ -0,0 +1,2 @@ +#!/bin/sh +exec /bin/bash --login diff --git a/rescue/tree/etc/fstab b/rescue/tree/etc/fstab new file mode 100644 index 000000000..fbafb7801 --- /dev/null +++ b/rescue/tree/etc/fstab @@ -0,0 +1,4 @@ +/dev/ram3 / ext2 defaults 1 1 +/dev/fd0 /mnt/floppy auto defaults,noauto 0 0 +none /proc proc defaults,noauto,ro 0 0 +/dev/cdrom /mnt/cdrom auto defaults,noauto 0 0 diff --git a/rescue/tree/etc/group b/rescue/tree/etc/group new file mode 100644 index 000000000..5ba713c83 --- /dev/null +++ b/rescue/tree/etc/group @@ -0,0 +1 @@ +root::0:root diff --git a/rescue/tree/etc/host.conf b/rescue/tree/etc/host.conf new file mode 100644 index 000000000..1a8c1e151 --- /dev/null +++ b/rescue/tree/etc/host.conf @@ -0,0 +1,2 @@ +order hosts,bind +multi on diff --git a/rescue/tree/etc/hosts b/rescue/tree/etc/hosts new file mode 100644 index 000000000..a9bbdee7f --- /dev/null +++ b/rescue/tree/etc/hosts @@ -0,0 +1 @@ +127.0.0.1 mandrake-rescue diff --git a/rescue/tree/etc/inittab b/rescue/tree/etc/inittab new file mode 100644 index 000000000..771d7c0d4 --- /dev/null +++ b/rescue/tree/etc/inittab @@ -0,0 +1,14 @@ +#Inittab for Mandrake Rescue Disk +#Author: Daouda Lo <daouda@mandrakesoft.com> +id:3:initdefault: + +si::sysinit:/etc/rc.sysinit +re:6:wait:/etc/rc.reboot +ca:12345:ctrlaltdel:/sbin/fakeshutdown + +1:12345:respawn:/sbin/mingetty --autologin root tty1 +2:23:respawn:/sbin/mingetty tty2 +3:23:respawn:/sbin/mingetty tty3 +4:23:respawn:/sbin/mingetty tty4 +5:23:respawn:/sbin/mingetty tty5 +6:23:respawn:/sbin/mingetty tty6 diff --git a/rescue/tree/etc/issue b/rescue/tree/etc/issue new file mode 100644 index 000000000..2bbd2b38a --- /dev/null +++ b/rescue/tree/etc/issue @@ -0,0 +1,28 @@ +[40m[40m +[2J[0;0H +[0;1;30;44m [40m [44m [40m +[1;44m [40m [44m [2C[47m [5C [1C [3C [1C [2C [1C [2C [40m +[1;30;44m [40m [47m [40m [47m [40m [44m [2C[47m [7C [3C [2C [1C [2C [2C [40m +[1;30;44m [40m [47m [40m [47m [40m [44m [2C[47m [7C [3C [1C [1C [2C [3C [40m +[1;30;44m [40m [43m [40m [44m [2C[47m [7C [3C [1C [1C [2C [2C [40m +[1;30;44m [40m [0;30;43m`----'[40m [1;44m [2C[47m [1C [1C [3C [2C [2C [2C [40m +[1;30;44m [40m [47m [37m [30m [40m [44m [40m +[1;30;44m [40m [47m [40m [44m [40m[2C[1;37;40m[0m +[1;30;44m [40m [47m [40m [44m [40m[2[1;37;4[0m +[1;30;44m [40m [47m [40m [30;44m [40m[2C[1;37;40m[0m +[1;30;44m [40m [47m [40m [2C[1;37;40m[0m +[1;30;44m [40m [47m [40m [2C[1;37;40mMandriva Linux Rescue Disk[0m +[1;30;44m [43m [30;47m [43m [40m [2C[1;37;40m[0m +[1;30;44m [43m [47m [43m [40m [2C +[1;30;44m [43m [47m [43m [40m[2C +[1;30;44m [43m [40m [47m [40m [43m [40m[2C +[0m[255D + +DISTRIB_DESCR + +Use [1;33;40mloadkeys[0m to change your keyboard layout (eg: loadkeys fr) +Use [1;33;40mmodprobe[0m to load modules (eg: modprobe snd-card-fm801) +Use [1;33;40mdrvinst[0m to install drivers according to detected devices +Use [1;33;40mlsparts[0m to list your partitions with types +Use [1;33;40mrescue-gui[0m to go back to the rescue menu + diff --git a/rescue/tree/etc/passwd b/rescue/tree/etc/passwd new file mode 100644 index 000000000..568451e4e --- /dev/null +++ b/rescue/tree/etc/passwd @@ -0,0 +1,3 @@ +root::0:0::/:/bin/bash +shutdown:*:6:0:shutdown:/sbin:/sbin/shutdown +halt:*:7:0:halt:/sbin:/sbin/halt diff --git a/rescue/tree/etc/profile b/rescue/tree/etc/profile new file mode 100644 index 000000000..3b5ac21cc --- /dev/null +++ b/rescue/tree/etc/profile @@ -0,0 +1,24 @@ +# /etc/profile +# (c) Mandrakesoft, Chmouel Boudjnah <chmouel@mandrakesoft.com> + +# System wide environment and startup programs +# Functions and aliases go in /etc/bashrc + +PROFILE_LOADED=1 + +export PATH=/usr/bin:/bin:/sbin:/usr/sbin:/usr/X11R6/bin + +PS1="[root@rescue \w]\\$ " +ls () { /bin/ls --color=auto -F "$@";} +ll () { /bin/ls --color=auto -Fl "$@";} +d () { /bin/ls --color=auto -F "$@";} +s () { cd .. ;} +which () { type -p "$@" ;} +HOSTNAME=rescue +HISTSIZE=1000 +HISTFILESIZE=1000 + +INPUTRC=/etc/inputrc +export PATH PS1 USER HOSTNAME HISTSIZE HISTFILESIZE INPUTRC + +cat /etc/issue diff --git a/rescue/tree/etc/rc.reboot b/rescue/tree/etc/rc.reboot new file mode 100755 index 000000000..0b67416f1 --- /dev/null +++ b/rescue/tree/etc/rc.reboot @@ -0,0 +1,8 @@ +#!/bin/sh + +sleep 1 +/sbin/killall5 -9 + +umount -a -f -t noproc + +reboot -i -d diff --git a/rescue/tree/etc/rc.sysinit b/rescue/tree/etc/rc.sysinit new file mode 100755 index 000000000..bf8ffa13e --- /dev/null +++ b/rescue/tree/etc/rc.sysinit @@ -0,0 +1,80 @@ +#!/bin/sh + +action() { echo $1; shift; $*; } +DATE=`date +%Y%m%d-%Hh%M` +KADIR="/ka2" + +export PATH=/bin:/sbin:/usr/bin:/usr/sbin + +echo -e "\t\t\tWelcome to \\033[1;36mMandriva\\033[0;39m Linux" + +action "Remounting root filesystem in read-write mode" mount -n -o remount,rw / + +ln -s /tmp/stage2/etc/* /etc 2>/dev/null + +rm -f /dev ; cp -a /tmp/stage2/dev /dev + +mkdir -p /mnt /var/log + +>/etc/mtab +mount -f / +mount -f /proc + +# Set the hostname. +action "Setting hostname rescue" hostname rescue +echo rescue > /etc/HOSTNAME + +# Loads common modules ( no kerneld :( ) +echo "Loading additional modules..." +load() { modprobe $* 2>/dev/null; } +load ide-disk +load ide-cd_mod +load floppy +load af_packet +load isofs +load vfat +load ext3 +load reiserfs +load xfs +load jfs +load loop +load sd_mod +load sr_mod + +/sbin/ifconfig lo 127.0.0.1 netmask 255.0.0.0 +/sbin/route add 127.0.0.1 lo + +# disable the weird echoprt in cooked mode for user interaction: +stty sane + +#LANGUAGE (filled by make_rescue_img) + +grep -q noauto /proc/cmdline || drvinst SERIAL_USB + +partimage_default_dir=/data/box +partimage_dir=`perl -lne 'print $1 if /BOX=(\S+)/' /proc/cmdline` +[ -z "$partimage_dir" ] && partimage_dir=$partimage_default_dir +partimage_server=`perl -lne 'print $1 if /\bpserver=(\S+)/' /proc/cmdline` + +if grep -q save_all /proc/cmdline; then + partimage_whole_disk -s $partimage_server save_all $partimage_default_dir +elif grep -q rest_all /proc/cmdline; then + if [ -d /tmp/image$partimage_dir ]; then + partimage_whole_disk rest_all /tmp/image$partimage_dir + else + partimage_whole_disk -s $partimage_server rest_all $partimage_dir + fi +elif grep -q restore /proc/cmdline; then + /usr/sbin/restore-image.sh +elif grep -q kamethod /proc/cmdline; then + echo "Welcome to Ka" + drvinst + ln -sf /tmp/stage2/ka $KADIR + ln -sf /tmp/stage2/disk /disk + cd $KADIR + echo "-------- Starting LOG server -------------" + perl send_status.pl > /tmp/kacmd & + exec ./ka_replication.sh > /tmp/ka_log-$HOSTNAME-$DATE 2>&1 +elif ! grep -q expert /proc/cmdline; then + rescue-gui +fi diff --git a/rescue/tree/etc/resolv.conf b/rescue/tree/etc/resolv.conf new file mode 100644 index 000000000..3822939b1 --- /dev/null +++ b/rescue/tree/etc/resolv.conf @@ -0,0 +1,2 @@ +search foo.com +nameserver 192.168.1.1 diff --git a/rescue/tree/sbin/fakeshutdown b/rescue/tree/sbin/fakeshutdown new file mode 100755 index 000000000..3511020ff --- /dev/null +++ b/rescue/tree/sbin/fakeshutdown @@ -0,0 +1,39 @@ +#!/usr/bin/perl + +# +# Guillaume Cottenceau (gc@mandrakesoft.com) +# +# Copyright 2001 Mandrakesoft +# +# 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. +# + +sub cat_ { local *F; open F, $_[0] or $_[1] ? die "cat of file $_[0] failed: $!\n" : return; my @l = <F>; wantarray ? @l : join '', @l } + +print "\n"; + + +#- try to umount as much as possible; uses Pixel's ultra optimized algo (let you guess how it works..) +print "Umounting:\n"; +my @mounts = cat_('/proc/mounts'); +my $something_moved; +do { + $something_moved = 0; + foreach (@mounts) { + my $where = (split)[1]; + next if $where eq '/'; #- ouch! umounting the ramdisk on / always succeeds, and makes it becoming ro :-( + if (!system("umount $where 2>/dev/null")) { + print "\t$where\n"; + $something_moved++; + } + } +} while $something_moved; + + +#- shutdown with init +exec '/sbin/init', 6; diff --git a/rescue/tree/sbin/modprobe b/rescue/tree/sbin/modprobe new file mode 100755 index 000000000..a9cd91a89 --- /dev/null +++ b/rescue/tree/sbin/modprobe @@ -0,0 +1,16 @@ +#!/usr/bin/perl + +use lib qw(/usr/lib/libDrakX); +use list_modules; +use modules; + +# based on install::commands +sub modprobe { + !@_ || $_[0] =~ /^-?-h/ and die "usage: modprobe <module> [<options...>]\n"; + my $name = shift; + list_modules::load_default_moddeps(); + modules::load_with_options([ $name ], { $name => join(' ', @_) }); +} + +$::isInstall = 1; +modprobe(@ARGV); diff --git a/rescue/tree/usr/lib/CVS. b/rescue/tree/usr/lib/CVS. new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/rescue/tree/usr/lib/CVS. diff --git a/rescue/tree/usr/share/symlinks b/rescue/tree/usr/share/symlinks new file mode 100644 index 000000000..5862fb8ac --- /dev/null +++ b/rescue/tree/usr/share/symlinks @@ -0,0 +1,10 @@ +/bin +/boot +/dev +/etc/fstab +/etc/inittab +/etc/rc.sysinit +/lib +/lib64 +/sbin +/usr |