* Use QEMU/KVM's paravirtualised console device for the backdoor.

This has the advantage that it doesn't depend on networking being
  up.
* Move common QEMU/KVM guest configuration to profiles/qemu-guest.nix.

svn path=/nixos/trunk/; revision=26421
This commit is contained in:
Eelco Dolstra 2011-03-18 12:38:22 +00:00
parent c52aeacf1a
commit be0fca5781
4 changed files with 16 additions and 9 deletions

View file

@ -125,8 +125,8 @@ sub start {
$ENV{USE_TMPDIR} = 1;
$ENV{QEMU_OPTS} =
"-no-reboot -monitor unix:./monitor -chardev socket,id=shell,path=./shell " .
"-device virtio-serial -device virtconsole,chardev=shell " .
($showGraphics ? "-serial stdio" : "-nographic");
$ENV{QEMU_NET_OPTS} = "guestfwd=tcp:10.0.2.6:23-chardev:shell";
$ENV{QEMU_KERNEL_PARAMS} = "hostTmpDir=$ENV{TMPDIR}";
chdir $self->{stateDir} or die;
exec $self->{startCommand};

View file

@ -0,0 +1,8 @@
# Common configuration for virtual machines running under QEMU (using
# virtio).
{ config, pkgs, ... }:
{
boot.initrd.kernelModules = [ "virtio_net" "virtio_pci" "virtio_blk" "virtio_balloon" "virtio_console" ];
}

View file

@ -24,10 +24,7 @@ in
config = {
jobs.backdoor =
{ # If the firewall is enabled, this job must start *after* the
# firewall, otherwise connection tracking won't know about
# this connection.
startOn = if config.networking.firewall.enable then "started firewall" else "ip-up";
{ startOn = "startup";
stopOn = "never";
script =
@ -37,8 +34,10 @@ in
export DISPLAY=:0.0
source /etc/profile
cd /tmp
echo "connecting to host..." > /dev/ttyS0
${pkgs.socat}/bin/socat tcp:10.0.2.6:23 exec:${rootShell} 2> /dev/ttyS0 # || poweroff -f
exec < /dev/hvc0 > /dev/hvc0 2> /dev/ttyS0
echo "connecting to host..." >&2
stty -F /dev/hvc0 raw # prevent nl -> cr/nl conversion
${pkgs.socat}/bin/socat stdio exec:${rootShell}
'';
respawn = false;

View file

@ -228,7 +228,7 @@ let
in
{
require = options;
require = [ options ../profiles/qemu-guest.nix ];
boot.loader.grub.device = mkOverride 50 "/dev/vda";
@ -236,7 +236,7 @@ in
# CIFS. Also use paravirtualised network and block devices for
# performance.
boot.initrd.availableKernelModules =
[ "cifs" "virtio_net" "virtio_pci" "virtio_blk" "virtio_balloon" "nls_utf8" ]
[ "cifs" "nls_utf8" ]
++ optional cfg.writableStore [ "aufs" ];
boot.extraModulePackages =