Re: Consoles and d-i
On Thu, Mar 24, 2011 at 11:56:10PM +0000, Jurij Smakov wrote:
> Hello,
>
> I've noticed that 2.6.38 kernel supports TIOCGDEV ioctl, which can be
> used to unambigously determine the real tty device corresponding to
> /dev/console [0]. I believe that by using this we can significantly
> simplify reopen-console-linux script in rootskel [1], and use the
> device from /var/run/console-device in finish-install's 90console [2],
> instead of the current method based on looking at the fds of the
> debian-installer binary.
>
> I expect that doing it this way will (at least) fix the installs for
> machines using sunhv.c serial drivers, for which the current rootskel
> detection does not work. It is quite possible though that I'm
> overlooking some important details, so if you know of reasons why such
> changes are not a good idea, please let me know.
I have now come up with a set of changes which implements it, see the
attached patch. I've tested it on my sparc box with a 2.6.38 netboot
image, with both regular and serial console.
Please let me know what you think, if there are no objections, I plan
to push it to the main repo and upload new rootskel next weekend (Apr
9-10).
Best regards,
--
Jurij Smakov jurij@wooyd.org
Key: http://www.wooyd.org/pgpkey/ KeyID: C99E03CC
>From d3f29283db9d58ad5b1702f66f9da15df6881526 Mon Sep 17 00:00:00 2001
From: Jurij Smakov <jurij@debian.org>
Date: Sun, 27 Mar 2011 20:14:56 +0100
Subject: [PATCH] Use TIOCGDEV ioctl to find real serial console device on Linux.
Kernels >= 2.6.38 support TIOCGDEV ioctl, which allows to unambigously
determine the real device corresponding to /dev/console. This change
adds support to using if for real console device detection to
rootskel.
---
debian/changelog | 2 ++
src/sbin/Makefile | 10 +++++++---
src/sbin/get-real-console-linux.c | 34 ++++++++++++++++++++++++++++++++++
src/sbin/reopen-console-linux | 8 +++++++-
4 files changed, 50 insertions(+), 4 deletions(-)
create mode 100644 src/sbin/get-real-console-linux.c
diff --git a/debian/changelog b/debian/changelog
index 487f4c0..e7e31f7 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -7,6 +7,8 @@ rootskel (1.94) UNRELEASED; urgency=low
[ Jurij Smakov ]
* Set DEB_HOST_ARCH_OS in src/Makefile to make sure that everything builds
correctly without help from dpkg-buildpackage.
+ * Switch to using TIOCGDEV ioctl for detection of the real console for
+ kernels >= 2.6.38.
-- Samuel Thibault <sthibault@debian.org> Sat, 19 Mar 2011 20:21:40 +0100
diff --git a/src/sbin/Makefile b/src/sbin/Makefile
index 64c91d3..dec554e 100644
--- a/src/sbin/Makefile
+++ b/src/sbin/Makefile
@@ -13,22 +13,26 @@ files_exec = \
ifeq ($(DEB_HOST_ARCH_OS),linux)
files_exec += \
- console-type
+ console-type \
+ get-real-console-linux
endif
console-type: console-type.c
gcc -Os -Wall console-type.c -o console-type
+get-real-console-linux:
+ gcc -Os -Wall get-real-console-linux.c -o get-real-console-linux
+
steal-ctty: steal-ctty.c
gcc -Os -Wall steal-ctty.c -o steal-ctty
ifeq ($(DEB_HOST_ARCH_OS),linux)
-build: console-type steal-ctty
+build: console-type get-real-console-linux steal-ctty
else
build: steal-ctty
endif
clean:
- rm -f console-type steal-ctty
+ rm -f console-type get-real-console-linux steal-ctty
include ../../Makefile.inc
diff --git a/src/sbin/get-real-console-linux.c b/src/sbin/get-real-console-linux.c
new file mode 100644
index 0000000..89c3a24
--- /dev/null
+++ b/src/sbin/get-real-console-linux.c
@@ -0,0 +1,34 @@
+/*
+ * Licensed under GPLv2
+ *
+ * Print out major:minor number of the real console device,
+ * using the TIOCGDEV ioctl (only works on kernels >= 2.6.38).
+ *
+ * Copyright (c) 2011 Jurij Smakov <jurij@debian.org>
+ */
+
+#include <stdio.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#define TIOCGDEV _IOR('T', 0x32, unsigned int)
+
+int main()
+{
+ int fd = 0;
+ unsigned int dev;
+
+ fd = open("/dev/console", O_WRONLY, 0);
+ if (fd < 0) {
+ perror("open");
+ return(1);
+ }
+ if (ioctl(fd, TIOCGDEV, &dev) < 0) {
+ perror("ioctl");
+ return(2);
+ }
+ printf("%d:%d\n", major(dev), minor(dev));
+ return(0);
+}
diff --git a/src/sbin/reopen-console-linux b/src/sbin/reopen-console-linux
index 4e65a13..9062a8a 100755
--- a/src/sbin/reopen-console-linux
+++ b/src/sbin/reopen-console-linux
@@ -14,9 +14,15 @@ if ! [ -f /var/run/console-device ]; then
console="$(dmesg -s 65535 |
sed -n -r -e 's/(.*\])? *console handover: boot \[.*\] -> real \[(.*)\]$/\2/p')"
;;
- *) # >=2.6.32
+ 2.6.3[234567]*)
console="$(dmesg -s 65535 |
sed -n -r -e 's/(.*\])? *console \[(.*)\] enabled, bootconsole disabled$/\2/p')"
+ ;;
+ *) # >= 2.6.38
+ console_major_minor="$(get-real-console-linux)"
+ console_raw="$(readlink "/sys/dev/char/${console_major_minor}")"
+ console="${console_raw##*/}"
+ ;;
esac
# Except if it is the wrong type...
--
1.7.2.3
Reply to: