I'd like to pass the host's /dev/urandom device through to a qemu/kvm virtual machine.

Note that /dev/urandom is not seekable, so it's not possible to pass it through as a block device using -hda, -fda, or -sda.

I would expect that I should be able to pass it through as a serial device, but I can't see to get that working. The guest needs to be able to read random data from some device in /dev where that random data is served by the host.

I am well aware of virtio-rng in modern versions of qemu/kvm and that's not quite what I'm looking for.

  • 3
    Why do you want to do this? The guest OS should have its own random number generator... – voretaq7 Oct 12 '12 at 15:50
  • I can see a way to do what you are asking but it seems terribly kludgy: cron script pulls a buffers worth of data on host OS into a file (cat), copy it into a file which has a filesystem (dd mke2fs cp), which is loop mounted and shared into kvm to its guest ... yuck. – adric Oct 12 '12 at 22:08

For /dev/urandom you don't need to do anything.

For /dev/random KVM provides a paravirtualized random number generator to its (Linux) guests. This allows guests to use the host's entropy pool. To use it, make sure that HW_RANDOM_VIRTIO is set in your guest kernel configuration.

  • Read the first paragraph, then. – Michael Hampton Oct 12 '12 at 20:29
  • Okay, so virtio-rng is a module. It loads via modprobe. Now what? Should that create a new device, or just populate /dev/random? – Dustin Kirkland Oct 12 '12 at 20:50
  • 1
    Sorry, but when you ask for something that sounds like a very bad idea here, you are going to be asked about it, and should be prepared to justify it. We have a very strong culture of "do it right or not at all" here. – Michael Hampton Oct 16 '12 at 18:42
  • 2
    The question asks, "Is it possible..." to do something very specific. I've read the documentation. I've contacted the QEMU upstream developers. I haven't found the answer I'm looking for, and so I turned to StackExchange. If the answer to my question is "no", and that can be justified, I'm perfectly fine with that. I'll gladly +1 that, and select as the correct answer. – Dustin Kirkland Oct 17 '12 at 2:09
  • 2
    Again, that's because you're almost certainly asking the wrong question and need to rethink what you're doing. – Michael Hampton Oct 17 '12 at 11:16

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.