isirc/linuxrc

91 lines
1.5 KiB
Bash
Executable File

#!/bin/sh
QUITE=false
log() {
if [ "X$QUITE" != "Xtrue" ]
then
echo "$*"
fi
}
err() {
echo "$*" >&2
}
if [ "x${1}x" != "x-rx" ]
then
exec </dev/console >/dev/console 2>&1
log "### ISIRD ###"
PATH=/bin
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"
vgscan --mknodes --ignorelockingfailure
vgchange --ignorelockingfailure -P -a y
if cmdline -c isirdsh
then
log " start shell"
exec sh
fi
else
log " returned"
fi
log " detect cmdline options..."
ROOT="$(cmdline -c root)"
log " root: #{ROOT}"
FLAGS="$(cmdline -c rootflags)"
log " flags: ${FLAGS}"
if cmdline -c ro
then
FLAGS="${FLAGS},ro"
elif cmdline -c rw
then
FLAGS="${FLAGS},rw"
fi
log " flags: ${FLAGS}"
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!"
exec sh
fi
if ! test -d /mnt/initrd || mkdir /mnt/initrd
then
err "/initrd doesn't exist on root!"
exec sh
fi
log " Change to new root"
cd /mnt
if ! pivot_root . initrd
then
err "Can't pivot root!"
cd /
exec sh
fi
log " OK :)"
export LD_LIBRARY_PATH="/initrd/lib"
LD_SO="${LD_LIBRARY_PATH}/ld-linux.so.2"
${LD_SO} /initrd/bin/ls /mnt/dev/*
echo 0x0100 > /initrd/proc/sys/kernel/real-root-dev
${LD_SO} /initrd/bin/umount -n /initrd/proc
exit 0