Commit be0fca57 authored by Eelco Dolstra's avatar Eelco Dolstra
Browse files

* 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
parent c52aeacf
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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};
+8 −0
Original line number Diff line number Diff line
# 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" ];
}
+5 −6
Original line number Diff line number Diff line
@@ -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;
+2 −2
Original line number Diff line number Diff line
@@ -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 =