where can i find the programs/scripts that run in rescue mode?

General support questions
Post Reply
theoriginalguru
Posts: 13
Joined: 2009/04/10 08:08:31

where can i find the programs/scripts that run in rescue mode?

Post by theoriginalguru » 2016/06/28 00:28:18

Hello,

I need to understand in detail how the rescue mode works on CentOS 7. In particular, when you boot in rescue mode of the ISO image, there is an option to automatically detect your system and mount it under /mnt/sysimage in the rescue environment. I need to know exactly what this option (#1) does, and so I would like to look at the program or script that performs the operations when option 1 is selected in rescue mode.

This is what i've found so far:

1. from the ISO image, I see that isolinux.cfg boots the kernel with these parameters under rescue mode:

Code: Select all

kernel vmlinuz
append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 rescue quiet
I'm not 100% sure how the "rescue" option is handled... my guess is that it tells systemd to run the rescue.target?

2. I extracted the initrd.img, and I see:

# find . -name rescue.target
./usr/lib/systemd/system/rescue.target
# less -X ./usr/lib/systemd/system/rescue.target

Code: Select all

#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

[Unit]
Description=Rescue Mode
Documentation=man:systemd.special(7)
Requires=sysinit.target rescue.service
After=sysinit.target rescue.service
AllowIsolate=yes

[Install]
Alias=kbrequest.target
so, i next look for rescue.service:

# find . -name rescue.service
./usr/lib/systemd/system/rescue.service
# less -X ./usr/lib/systemd/system/rescue.service

Code: Select all

#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

# See systemd.special(7) for details

[Unit]
Description=Emergency Shell
DefaultDependencies=no
After=systemd-vconsole-setup.service
Wants=systemd-vconsole-setup.service
ConditionPathExists=!/lib/dracut/no-emergency-shell

[Service]
Environment=HOME=/
Environment=DRACUT_SYSTEMD=1
Environment=NEWROOT=/sysroot
WorkingDirectory=/
ExecStart=/bin/dracut-emergency
ExecStopPost=-/usr/bin/systemctl --fail --no-block default
Type=oneshot
StandardInput=tty-force
StandardOutput=inherit
StandardError=inherit
KillMode=process
IgnoreSIGPIPE=no

# Bash ignores SIGTERM, so we send SIGHUP instead, to ensure that bash
# terminates cleanly.
KillSignal=SIGHUP
I see that it runs /bin/dracut-emergency, so I look at that script:

# less -X dracut-emergency

Code: Select all

#!/bin/sh
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=sh

export DRACUT_SYSTEMD=1
if [ -f /dracut-state.sh ]; then
    . /dracut-state.sh 2>/dev/null
fi
type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh

source_conf /etc/conf.d

type plymouth >/dev/null 2>&1 && plymouth quit

export _rdshell_name="dracut" action="Boot" hook="emergency"

source_hook "$hook"


if getargbool 1 rd.shell -d -y rdshell || getarg rd.break -d rdbreak; then
    echo
    rdsosreport
    echo
    echo
    echo 'Entering emergency mode. Exit the shell to continue.'
    echo 'Type "journalctl" to view system logs.'
    echo 'You might want to save "/run/initramfs/rdsosreport.txt" to a USB stick or /boot'
    echo 'after mounting them and attach it to a bug report.'
    echo
    echo
    [ -f /etc/profile ] && . /etc/profile
    [ -z "$PS1" ] && export PS1="$_name:\${PWD}# "
    exec sh -i -l
else
    warn "$action has failed. To debug this issue add \"rd.shell rd.debug\" to the kernel command line."
    exit 1
fi

/bin/rm -f -- /.console_lock

exit 0
at this point, i'm lost. I don't see where it tells the rescue mode user what it is doing and if it should continue and prompt for option 1 and other options.

Can someone please help me point in the right direction?

Post Reply