rescue-0.23/000075500000000000000000000000001233416267100127275ustar00rootroot00000000000000rescue-0.23/find-fstab000075500000000000000000000032601233416267100146730ustar00rootroot00000000000000#!/bin/sh -efu . shell-error ## Volume manager specific functions fstype() { [ "$#" -eq 1 -a -n "$1" ] || return 1 blkid -o value -s TYPE "$1"|grep -v swap } volumes() { blkid -o device|grep -v loop } ## Functions usage() { echo "Usage: $PROG [--help|--list-only|]" >&2 exit 1 } workdir= exit_handler() { local rc=$? trap - EXIT if cut -d' ' -f2 /proc/mounts |fgrep -xqs "$workdir"; then umount -l "$workdir" fi [ ! -d "$workdir" ] || rm -rf -- "$workdir" exit $rc } suggest_manual() { echo "warning: $1 might need recovery or \`noload' mount option" >&2 } listonly= outdir= i=0 fstab_list() { local v fs fslist success opts grep -wqs forensic /proc/cmdline && opts=",loop" || opts= for v in `volumes`; do fslist="`fstype "$v"`" && [ -n "$fslist" ] || continue success= for fs in $fslist; do case "$fs" in # MDRAID, LVM2, LUKS *_member|crypto_*) continue;; esac modprobe -b $fs ||: mount -t "$fs" -o "ro$opts" "$v" "$workdir" \ >/dev/null 2>&1 && success=1 || { [ -z "$opts" ] || case "$fs" in ext3|ext4) suggest_manual "$v";; esac } done [ -n "$success" ] || continue if [ ! -f "$workdir/etc/fstab" ]; then umount -l "$workdir" continue fi i="$(($i+1))" [ -z "$listonly" ] && cp -- "$workdir/etc/fstab" "$outdir/fstab.$i" || echo "File /etc/fstab found on volume '$v'" umount -l "$workdir" done } [ "$#" -eq 1 ] || usage if [ "$1" = "--list-only" ]; then listonly=1 elif [ "$1" = "--help" ]; then usage else outdir="`readlink -ev "$1"`" fi trap exit_handler HUP PIPE INT QUIT TERM EXIT workdir="`mktemp -dt "$PROG.XXXXXXXXXX"`" fstab_list [ "$i" -gt 0 ] && rc=0 || rc=1 exit $rc rescue-0.23/fixmbr000075500000000000000000000064601233416267100141520ustar00rootroot00000000000000#!/bin/bash verbose() { [ -z "$verbose" ] || echo $@ } show_help() { cat <<'EOF' fixmbr - try to restore grub or lilo MBR Usage: fixmbr [options] [] The option is meaningfull only in --grub case (see). If no specified, then fixmbr tries to install grub on each non-lilo disk. Options: --grub try to restore grub [this is default]; --lilo try to restore lilo; -v, --verbose be more verbose; -h, --help show this text and exit. Report bugs to http://bugzilla.altlinux.ru/ EOF exit } # List possible target devices list_disks() { tail -n +3 /proc/partitions | while read major minor blocks name; do [ -d "/sys/block/$name" ] && echo "$name" done } # List devices where grub should be placed list_grub_disks() { for disk in $(list_disks); do detectloader.sh "/dev/$disk" | grep -q -v lilo && echo "/dev/$disk" done } # Find root partition with latest (by modification date) grub.cfg find_grub_system() { ls -ct1 /mnt/system*/boot/grub/grub.cfg 2>/dev/null | head -n 1 | sed -s 's|/boot/grub/grub.cfg||' } # Find root partition with latest (by modification date) lilo.conf find_lilo_system() { ls -ct1 /mnt/system*/etc/lilo.conf 2> /dev/null | head -n 1 | sed -s 's|/etc/lilo.conf||' } # repair_grub # # @device: repair grub MBR on that device # @system: system to chroot to repair_grub() { local device="$1" system="$2" if [ -z "$device" ]; then verbose "device is not given" return 1 fi if [ -z "$system" ]; then verbose "system is not given" return 1 fi verbose "installing grub from $system to $device" chroot "$system" grub-install --no-floppy "$device" } # repair_lilo # # @system: system to chroot to repair_lilo() { local system="$1" if [ -z "$system" ]; then verbose "system is not given" return 1 fi verbose "installing lilo from $system" chroot "$system" lilo } TEMP=`getopt -n fixmbr -o v,h -l verbose,help,grub,lilo -- "$@"` || show_help eval set "--" $TEMP loader=grub # try to repair grub by default while :; do case "$1" in --lilo) loader=lilo ;; --grub) loader=grub ;; -v|--verbose) verbose=-v ;; -h|--help) show_help ;; --) shift; break; ;; esac shift done verbose "Mounting partitions" verbose `mount-system 2>&1` ok= case "$loader" in lilo) # find ``good'' lilo.conf if system=$(find_lilo_system) && [ -n "$system" ]; then repair_lilo "$system" && ok=1 || verbose "can't install lilo from $system" else verbose "can't find root partition with lilo.conf" fi ;; grub) # find ``good'' grub.cfg if system=$(find_grub_system) && [ -n "$system" ]; then # generate list of target grub devices, i.e., devices # that don't contain lilo bootloader [ -n "$1" ] && target_devices="$1" || target_devices="$(list_grub_disks)" # install grub on each such device for device in $target_devices; do repair_grub "$device" "$system" && ok=1 || verbose "can't install grub on $device from $system" done else verbose "can't find root partition with grub.cfg" verbose "maybee you should try \`fixmbr --lilo' instead?" fi ;; *) verbose "unsupported loader $loader" ;; esac if [ -z "$ok" ]; then echo "Automatic fixing failed see /mnt/* and try repire manually..." fi rescue-0.23/inittab.rescue000064400000000000000000000026751233416267100156030ustar00rootroot00000000000000# The default runlevel. id:3:initdefault: # Boot-time system configuration/initialization script. # This is run first except when booting in emergency (-b) mode. si::sysinit:/etc/rc.d/rc.sysinit.rescue # /etc/rc.d/rc executes the S and K scripts upon change of runlevel. # # Runlevel 0 is halt. # Runlevel 1 is single-user. # Runlevels 2-5 are multi-user. # Runlevel 6 is reboot. l0:0:wait:/etc/rc.d/rc 0 l1:1:wait:/etc/rc.d/rc 1 l2:2:wait:/etc/rc.d/rc 2 l3:3:wait:/etc/rc.d/rc 3 l4:4:wait:/etc/rc.d/rc 4 l5:5:wait:/etc/rc.d/rc 5 l6:6:wait:/etc/rc.d/rc 6 # Normally not reached, but fallthrough in case of emergency. z6:6:respawn:/sbin/sulogin # What to do when CTRL-ALT-DEL is pressed. ca:012345:ctrlaltdel:/sbin/shutdown -t3 -r now # Action on special keypress (ALT-UpArrow). kb::kbrequest:/bin/echo "Keyboard Request -- edit /etc/inittab to let this work." # What to do when the power fails/returns. pf::powerwait:/etc/rc.d/rc.powerfail start pn::powerfailnow:/etc/rc.d/rc.powerfail now po::powerokwait:/etc/rc.d/rc.powerfail stop # Format: # ::: 1:2345:respawn:/bin/openvt -elfw -c 1 -- /usr/bin/rescue-shell 2:2345:respawn:/bin/openvt -elfw -c 2 -- /usr/bin/rescue-shell 3:2345:respawn:/bin/openvt -elfw -c 3 -- /usr/bin/rescue-shell 4:2345:respawn:/bin/openvt -elfw -c 4 -- /usr/bin/rescue-shell 5:2345:respawn:/bin/openvt -elfw -c 5 -- /usr/bin/rescue-shell 6:2345:respawn:/bin/openvt -elfw -c 6 -- /usr/bin/rescue-shell rescue-0.23/mdadm-ro.conf000064400000000000000000000001731233416267100152770ustar00rootroot00000000000000# Use loop devices only! DEVICE /dev/loop* CREATE owner=root group=disk mode=0660 auto=yes HOMEHOST MAILADDR root rescue-0.23/mount-fstab000075500000000000000000000034321233416267100151160ustar00rootroot00000000000000#!/bin/sh -efu . shell-error . shell-args TEST= show_help() { local rc="${1:-0}" cat < Options: --dry-run -q, --quiet Try to be more quiet. -v, --verbose Print a message for each action. -V, --version print program version and exit. -h, --help Show this message. EOF exit "$rc" } workdir= exit_handler() { local rc=$? trap - EXIT [ ! -d "$workdir" ] || rm -rf -- "$workdir" exit $rc } TEMP=`getopt -n $PROG -o $getopt_common_opts -l dry-run,$getopt_common_longopts -- "$@"` || show_usage eval set -- "$TEMP" while :; do case "$1" in --dry-run) TEST=message ;; --) shift; break ;; *) parse_common_option "$1" ;; esac shift done [ "$#" -eq 2 ] || show_usage fstab="`readlink -ev "$1"`" dstdir="`readlink -ev "$2"`" trap exit_handler HUP PIPE INT QUIT TERM EXIT workdir="`mktemp -dt "$PROG.XXXXXXXXXX"`" sed -e '\,[[:space:]]*#,d' \ -e '\,^[[:space:]]*[^[:space:]]\+[[:space:]]\+/,!d' \ -e 's/[[:space:]]\+/ /g' "$fstab" | sort -k2,2 -so "$workdir/fstab" while read dev mpoint fstype opts dummy; do if printf %s "$opts" |grep -qs '\'; then continue fi case "$fstype" in ext2|ext3|ext4|reiserfs|xfs|jfs) modprobe -b "$fstype" ;; *) [ "$mpoint" = "/boot/efi" ] || continue ;; esac # avoid filesystem journal rollback when investigating if grep -wqs forensic /proc/cmdline; then opts="${opts:+$opts,}ro,loop,noexec" fi cmd="mount -t '$fstype' -o '$opts'" case "$dev" in LABEL=*) cmd="$cmd -L '${dev#LABEL=}'" ;; UUID=*) cmd="$cmd -U '${dev#UUID=}'" ;; *) cmd="$cmd $dev" ;; esac $TEST mkdir -p -- "$dstdir$mpoint" $TEST eval $cmd "$dstdir$mpoint" done < "$workdir/fstab" rescue-0.23/mount-system000075500000000000000000000013631233416267100153440ustar00rootroot00000000000000#!/bin/sh -eu . shell-error workdir= exit_handler() { local rc=$? trap - EXIT [ ! -d "$workdir" ] || rm -rf -- "$workdir" exit $rc } trap exit_handler HUP PIPE INT QUIT TERM EXIT workdir="`mktemp -dt "$PROG.XXXXXXXXXX"`" mountpoint -q /mnt || mount -o rw -t tmpfs tmpfs /mnt grep -wqs forensic /proc/cmdline || ! type -t vgchange >/dev/null || vgchange -ay find-fstab "$workdir" || fatal "No fstab found (see dmesg?)" cd "$workdir" for fstab in fstab.*; do [ "$fstab" != "fstab.*" ] || break mpoint="/mnt/system${fstab##*.}" mkdir -p -- "$mpoint" if mount-fstab "$fstab" "$mpoint"; then message "$mpoint: done" fi mount --bind /proc "$mpoint/proc" mount --bind /sys "$mpoint/sys" mount --bind /dev "$mpoint/dev" done cd ->/dev/null rescue-0.23/rc.sysinit.rescue000075500000000000000000000135301233416267100162510ustar00rootroot00000000000000#!/bin/sh # Based on rc.sysinit from startup-0.9.8.10-alt1 # Don't do coredumps ulimit -Sc 0 >/dev/null 2>&1 trap '' SIGPIPE WITHOUT_RC_COMPAT=1 # Source function library . /etc/init.d/functions action_begin_msg() { [ -z "$*" ] || printf '%s ' "$*" } action_end_msg() { local rc=$1 if [ "$BOOTUP" = color ]; then [ $rc = 0 ] && echo_success || echo_failure fi echo } unset action action() { action_begin_msg "$1" shift $* local rc=$? action_end_msg "$rc" return $rc } # Fix console loglevel dmesg -n "$LOGLEVEL" HOSTNAME=`hostname` # Read in config data if ! SourceIfNotEmpty /etc/sysconfig/network; then NETWORKING=no fi if [ -z "$HOSTNAME" -o "$HOSTNAME" = "(none)" ]; then HOSTNAME=localhost fi # Set system font ExecIfExecutable /sbin/setsysfont >/dev/null 2>&1 && SETSYSFONT_DONE=1 || SETSYSFONT_DONE= PrintMargin() { [ "$BOOTUP" != serial ] || return 0 local n n="`printf %s "$*" |wc -c`" 2>/dev/null && tput hpa $(( ($COLUMNS - $n)/2 )) } WELCOME="Welcome to " BANNER="ALT Linux (rescue)" PrintMargin "$WELCOME$BANNER" printf %s "$WELCOME" SETCOLOR_INFO printf %s "$BANNER" SETCOLOR_NORMAL echo # Mount /proc (done here so volume labels can work with fsck) action "Mounting proc filesystem:" mount -n -t proc proc /proc # Mount /sys where appropriate if [ ! -d /sys/kernel ] && grep -wqs sysfs /proc/filesystems; then action "Mounting sys filesystem:" mount -n -t sysfs sysfs /sys fi action "Mounting tmpfs filesystem [/tmp]:" mount -t tmpfs tmpfs /tmp remount_aufs() { [ -d "$1" ] || return 0 mkdir -p -- "/tmp/root$1" mount -n -t aufs -o dirs="/tmp/root$1=rw:$1=ro" "/tmp/root$1" "$1" } # Avoid double-aufs attempt if ! grep -q "/ aufs" /proc/mounts; then for mpoint in /etc /var /lib /bin /sbin /home /root /mnt; do action "Mounting '$mpoint' to overlay:" remount_aufs "$mpoint" done fi # Avoid mdraid auto-assembly in forensics mode; AUTO is not effective MDCONF=/etc/mdadm.conf if [ -s "$MDCONF" ] && grep -wqs forensic /proc/cmdline; then sed -i 's,^DEVICE partitions,DEVICE /dev/null,' "$MDCONF" fi # Generate blacklist for udev if [ -d /etc/modprobe.d ] && grep -iqs 'blacklist=' /proc/cmdline; then sed -n -e 's/^.*blacklist=\([^= ]\)\( .*\|\$\)/\1/p' /proc/cmdline | tr -s ':,' '\n' | while read kmodule; do echo "blacklist ${kmodule%.ko}" done >> /etc/modprobe.d/local-blacklist fi RUN_UDEV= udevd_exe=/etc/init.d/udevd [ ! -x "$udevd_exe" ] || grep -iwqs noudev /proc/cmdline || RUN_UDEV=1 # Start udev if [ -n "$RUN_UDEV" ]; then RUN_FROM_SYSINIT=1 "$udevd_exe" start [ -c /dev/rtc ] || modprobe -b rtc >/dev/null 2>&1 fi # Recover mdadm.conf if it's been changed above if [ -s "$MDCONF" ]; then sed -i 's,^DEVICE /dev/null,DEVICE partitions,' "$MDCONF" echo "# NB: modified during boot to avoid auto-assembly" >> "$MDCONF" fi # Find swap partitions and add them to /etc/fstab sfdisk -l 2>/dev/null | sed \ -e '/\/dev/!d' \ -e 's/[[:space:]]\+/ /g' \ -e 's/^\(\/dev\/[^[:space:]]\+\) \([[:digit:]]\)/\1 x \2/' | while read dev boot start end blocks id system; do [ "$id" = "82" ] || continue printf "%s swap swap defaults 0 0\n" "$dev" done >> /etc/fstab # Do NOT activate swap automatically #action "Activating swap partitions:" swapon -a -e # Set the hostname action "Setting hostname $HOSTNAME:" hostname "$HOSTNAME" # Set the NIS domain name if [ -n "$NISDOMAIN" ] && ! is_no "$NISDOMAIN"; then action "Setting NIS domain name $NISDOMAIN:" domainname "$NISDOMAIN" fi # Clear mtab [ -L /etc/mtab ] || >/etc/mtab # Remove stale backups rm -f /etc/mtab~ /etc/mtab~~ # Enter root and /proc into mtab. (pixel) also added /initrd/loopfs for loopback root mount -f /proc [ -d /sys/bus ] && mount -f -t sysfs sysfs /sys [ -f /proc/bus/usb/devices ] && mount -f -t usbfs usbfs /proc/bus/usb ! mountpoint -q /dev || mount -f -t tmpfs udevfs /dev ! mountpoint -q /dev/pts || mount -f -t devpts devpts /dev/pts ! mountpoint -q /dev/shm || mount -f -t tmpfs shmfs /dev/shm ! mountpoint -q /tmp || mount -f -t tmpfs tmpfs /tmp # Set hard disk parameters /etc/rc.d/scripts/idetune echo "$HOSTNAME" >/etc/HOSTNAME # Configure kernel parameters action "Configuring kernel parameters:" sysctl -e -p /etc/sysctl.conf if [ -z "$USEMODULES" ]; then if [ -f /proc/ksyms -o -f /proc/kallsyms ] && ! fgrep -iwqs nomodules /proc/cmdline; then USEMODULES=y else USEMODULES=n fi fi if [ -f /proc/sys/kernel/modprobe ]; then if is_yes "$USEMODULES"; then if [ -z "$RUN_UDEV" ]; then sysctl -w kernel.modprobe="/sbin/modprobe" >/dev/null 2>&1 sysctl -w kernel.hotplug="/sbin/hotplug" >/dev/null 2>&1 fi else # We used to set this to NULL, but that causes 'failed to exec' messages" sysctl -w kernel.modprobe="/bin/true" >/dev/null 2>&1 sysctl -w kernel.hotplug="/bin/true" >/dev/null 2>&1 fi fi OLD_COLUMNS="$COLUMNS" # Load modules /etc/rc.d/scripts/load_modules # Load framebuffer device settings /etc/rc.d/scripts/framebuffer_init # Set system font again, if required if [ "$OLD_COLUMNS" != "$COLUMNS" ]; then ExecIfExecutable /sbin/setsysfont >/dev/null 2>&1 && SETSYSFONT_DONE=1 || SETSYSFONT_DONE= fi #VGSCAN=/sbin/vgscan #VGCHANGE=/sbin/vgchange #if [ -e "$VGCHANGE" -a -e "$VGSCAN" -a -c /dev/mapper/control ] && ! grep -iwqs nolvm /proc/cmdline; then # modprobe dm-mod >/dev/null 2>&1 # "$VGSCAN" >/dev/null 2>&1 # action "Setting up LVM2:" "$VGCHANGE" -a y #fi MBRRESC=/sbin/fixmbr if [ -e "$MBRRESC" ] && grep -iwqs fixmbr /proc/cmdline; then action "Restore MBR:" "$MBRRESC" if [ "$?" -eq "0" ]; then # MBR successfully restored printf "reboot in 10 seconds..." sleep 10 && reboot fi fi # Language fixes /etc/rc.d/scripts/lang # If they asked for ide-scsi, load it if grep -iwqs ide-scsi /proc/cmdline; then modprobe -b ide-cd >/dev/null 2>&1 modprobe -b ide-scsi >/dev/null 2>&1 fi if [ -x /usr/sbin/update_chrooted ]; then action "Updating chrooted environments:" /usr/sbin/update_chrooted conf lib fi rescue-0.23/rescue-shell000075500000000000000000000015441233416267100152540ustar00rootroot00000000000000#!/bin/sh banner() { echo -e "$1\033[0m"; } say() { echo -e "$1\033[1m$2\033[0m"; } echo if grep -wqs forensic /proc/cmdline; then banner "MDRAID/LVM/LUKS/swaps inactive in \033[1;33mforensic mode" say '* activate MDRAID (loop): ' 'raid-forensic' say '* activate LVM (loop): ' 'lvm2-forensic' say "* mount clean filesystems (ro,loop): " \ 'mount-forensic, mount-system' else banner "Your rescue shell; when in emergency, \033[1;32mdon't panic!" say "* mount Linux filesystems: " 'mount-system' say "* mount any filesystems (ro,loop): " 'mount-forensic' if [ -d /sys/firmware/efi ]; then say '* restore GRUB bootloader (inside chroot): ' 'grub-install' else say '* restore Master Boot Record: ' 'fixmbr' fi fi echo echo -e 'More info: \033[1;36mhttp://en.altlinux.org/rescue\033[0m' echo export HOME=/root export SHELL=/bin/bash exec /bin/bash -l rescue-0.23/sysreport.init000075500000000000000000000007361233416267100156770ustar00rootroot00000000000000#!/bin/sh # # Run sysreport # # chkconfig: 2345 99 01 # description: This service gathers system information via system-report. WITHOUT_RC_COMPAT=1 # Source function library. . /etc/init.d/functions LOCKFILE=/var/lock/subsys/sysreport case "$1" in start|restart|reload) # This action line is required to fool rc script. system-report -o "/root/sysreport-$(date +"%Y%m%d").tar.bz2" touch "$LOCKFILE" ;; stop|condstop) rm -f "$LOCKFILE" ;; *) ;; esac exit 0