isirc/isirc
Denis Knauf a09b427d1c new flags and lvm
isirc:
	lvm instead symlinks (vgscan, ...) will be called with --sysinit.

flags:
	NOSEC: default, on failure, isirc crashes and no shell will start.
		but NOSEC will allow isirc to start a shell for debugging.
		if you have a secure grub-config and nobody should be able to start
		a root-shell, this will be default. else NOSEC is interesting for
		debugging.
	init: yes, init=/bin/sh will be possible. NOSEC is not needed.
	isirdsh: start a shell before mounting. needs NOSEC.
	ISIRDSH: start a shell after mounting and before switch root. needs NOSEC.
2012-08-18 00:20:03 +02:00

77 lines
1.3 KiB
Bash
Executable file

#!/bin/sh
PATH=/bin
export PATH
QUITE=${QUITE:-false}
NOSEC=false
log() {
[ "X$QUITE" != "Xtrue" ] && echo "$*"
}
err() {
echo "$*" >&2
}
if [ "x${1}x" != "x-rx" ]
then
exec </dev/console >/dev/console 2>&1
log "### ISIRD ###"
cd /
log " mount proc and sysfs and / as rw"
mount -t proc proc /proc
mount -t sysfs sysfs /sys
mount -o remount,rw /
log " mdev"
mdev -s
log " activate volume groups"
lvm vgscan --mknodes --sysinit
lvm vgchange --sysinit -P -a y
if cmdline -c NOSEC
then
NOSEC=true
fi
if [ Xtrue = "X$NOSEC" ] && cmdline -c isirdsh
then
log " start shell"
exec sh
fi
else
log " returned"
fi
ROOT="$(cmdline -c root)"
FLAGS="$(cmdline -c rootflags)"
if cmdline -c ro
then FLAGS="${FLAGS},ro"
elif cmdline -c rw
then FLAGS="${FLAGS},rw"
fi
FSTYPE="$(cmdline -c rootfstype)"
FSTYPE="${FSTYPE:-auto}"
log " umount sysfs"
umount /sys
FLAGS="${FLAGS#,}"
log " mount ${ROOT} as ${FSTYPE} with ${FLAGS}"
if ! mount -o "${FLAGS}" -t "${FSTYPE}" "${ROOT}" /mnt
then
err "Can't mount root!"
[ Xtrue = "X$NOSEC" ] && exec sh
fi
# ISIRDSH -> shell for debugging, testing, what ever...
if [ Xtrue = "X$NOSEC" ] && cmdline -c ISIRDSH
then
exec sh
fi
INIT="$(cmdline -c init)"
INIT="${INIT:-/sbin/init}"
cd /mnt
log " Change to new root"
exec switch_root /mnt "$INIT"