Commit 6cf8864a authored by Ryan Jackson's avatar Ryan Jackson
Browse files

Dynamically add lines to inittab for serial consoles

Modified /init to parse /proc/cmdline for console devices.  Each
'console=' parameter is parsed and each serial device (ttyS* or
ttyUSB* for now) specified is used to generate an /etc/inittab entry
that starts a getty on that device.  The baud rate is parsed as well,
but defaults to 115200 if not specifed.  Parity and data/stop bits are
assumed to be N-8-1.

The specified device is also added to /etc/securetty if not already
present.
parent 8afb84d4
......@@ -21,8 +21,10 @@
tty1::respawn:/sbin/getty 38400 tty1
tty2::respawn:/sbin/getty 38400 tty2
# Put a getty on the serial port
ttyS0::respawn:/sbin/getty -L ttyS0 115200 vt100
# DO NOT SPECIFY ANY SERIAL CONSOLES HERE !!!
# The '/init' script will automatically add
# lines for any consoles you pass on the kernel
# command line, so just specify them there.
# Logging junk
#null::sysinit:/bin/touch /var/log/messages
......
#! /bin/sh
# Parse /proc/cmdline for any serial console devices to add
# to /etc/inittab. Also add the specified devices to
# /etc/securetty if necessary
mount -n -t proc none /proc
for token in `cat /proc/cmdline`; do
case $token in
console=*) ;;
*) continue ;;
esac
device=${token##*=}
device=${device%%,*}
options=${token##*,}
[ "$options" = "$token" ] && options=""
case $device in
ttyS*|ttyUSB*) ;;
*) continue ;;
esac
# Right now we assume no parity, 8 data bits, 1 stop bit
# since other configurations are generally unlikely these
# days.
speed=`echo $options | sed 's/^\([0-9]*\).*$/\1/'`
[ -z "$speed" ] && speed=115200
echo "$device::respawn:/sbin/getty -L $device $speed vt100" >> /etc/inittab
if ! grep "^$device$" /etc/securetty > /dev/null 2>&1; then
echo $device >> /etc/securetty
fi
done
umount -n /proc
mkdir -p /newroot
mount -t tmpfs none /newroot
mount -n -t tmpfs none /newroot
tar cf - `ls / | grep -v newroot` | (cd newroot; tar xf-)
cd /newroot
exec switch_root -c /dev/console . /sbin/init $@
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment