I’m doing a course of system and network administration through Linux in a small company. Obviously, the choice for making virtual hosts and networks over which try the theory I taught fall on UML. To be exact, I found the Netkit project to be really promising (a joint work of several people from the Computer Networks Research Group of the University of Roma Tre and from the Linux User Group LUG Roma 3).
All the work is done at a remote server, which is big and fast enough to manage easily many virtual machines (and, most of all, which is reachable through Internet to make it easy for me to test the lesson on the same system on which it’ll be run ^_^). Netkit has many advantages, but by default, as UML does, links its terminal to an xterm.
I didn’t want to use X forwarding or stuff - especially because I run lessons on a Windows XP computer (sigh). So, I had dear putty at hand, and nothing more. Moreover, I wanted for my students to get the habit to use the terminal: they can easily learn to use graphical interfaces by themselves, but god knows how many times I have wished to have a competent person near me to tell me if it was possible to do this and that on a terminal faster when I began, and to discover those things after a lot of time. And if this all sounds to you like I’m a terminal zealot, well, I’m a terminal zealot :-).
So, I thought this setup. Accounts for every partecipant on the UNIX machine (luckily they are not a lot), a common account for making the exercises (an obvious account - username equal to password - but disabled to external access), and the screen utility to run the machines inside.
First problem. Try this:
mat@jericho:~$ su - exercises
Password:
exercises@jericho:~$ screen
Cannot open your terminal ‘/dev/pts/1′ - please check.
Why? because once the terminal device is given to a user - by login, ssh, or whichever mean, ownership is set accordingly. Simple to check:
exercises@jericho:~$ ls /dev/pts/1 -l
crw——- 1 mat tty 136, 1 May 9 00:03 /dev/pts/1
(Sometimes group users are given write permission - that is, users who are in the tty group can write each other messages by writing directly onto other’s consoles with simple “echo”)
So, the solution is simple:
mat@jericho:~$ chmod g+rw /dev/pts/1
mat@jericho:~$ chgrp exercises /dev/pts/1
mat@jericho:~$ ls /dev/pts/1 -l
crw-rw—- 1 mat exercises 136, 1 2007-05-09 00:07 /dev/pts/1
And if you try “screen” as user “exercises”, now it works fine.
The other problem was: how do I connect screen to UML machines? At first I tried a way I found many times on the net:
$ vstart -v –con0=pts star
After that, UML uses a pts, so connecting to /dev/ttyp?, where “?” is a number, gets it:
$ screen -S star /dev/ttyp0
Two problems with this approach:
- the name of the /dev/ttyp? is declared during boot. Netkit boot logs, even when verbose, are not verbose enough to include this information, so you have to guess. Not that it’s hard (first run, /dev/ttyp0, second run, /dev/ttyp1, etc…), but obviously this way you throw away security and get extra work every time you run a virtual machine (I assure you I’ve done it many times even for simple explanations)
- It didn’t work :-) - that is, screen interaction with tools like “less” was ugly, if pts was used. less didn’t understand the size of terminal or something like this, and it did a lot of mess. Try to explain a /sbin/ifconfig -a with some 6 interfaces when you can’t use “less” or “more”.
Ok, so what was the solution? very simple: do not use pts, but use standard input/output. To use standard I/O is told, in netkit, by “con0=this” (and not con0=fd:0,fd:1 as the UML command line would require). Now, the game was to run the netkit machine already inside a screen:
$ screen -S star -d -m vstart con0=this […]
the “-d -m” simply tells screen to start detached. At this point reconnecting to the started screen (screen -r star) gave satisfactory results, with less, more and the family working correctly.
