vm/windows: Implement and use "xchg" share.
This now finally introduces our xchg share and also uses it for exchanging state while suspending a VM. However, accessing the _real_ Nix store still isn't possible because we're shadowing the directory in the initrd. Signed-off-by: aszlig <aszlig@redmoonstudios.org>
This commit is contained in:
parent
0ce1fd07fe
commit
fedf13e6cf
@ -36,13 +36,17 @@ let
|
|||||||
ifconfig lo up
|
ifconfig lo up
|
||||||
ifconfig eth0 up 192.168.0.2
|
ifconfig eth0 up 192.168.0.2
|
||||||
|
|
||||||
mkdir -p /nix/store /etc /var/run /var/log
|
mkdir -p /xchg /nix/store /etc /var/run /var/log
|
||||||
|
|
||||||
cat > /etc/passwd <<PASSWD
|
cat > /etc/passwd <<PASSWD
|
||||||
root:x:0:0::/root:/bin/false
|
root:x:0:0::/root:/bin/false
|
||||||
nobody:x:65534:65534::/var/empty:/bin/false
|
nobody:x:65534:65534::/var/empty:/bin/false
|
||||||
PASSWD
|
PASSWD
|
||||||
|
|
||||||
|
mount -t 9p \
|
||||||
|
-o trans=virtio,version=9p2000.L,msize=262144,cache=loose \
|
||||||
|
xchg /xchg
|
||||||
|
|
||||||
mount -t 9p \
|
mount -t 9p \
|
||||||
-o trans=virtio,version=9p2000.L,msize=262144,cache=loose \
|
-o trans=virtio,version=9p2000.L,msize=262144,cache=loose \
|
||||||
store /nix/store
|
store /nix/store
|
||||||
@ -59,6 +63,8 @@ let
|
|||||||
|
|
||||||
shellEscape = x: "'${lib.replaceChars ["'"] [("'\\'" + "'")] x}'";
|
shellEscape = x: "'${lib.replaceChars ["'"] [("'\\'" + "'")] x}'";
|
||||||
|
|
||||||
|
loopForever = "while :; do ${coreutils}/bin/sleep 1; done";
|
||||||
|
|
||||||
initScript = writeScript "init.sh" (''
|
initScript = writeScript "init.sh" (''
|
||||||
#!${stdenv.shell}
|
#!${stdenv.shell}
|
||||||
${coreutils}/bin/mkdir -p /etc/samba /etc/samba/private /var/lib/samba
|
${coreutils}/bin/mkdir -p /etc/samba /etc/samba/private /var/lib/samba
|
||||||
@ -77,6 +83,11 @@ let
|
|||||||
path = /nix/store
|
path = /nix/store
|
||||||
read only = no
|
read only = no
|
||||||
guest ok = yes
|
guest ok = yes
|
||||||
|
|
||||||
|
[xchg]
|
||||||
|
path = /xchg
|
||||||
|
read only = no
|
||||||
|
guest ok = yes
|
||||||
CONFIG
|
CONFIG
|
||||||
|
|
||||||
${samba}/sbin/nmbd -D
|
${samba}/sbin/nmbd -D
|
||||||
@ -92,7 +103,7 @@ let
|
|||||||
done
|
done
|
||||||
echo " success."
|
echo " success."
|
||||||
# Loop forever, because this VM is going to be killed.
|
# Loop forever, because this VM is going to be killed.
|
||||||
while :; do ${coreutils}/bin/sleep 1; done
|
${loopForever}
|
||||||
'' else ''
|
'' else ''
|
||||||
echo -n "Waiting for Windows VM to become available..."
|
echo -n "Waiting for Windows VM to become available..."
|
||||||
while ! ${netcat}/bin/netcat -z 192.168.0.1 22; do
|
while ! ${netcat}/bin/netcat -z 192.168.0.1 22; do
|
||||||
@ -108,6 +119,10 @@ let
|
|||||||
-l Administrator \
|
-l Administrator \
|
||||||
192.168.0.1 -- ${shellEscape command}
|
192.168.0.1 -- ${shellEscape command}
|
||||||
|
|
||||||
|
${lib.optionalString (suspendTo != null) ''
|
||||||
|
${coreutils}/bin/touch /xchg/suspend_now
|
||||||
|
${loopForever}
|
||||||
|
''}
|
||||||
${busybox}/sbin/poweroff -f
|
${busybox}/sbin/poweroff -f
|
||||||
''));
|
''));
|
||||||
|
|
||||||
@ -123,6 +138,7 @@ let
|
|||||||
"-nographic"
|
"-nographic"
|
||||||
"-no-reboot"
|
"-no-reboot"
|
||||||
"-virtfs local,path=/nix/store,security_model=none,mount_tag=store"
|
"-virtfs local,path=/nix/store,security_model=none,mount_tag=store"
|
||||||
|
"-virtfs local,path=$XCHG_DIR,security_model=none,mount_tag=xchg"
|
||||||
"-kernel ${modulesClosure.kernel}/bzImage"
|
"-kernel ${modulesClosure.kernel}/bzImage"
|
||||||
"-initrd ${initrd}/initrd"
|
"-initrd ${initrd}/initrd"
|
||||||
"-append \"${kernelAppend}\""
|
"-append \"${kernelAppend}\""
|
||||||
@ -147,6 +163,7 @@ let
|
|||||||
});
|
});
|
||||||
|
|
||||||
preVM = ''
|
preVM = ''
|
||||||
|
XCHG_DIR="$(${coreutils}/bin/mktemp -d nix-vm.XXXXXXXXXX --tmpdir)"
|
||||||
QEMU_VDE_SOCKET="$(pwd)/vde.ctl"
|
QEMU_VDE_SOCKET="$(pwd)/vde.ctl"
|
||||||
MONITOR_SOCKET="$(pwd)/monitor"
|
MONITOR_SOCKET="$(pwd)/monitor"
|
||||||
${vde2}/bin/vde_switch -s "$QEMU_VDE_SOCKET" &
|
${vde2}/bin/vde_switch -s "$QEMU_VDE_SOCKET" &
|
||||||
@ -154,20 +171,23 @@ let
|
|||||||
UNIX-CONNECT:$QEMU_VDE_SOCKET/ctl,retry=20
|
UNIX-CONNECT:$QEMU_VDE_SOCKET/ctl,retry=20
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
bgBoth = lib.optionalString (suspendTo != null) " &";
|
||||||
|
|
||||||
vmExec = if installMode then ''
|
vmExec = if installMode then ''
|
||||||
${vmTools.qemuProg} ${controllerQemuArgs} &
|
${vmTools.qemuProg} ${controllerQemuArgs} &
|
||||||
${vmTools.qemuProg} ${cygwinQemuArgs}
|
${vmTools.qemuProg} ${cygwinQemuArgs}${bgBoth}
|
||||||
'' else ''
|
'' else ''
|
||||||
${vmTools.qemuProg} ${cygwinQemuArgs} &
|
${vmTools.qemuProg} ${cygwinQemuArgs} &
|
||||||
${vmTools.qemuProg} ${controllerQemuArgs}
|
${vmTools.qemuProg} ${controllerQemuArgs}${bgBoth}
|
||||||
'' + lib.optionalString (suspendTo != null) ''
|
'' + lib.optionalString (suspendTo != null) ''
|
||||||
|
while ! test -e "$XCHG_DIR/suspend_now"; do sleep 1; done
|
||||||
${socat}/bin/socat - UNIX-CONNECT:$MONITOR_SOCKET <<CMD
|
${socat}/bin/socat - UNIX-CONNECT:$MONITOR_SOCKET <<CMD
|
||||||
stop
|
stop
|
||||||
migrate_set_speed 4095m
|
migrate_set_speed 4095m
|
||||||
migrate "exec:${gzip}/bin/gzip -c > '${suspendTo}'"
|
migrate "exec:${gzip}/bin/gzip -c > '${suspendTo}'"
|
||||||
quit
|
quit
|
||||||
CMD
|
CMD
|
||||||
wait %%
|
wait %-
|
||||||
'';
|
'';
|
||||||
|
|
||||||
in writeScript "run-cygwin-vm.sh" ''
|
in writeScript "run-cygwin-vm.sh" ''
|
||||||
|
@ -21,8 +21,11 @@ let
|
|||||||
"set -e"
|
"set -e"
|
||||||
"net config server /autodisconnect:-1"
|
"net config server /autodisconnect:-1"
|
||||||
"net use S: '\\\\192.168.0.2\\nixstore' /persistent:yes"
|
"net use S: '\\\\192.168.0.2\\nixstore' /persistent:yes"
|
||||||
|
"net use X: '\\\\192.168.0.2\\xchg' /persistent:yes"
|
||||||
"mkdir -p /nix/store"
|
"mkdir -p /nix/store"
|
||||||
"mount -o bind /cygdrive/s /nix/store"
|
"mount -o bind /cygdrive/s /nix/store"
|
||||||
|
"mkdir -p /tmp/xchg"
|
||||||
|
"mount -o bind /cygdrive/x /tmp/xchg"
|
||||||
];
|
];
|
||||||
suspendTo = "state.gz";
|
suspendTo = "state.gz";
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user