Skip to content
Snippets Groups Projects

Try to find console device by major,minor numbers

Closed Valentin Vidic requested to merge vvidic/rootskel:console-device into master
@@ -63,6 +63,8 @@ preferred=
# for which no device file exists
kernelconsoles="$(cat /proc/consoles)"
# enable major:minor handling only on s390x for now
if [ "$(uname -m)" != "s390x" ]; then
for cons in $(echo "$kernelconsoles" | sed -n -r -e 's/(^.*) .*\((.*)\).*$/\1/p' )
do
log "Looking at console $cons from /proc/consoles"
@@ -77,6 +79,34 @@ do
log " $cons is preferred"
fi
done
else
for cons in $(echo "$kernelconsoles" | sed -n -r -e 's/(^.*) .*\((.*)\).*$/\1/p')
do
log "Looking at console $cons from /proc/consoles"
device="$cons"
if [ ! -e "/dev/$device" ]; then
# Console device does not exist, try to find it by major:minor numbers
# ttyS1 -W- (EC p ) 4:65
majorminor=$(echo "$kernelconsoles" | grep $cons | sed -n -r -e 's/.* ([0-9]+:[0-9]+)$/\1/p')
if [ "$majorminor" ] && [ -e "/sys/dev/char/$majorminor" ]; then
device=$(readlink "/sys/dev/char/$majorminor")
device=${device##*/}
fi
fi
status=$(echo "$kernelconsoles" | grep $cons | sed -n -r -e 's/(^.*) *.*\((.*)\).*$/\2/p' )
if [ -e "/dev/$device" ]; then
if [ $(echo "$status" | grep -o 'E') ]; then
consoles="${consoles:+$consoles$NL}$device"
log " Adding $cons (/dev/$device) to possible consoles list"
fi
# 'C' console is 'most prefered'.
if [ $(echo "$status" | grep -o 'C') ]; then
preferred="$device"
log " $cons (/dev/$device) is preferred"
fi
fi
done
fi
if [ -z "$consoles" ]; then
# Nothing found? Default to /dev/console.
Loading