* 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:
parent
c52aeacf1a
commit
be0fca5781
|
@ -125,8 +125,8 @@ sub start {
|
||||||
$ENV{USE_TMPDIR} = 1;
|
$ENV{USE_TMPDIR} = 1;
|
||||||
$ENV{QEMU_OPTS} =
|
$ENV{QEMU_OPTS} =
|
||||||
"-no-reboot -monitor unix:./monitor -chardev socket,id=shell,path=./shell " .
|
"-no-reboot -monitor unix:./monitor -chardev socket,id=shell,path=./shell " .
|
||||||
|
"-device virtio-serial -device virtconsole,chardev=shell " .
|
||||||
($showGraphics ? "-serial stdio" : "-nographic");
|
($showGraphics ? "-serial stdio" : "-nographic");
|
||||||
$ENV{QEMU_NET_OPTS} = "guestfwd=tcp:10.0.2.6:23-chardev:shell";
|
|
||||||
$ENV{QEMU_KERNEL_PARAMS} = "hostTmpDir=$ENV{TMPDIR}";
|
$ENV{QEMU_KERNEL_PARAMS} = "hostTmpDir=$ENV{TMPDIR}";
|
||||||
chdir $self->{stateDir} or die;
|
chdir $self->{stateDir} or die;
|
||||||
exec $self->{startCommand};
|
exec $self->{startCommand};
|
||||||
|
|
8
modules/profiles/qemu-guest.nix
Normal file
8
modules/profiles/qemu-guest.nix
Normal 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" ];
|
||||||
|
}
|
|
@ -24,10 +24,7 @@ in
|
||||||
config = {
|
config = {
|
||||||
|
|
||||||
jobs.backdoor =
|
jobs.backdoor =
|
||||||
{ # If the firewall is enabled, this job must start *after* the
|
{ startOn = "startup";
|
||||||
# firewall, otherwise connection tracking won't know about
|
|
||||||
# this connection.
|
|
||||||
startOn = if config.networking.firewall.enable then "started firewall" else "ip-up";
|
|
||||||
stopOn = "never";
|
stopOn = "never";
|
||||||
|
|
||||||
script =
|
script =
|
||||||
|
@ -37,8 +34,10 @@ in
|
||||||
export DISPLAY=:0.0
|
export DISPLAY=:0.0
|
||||||
source /etc/profile
|
source /etc/profile
|
||||||
cd /tmp
|
cd /tmp
|
||||||
echo "connecting to host..." > /dev/ttyS0
|
exec < /dev/hvc0 > /dev/hvc0 2> /dev/ttyS0
|
||||||
${pkgs.socat}/bin/socat tcp:10.0.2.6:23 exec:${rootShell} 2> /dev/ttyS0 # || poweroff -f
|
echo "connecting to host..." >&2
|
||||||
|
stty -F /dev/hvc0 raw # prevent nl -> cr/nl conversion
|
||||||
|
${pkgs.socat}/bin/socat stdio exec:${rootShell}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
respawn = false;
|
respawn = false;
|
||||||
|
|
|
@ -228,7 +228,7 @@ let
|
||||||
in
|
in
|
||||||
|
|
||||||
{
|
{
|
||||||
require = options;
|
require = [ options ../profiles/qemu-guest.nix ];
|
||||||
|
|
||||||
boot.loader.grub.device = mkOverride 50 "/dev/vda";
|
boot.loader.grub.device = mkOverride 50 "/dev/vda";
|
||||||
|
|
||||||
|
@ -236,7 +236,7 @@ in
|
||||||
# CIFS. Also use paravirtualised network and block devices for
|
# CIFS. Also use paravirtualised network and block devices for
|
||||||
# performance.
|
# performance.
|
||||||
boot.initrd.availableKernelModules =
|
boot.initrd.availableKernelModules =
|
||||||
[ "cifs" "virtio_net" "virtio_pci" "virtio_blk" "virtio_balloon" "nls_utf8" ]
|
[ "cifs" "nls_utf8" ]
|
||||||
++ optional cfg.writableStore [ "aufs" ];
|
++ optional cfg.writableStore [ "aufs" ];
|
||||||
|
|
||||||
boot.extraModulePackages =
|
boot.extraModulePackages =
|
||||||
|
|
Loading…
Reference in a new issue