QEMU/Linux guest

This article describes the setup of a Gentoo Linux guest using QEMU.

Host
To create a disk image for the virtual machine, run:

Download a minimal Gentoo LiveCD from here.

Since QEMU requires a lot of options, it would be a good idea to put them into a shell script, e.g.:

Change the path to your disk image in the script. You can add more options when calling the script. To boot the disk image, run:

Install the guest per the Gentoo Handbook. See the guest section for optimum support. After the installation start the script without the additional options.

Headless server
If running on a headless server, you will need to tweak the settings a bit

and when prompted at boot time to select the kernel, you should input

Hard drive
The VirtIO hard drive is mapped to. Where the handbook refers to, always use when configuring the guest.

Kernel
If you use genkernel do not build the VirtIO drivers as modules, compile them into the kernel.

As an alternative, use these commands after emerging the kernel sources:

GRUB
For a minimal grub BIOS install:

Optional: to make the guest work in the headless mode, add these lines:

and uncomment the following:

Install grub on the guest disk:

Configure grub for the kernel build earlier:

Expose images to LAN
Sometimes it is required that the image should get a proper IP address on the LAN network to allow other peers to access it. Such a configuration is possible by using an existing network bridge and telling the machine to use it.

Assuming that there exists a bridge called  on the machine, the following configuration exposes the image to the LAN.

Optional post install guest IPv6 setup
For IPv6 networking see the IPv6 subarticle.

Run images as service
To conveniently configure, start and stop a Linux (or any other) guest, check out this great init script.

Mount guest image
To access the guest disk from the host (and e.g. chroot into the guest), use a "Network Block Device":

Make any changes required and clean up:

Boot hangs at syslog-ng
If the guest boots slow, or if the boot hangs on  or there are syslog messages like   or   (12 seconds after booting), this is likely due to the lack of entropy. A way to fix this is to enable the "VirtIO Random Number Generator support" (HW_RANDOM_VIRTIO=y) in the guest kernel and boot with the QEMU virtio-rng-pci device.

Another way to solve this is to enable "Trust the CPU manufacturer to initialize Linux's CRNG" (RANDOM_TRUST_CPU=y) in the guest kernel. However, there are security concerns with this approach.