Change console port after boot

Rune Torgersen runet at innovsys.com
Sat Sep 15 06:28:18 EST 2007


Hi..

Does anybody know if there is a way to change the console port after
linux has started?

I have a serial port cosole (82xx, ttyCPM0), that is used for initial
console.
After the system is booted, there are times where I need to use that
serial port to talk to some equipment.
My problem is that I get output from kernel/init and other things that
have the console open also.

Right now I kill the login process on the serial port, set
/proc/sys/kernel/printk to "0 0 0 0" and try to find anything with
/dev/console open and kill them.

This does work, but not always. 
What I'd like to do is be able to shut off all output from /dev/console
and kernel so only /dev/ttyCPM0 works.

This is the script I use now:
#!/bin/sh

# turn off serial login shell
echo 0 0 0 0 > /proc/sys/kernel/printk

sed -ri "s/^(::askfirst)/#\1/; s|(^ttyCPM0::respawn:).*$|#\1-/bin/sh|;"
/etc/inittab
init -q

PIDS=`ps | sed -nr "s|^ *([0-9]+) .*[-/]sh *$|\1|p"`

for p in ${PIDS}
do
        #echo ${p}
        OUT=`ls -l /proc/${p}/fd/0 | grep console`

        #echo ${OUT}
        if [ "${OUT}" != "" ]
        then
                #echo send kill to pid ${p}
                kill -9 ${p}
        fi

        OUT=`ls -l /proc/${p}/fd/0 | grep ttyCPM0`

        #echo ${OUT}
        if [ "${OUT}" != "" ]
        then
                #echo send kill to pid ${p}
                kill -9 ${p}
        fi
done

sleep 1
echo "Use ~ to enter menu"
echo "~tm changes linefeed mode"
echo "~x  exits"
microcom -D/dev/ttyCPM0
echo 7 4 1 7 > /proc/sys/kernel/printk

# turn login shell back on
sed -ri "s|#(ttyCPM0)|\1|;" /etc/inittab
init -q


More information about the Linuxppc-embedded mailing list