Getting Ctrl-C to work with UML shell in Debian

by Jarno Elonen <elonen@iki.fi>, 2007-08

Today at work we tried to configure some UML (User Mode Linux) virtual machines and ran into problems with break command (Control-C); it didn't work at all in the console that opens when you run the linux command (UML startup).

The problem seems to be that by default the command connects to the "main console" of linux, which apparently loses the session control commands (like ctrl-c) on real Linux as well, so this is not really a UML specific bug/feature.

We finally solved the problem by redirecting, from command line, UML's main console to null, opened a login shell to a virtual serial port in the UML side and redirected the port's input and output to the host machines stdin/stdout. There are no doubt other solutions but this is how we did it.

The drawback of this setup is that the kernel messages don't show up in the output, but they can of course be seen through dmesg, so no big loss there.

UML startup command (on host side):

$ linux con=null ssl0=fd:0,fd:1

Here the con=null part discards console output, ssl0 means ttyS0 in the UML, fd:0 means file descriptor 0 on host side, i.e. stdin, and fd:1 is stdout.

As a side note, we first tried to forward the ssl0 to a port on the host and connect to it. It didn't work, apparently because the UML executable wanted to put telnetd between the raw TCP port and the virtual serial line, but couldn't find /usr/sbin/in.telnetd. Installing the `telnetd package on the host would probably have solved the problem but it didn't seem like such a good idea (and neither did the open TCP port, really).

Relevant excerpt from /etc/inittab configuration (on UML side):

#0:1235:respawn:/sbin/getty 38400 console linux
#1:2345:respawn:/sbin/getty 38400 tty1
#2:23:respawn:/sbin/getty 38400 tty2
#3:23:respawn:/sbin/getty 38400 tty3
#4:23:respawn:/sbin/getty 38400 tty4
#5:23:respawn:/sbin/getty 38400 tty5
#6:23:respawn:/sbin/getty 38400 tty6

# Example how to put a getty on a serial line (for a terminal)
#
T0:23:respawn:/sbin/getty -L ttyS0 38400 vt100
#T1:23:respawn:/sbin/getty -L ttyS1 9600 vt100

(Here we have commented out the first line, commented in the "t0:23" line and changed the baud rate of ttyS0 to 38400.)

We also had to create the serial device file in the UML:

$ cd /dev
$ ./MAKEDEV ttyS0