From 1f8e6d48140b2f938dc381b922a935cb786a8318 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Sun, 13 Jun 2010 23:49:16 +0000 Subject: [PATCH] * The -smb flag in QEMU/KVM is unreliable: it doesn't work without the -no-kvm-irqchip flag, and on the Hydra machines only works on the rather old KVM 76. So as a workaround, don't use -smb, but use QEMU's "guestfwd" feature to forward 10.0.2.4:139 in the guest to a Unix domain socket on the host connected to Samba. * Use "cache=writeback" to improve performance a lot. * Use "werror=report" to make QEMU crash instead of hang if the host filesystem is full. svn path=/nixpkgs/trunk/; revision=22249 --- pkgs/build-support/vm/default.nix | 67 +++++++++++++++++++------------ 1 file changed, 41 insertions(+), 26 deletions(-) diff --git a/pkgs/build-support/vm/default.nix b/pkgs/build-support/vm/default.nix index a34c0fc77cad..8fef75e357a7 100644 --- a/pkgs/build-support/vm/default.nix +++ b/pkgs/build-support/vm/default.nix @@ -1,4 +1,4 @@ -{pkgs}: +{ pkgs }: with pkgs; @@ -7,15 +7,18 @@ rec { inherit (linuxPackages_2_6_32) kernel; - kvm = pkgs.kvm76; + kvm = pkgs.qemu_kvm; modulesClosure = makeModulesClosure { inherit kernel; - rootModules = ["cifs" "virtio_net" "virtio_pci" "virtio_blk" "virtio_balloon" "nls_utf8" "ext2" "ext3" "unix"]; + rootModules = [ "cifs" "virtio_net" "virtio_pci" "virtio_blk" "virtio_balloon" "nls_utf8" "ext2" "ext3" "unix" "sd_mod" "ata_piix" ]; }; + hd = "vda"; # either "sda" or "vda" + + initrdUtils = runCommand "initrd-utils" { buildInputs = [ nukeReferences ]; allowedReferences = [ "out" modulesClosure ]; # prevent accidents like glibc being included in the initrd @@ -47,8 +50,8 @@ rec { # Copy some other tools. cp ${bash}/bin/bash $out/bin cp ${module_init_tools}/sbin/insmod $out/bin/insmod - cp ${pkgs.nettools}/sbin/ifconfig $out/bin - cp ${pkgs.sysvinit}/sbin/halt $out/bin + cp ${nettools}/sbin/ifconfig $out/bin + cp ${sysvinit}/sbin/halt $out/bin # Run patchelf to make the programs refer to the copied libraries. for i in $out/bin/* $out/lib/*; do if ! test -L $i; then nuke-refs $i; fi; done @@ -65,8 +68,8 @@ rec { mknod ${dev}/null c 1 3 mknod ${dev}/zero c 1 5 mknod ${dev}/tty c 5 0 - . /sys/class/block/vda/uevent - mknod ${dev}/vda b $MAJOR $MINOR + . /sys/class/block/${hd}/uevent + mknod ${dev}/${hd} b $MAJOR $MINOR ''; @@ -123,25 +126,17 @@ rec { if test -z "$mountDisk"; then mount -t tmpfs none /fs else - mount -t ext2 /dev/vda /fs + mount -t ext2 /dev/${hd} /fs fi - + mkdir -p /fs/hostfs mkdir -p /fs/dev mount -o bind /dev /fs/dev - n=. - echo "mounting host filesystem..." - while true; do - if mount -t cifs //10.0.2.4/qemu /fs/hostfs -o guest,username=nobody; then - break - else - n=".$n" - test ''${#n} -le 10 || exit 1 - sleep 1 - echo "retrying..." - fi + for ((n = 0; n < 10; n++)); do + echo "mounting host filesystem, attempt $n..." + mount -t cifs //10.0.2.4/qemu /fs/hostfs -o guest,username=nobody && break done mkdir -p /fs/nix/store @@ -215,10 +210,10 @@ rec { qemuCommandLinux = '' - qemu-system-x86_64 -no-kvm-irqchip \ + qemu-system-x86_64 \ -nographic -no-reboot \ - -net nic,model=virtio -net user -smb / \ - -drive file=$diskImage,if=virtio,boot=on \ + -net nic,model=virtio -chardev socket,id=samba,path=$TMPDIR/samba -net user,guestfwd=tcp:10.0.2.4:139-chardev:samba \ + -drive file=$diskImage,if=virtio,boot=on,cache=writeback,werror=report \ -kernel ${kernel}/bzImage \ -initrd ${initrd}/initrd \ -append "console=ttyS0 panic=1 command=${stage2Init} tmpDir=$TMPDIR out=$out mountDisk=$mountDisk" \ @@ -229,12 +224,28 @@ rec { vmRunCommand = qemuCommand: writeText "vm-run" '' export > saved-env - PATH=${coreutils}/bin:${kvm}/bin:${samba}/sbin + PATH=${coreutils}/bin:${kvm}/bin diskImage=''${diskImage:-/dev/null} eval "$preVM" + cat > smb.conf <