I'd like to do what is mentioned here: https://wiki.archlinux.org/index.php/QEMU#Mounting_a_partition_of_the_guest_on_the_host - essentially mount a partition directly on the VM - this is so I can use mmap on the mount - (which 9p does not seem to support).

However I'm not sure of the relevant config for the nix module(?) here https://github.com/NixOS/nixpkgs/blob/b0df5a6816b644c2e0b6ebcde6ad0784b07205e0/nixos/modules/virtualisation/qemu-vm.nix to configure this. I'm actually using https://github.com/Mic92/nixos-shell though which in turn seems to use the referenced module/file.

Trying something like:

    extraMounts = {
      "/test" = {
        target = /dev/sdc;
        cache = "none";

results in an error of:

qemu-system-x86_64: -virtfs local,path=/dev/sdc,security_model=none,mount_tag=a457b9c00b7152b02ceea27e7fe1a07: cannot initialize fsdev 'a457b9c00b7152b02ceea27e7fe1a07': failed to open '/dev/sdc': Not a directory

It seems I need to set a -hda parameter, but I don't see any option in the nix module for this.


Solution found here: https://github.com/Mic92/nixos-shell/issues/14

I had to set an environment variable: QEMU_OPTS="-hdc /dev/disk/by-uuid/836d83ab-cba5-4eb4-a7c8-09911cd67403"

Which gets referenced here:

      # Start QEMU.
      exec ${qemuBinary qemu} \
          -name ${vmName} \
          -m ${toString config.virtualisation.memorySize} \
          -smp ${toString config.virtualisation.cores} \
          -device virtio-rng-pci \
          ${concatStringsSep " " config.virtualisation.qemu.networkingOptions} \
          -virtfs local,path=/nix/store,security_model=none,mount_tag=store \
          -virtfs local,path=$TMPDIR/xchg,security_model=none,mount_tag=xchg \
          -virtfs local,path=''${SHARED_DIR:-$TMPDIR/xchg},security_model=none,mount_tag=shared \
          ${drivesCmdLine config.virtualisation.qemu.drives} \
          ${toString config.virtualisation.qemu.options} \
          $QEMU_OPTS \

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.