Running Debian inside qemu using console

Introduction

qemu is good at running another OS inside Linux. One problem though is that packaged OS images and stock Debian installation still require an X server running on the host system (unless you're confident with the image and can login via ssh). So running qemu on a remote machine or one that doesnt have X installed is not possible. Thankfully, the qemu people offer a -nographic option and support for a virtual serial console. In the old days, a serial console would be attached via a null modem cable or a modem to a physical serial port (or parallel). It would then show bootloader and bootup messages and allow a remote login without any network connection being used. This is what I am going to do with qemu and a stock Debian Sarge image taken from http://www.freeoszoo.org. To get this working I first had to use the image in graphical mode and make changes to the configuration to enable serial console support. IMHO it would be nice to include these settings in images available on the net to ease use of qemu remotely or X free. So the checklist below provides all the necessary steps to get a Debian system running inside qemu. I can be started in a terminal window and does not require any X server support.


This is done using: Debian Sarge 3.1r0 for qemu Provided by Stefano Marinelli <marinell@cs.unibo.it> for the Free Os Zoo? (http://www.freeoszoo.org) 18/06/2005


Host system


Firewall rules:

        #qemu support
        $IPTABLES -t nat -A POSTROUTING -o ath0 -j MASQUERADE
        $IPTABLES -A FORWARD -i tun0 -s 0/0 -d 0/0 -j ACCEPT
        /bin/echo "1" >/proc/sys/net/ipv4/ip_forward

ath0 is my public interface, replace with eth0


DHCPD setup:

subnet 172.20.0.0 netmask 255.255.255.0 {
  range 172.20.0.2 172.20.0.254;
  option domain-name-servers 10.0.0.2;
  option domain-name "internal.example.org";
  option routers 172.20.0.1;
  option broadcast-address 172.20.0.255;
  default-lease-time 600;
  max-lease-time 7200;
}

10.0.0.2 is my nameserver

The dhcpd needs to be launched once the tun0 interface is up. If this is done via sudo then this means starting dhcpd while qemu is bootng the system.

Enable dhcpd for tun0 in /etc/default/dhcp3-server
INTERFACES="tun0 tun1"

qemu runs perfectly as a non privileged user. the user needs access to the tunnel device and to ifup command

/etc/sudoers

(username)    (hostname) = NOPASSWD: /etc/qemu-ifup,/sbin/ifconfig

Allow (username) to read/write to the tunel device (even create it if necessary):

mkdir -p /dev/net
mknod /dev/net/tun c 10 200
chgrp users /dev/net/tun
chmod g+w /dev/net/tun

Add (username) to users


Client system


Having everything in place startup the qemu system to make the changes so it will be able to run in -nographic mode.

qemu -hda sarge.img

Dont forget that if you want networking support during the configuration of the client system you need to start dhcpd while the client system is booting.


grub & boot configuration

stock debian kernels have support for console

copy the default boot stanza before any other stanzas, disable splashimage, and add console=tty0 console=ttyS0,9600n8 vga=normal to the kernel line:

/boot/grub/menu.lst

serial --unit=0 --speed=9600 --word=8 --parity=no --stop=1
terminal --timeout=10 --dumb serial console

title   serial
kernel  /boot/kernel.img root=/dev/rootdev ro console=tty0 console=ttyS0,9600n8 vga=normal
..

This should enable grub & kernel displaying msgs over console, if there is no console output will go to the normal screen/keyboard if attached


lilo config should be similiar, havent tested though: see http://www.tldp.org/HOWTO/Remote-Serial-Console-HOWTO/configure-kernel-lilo.html


Linux

in order to allow logins uncoment the T0 line and change 23 to 123 (doesn't hurt and maybe means we will have console support in single user mode) telinit q and can test if using a physical serial console

check ttyS0 is in /etc/securetty


If you used -snapshot dont forget to commit the changes to the image. Enter qemu and press ctrl-alt-2 and type commit

Now you are ready to boot the system without graphical support. Shutdown the client. Do killall qemu and launch the new image using
qemu -nographic -hda sarge.img

You should see


Press any key to continue.
Press any key to continue.
    GNU GRUB  version 0.95  (639K lower / 130048K upper memory)

-------------------------------------------------------------------
 0: serial
 1: Debian GNU/Linux, kernel 2.6.8-2-386
 2: Debian GNU/Linux, kernel 2.6.8-2-386 (recovery mode)
-------------------------------------------------------------------

      Use the ^ and v keys to select which entry is highlighted.
      Press enter to boot the selected OS, 'e' to edit the
      commands before booting, or 'c' for a command-line.

    Highlighted entry is 0:

Just let it boot and bring up your dhcpd whilst you're waiting.

Done!


Annoyances when using the console (&hints)

in grub press space to stop automatic boot, use ^, v to select what to boot (not really an annoyance)

keys dont work correctly, in vim use j k l to navigate

terminal mode is vt100 whatever that means

single mode: telinit 1 in the console should work and comes up with root prompt


Todo


comments & discussion

Leave a comment, start a discussion, or submit a patch


title last post author
xpqd anjvq Monday 20 August 2007 1:56:58 202.6.236.242

Post new
Title:
Reply:

Last edited on Sunday 14 August 2005 16:34:46.


PHP Warnings

lib/pear/DB/common.php:741: Notice[8]: Only variable references should be returned by reference

lib/DB_Session.php:148: Notice[8]: Only variables should be assigned by reference

lib/pear/DB/common.php:741: Notice[8]: Only variable references should be returned by reference

lib/WikiUser.php:77: Notice[8]: Only variables should be assigned by reference

lib/pear/DB/common.php:741: Notice[8]: Only variable references should be returned by reference

lib/pear/DB/common.php:741: Notice[8]: Only variable references should be returned by reference

lib/pear/DB/common.php:741: Notice[8]: Only variable references should be returned by reference

lib/pear/DB/common.php:741: Notice[8]: Only variable references should be returned by reference

lib/Template.php:120: Notice[8]: Only variables should be assigned by reference

lib/Template.php:122: Notice[8]: Only variables should be assigned by reference

lib/Template.php (In template 'html'):120: Notice[8]: Only variables should be assigned by reference

lib/Template.php (In template 'html'):122: Notice[8]: Only variables should be assigned by reference

lib/Template.php (In template 'html'):120: Notice[8]: Only variables should be assigned by reference

lib/Template.php (In template 'html'):122: Notice[8]: Only variables should be assigned by reference

lib/Template.php (In template 'body') (In template 'html'):120: Notice[8]: Only variables should be assigned by reference

lib/Template.php (In template 'body') (In template 'html'):122: Notice[8]: Only variables should be assigned by reference

lib/Template.php (In template 'top') (In template 'body') (In template 'html'):120: Notice[8]: Only variables should be assigned by reference

lib/Template.php (In template 'top') (In template 'body') (In template 'html'):122: Notice[8]: Only variables should be assigned by reference

lib/Template.php (In template 'body') (In template 'html'):120: Notice[8]: Only variables should be assigned by reference

lib/Template.php (In template 'body') (In template 'html'):122: Notice[8]: Only variables should be assigned by reference

lib/pear/DB/common.php (In template 'navbar') (In template 'body') (In template 'html'):741: Notice[8]: Only variable references should be returned by reference

lib/Template.php (In template 'body') (In template 'html'):120: Notice[8]: Only variables should be assigned by reference

lib/Template.php (In template 'body') (In template 'html'):122: Notice[8]: Only variables should be assigned by reference

lib/pear/DB/common.php (In template 'browse') (In template 'body') (In template 'html'):741: Notice[8]: Only variable references should be returned by reference

lib/WikiUser.php (In template 'browse') (In template 'body') (In template 'html'):671: Notice[1024]: googleLink: unknown preference

lib/CachedMarkup.php (In template 'browse') (In template 'body') (In template 'html'):464: Notice[8]: Only variables should be assigned by reference

lib/pear/DB/common.php (In template 'browse') (In template 'body') (In template 'html'):741: Notice[8]: Only variable references should be returned by reference

lib/pear/DB/common.php (In template 'browse') (In template 'body') (In template 'html'):741: Notice[8]: Only variable references should be returned by reference

lib/pear/DB/common.php (In template 'browse') (In template 'body') (In template 'html'):741: Notice[8]: Only variable references should be returned by reference

lib/pear/DB/common.php (In template 'browse') (In template 'body') (In template 'html'):741: Notice[8]: Only variable references should be returned by reference

lib/pear/DB/common.php (In template 'browse') (In template 'body') (In template 'html'):741: Notice[8]: Only variable references should be returned by reference

lib/pear/DB/common.php (In template 'browse') (In template 'body') (In template 'html'):741: Notice[8]: Only variable references should be returned by reference

lib/pear/DB/common.php (In template 'browse') (In template 'body') (In template 'html'):741: Notice[8]: Only variable references should be returned by reference

lib/pear/DB/common.php (In template 'browse') (In template 'body') (In template 'html'):741: Notice[8]: Only variable references should be returned by reference

lib/pear/DB/common.php (In template 'browse') (In template 'body') (In template 'html'):741: Notice[8]: Only variable references should be returned by reference

lib/CachedMarkup.php (In template 'browse') (In template 'body') (In template 'html'):464: Notice[8]: Only variables should be assigned by reference

lib/Template.php (In template 'browse') (In template 'body') (In template 'html'):120: Notice[8]: Only variables should be assigned by reference

lib/Template.php (In template 'browse') (In template 'body') (In template 'html'):122: Notice[8]: Only variables should be assigned by reference

lib/Template.php (In template 'browse') (In template 'body') (In template 'html'):120: Notice[8]: Only variables should be assigned by reference

lib/Template.php (In template 'browse') (In template 'body') (In template 'html'):122: Notice[8]: Only variables should be assigned by reference

Edit  | PageHistory | Diff  | PageInfo

lib/Template.php (In template 'browse') (In template 'body') (In template 'html'):120: Notice[8]: Only variables should be assigned by reference

lib/Template.php (In template 'browse') (In template 'body') (In template 'html'):122: Notice[8]: Only variables should be assigned by reference

lib/PagePerm.php (In template 'actionbar') (In template 'browse') (In template 'body') (In template 'html'):330: Notice[8]: Only variables should be assigned by reference