User:Egberts/Drafts/QEMU/Linux guest

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

Kernel Configuration
As a demonstration of completeness of configuration settings for the Linux kernel, the kernel configuration file will be initialized to tinyconfig which is the smallest buildable Linux kernel (but not necessarily the bootable or functional one).

Now blow away the .config with the smallest default setting possible, execute:

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.

By using SLAB over SLUB, the level of kernel effort during lookaside page translation is reduced by 2-level of pointer indirections for each page read; SLAB is generally faster for a guest OS but at the expense of introducing CPU-jitter at application level.

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

* Checking your configfile (/etc/syslog-ng/syslog-ng.conf)

or there are syslog messages like

[   1.264763] random: dbus-deamon: uninitialized urandom read (12 bytes read)

or [  12.667558] random: crng init done

about 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) kernel configuration in the guest VM 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 kernel configuration inside the guest VM. However, there are security concerns with this approach.

VM shutdown problems
Host control scripts may send a  message to the virtual machine in order to shut it down. For this to work properly, ACPI functionality on the guest is necessary. Also, ACPI daemon should be installed and running on the guest.

Firmware hang
If the following lines were the last breath of a failed Gentoo boot:

```console [ 0.95951] Loading firmware: regulatory.db [  0.95980] platform regulatory.0: Direct firmware load for regulatory.db ``` then the next line (that is missing) is your video driver bootup failed.

Workaround: Go back to the `virt-manager` `View->Detail` submenu and change to Video QXL option from Video Virtio.