Is it possible to pass /dev/urandom through from the host to a qemu/kvm guest?

Dustin Kirkland asked:

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.

My answer:

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.

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.