QEMU/Linux guest

From Gentoo Wiki
< QEMU
Jump to: navigation, search

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

Configuration

Host

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

user $qemu-img create -f qcow2 GentooVM.img 15G

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.:

FILE GentooVM
#!/bin/sh
exec qemu-system-x86_64 -enable-kvm \
        -cpu host \
        -drive file=GentooVM.img,if=virtio \
        -net nic -net user,hostname=gentoovm \
        -m 256M \
        -monitor stdio \
        -name "Gentoo VM" \
        $@
Note
The above script uses the legacy syntax of -net.
-net nic -net user,hostname=gentoovm
could also be written as
-netdev user,id=vmnic,hostname=gentoovm -device virtio-net,netdev=vmnic

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

user $./GentooVM -boot d -cdrom install-amd64-minimal-20120621.iso

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

Guest

Kernel

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

KERNEL
Processor type and features  --->
    [*] Linux guest support --->
        [*] Enable Paravirtualization code
        [*] KVM Guest support (including kvmclock)
Device Drivers  --->
    Virtio drivers  --->
        <*>   PCI driver for virtio devices
    [*] Block devices  --->
        <*>   Virtio block driver
    [*] Network device support  --->
        <*>   Virtio network driver
    SCSI device support  --->
        [*] SCSI low-level drivers  --->
            [*]   virtio-scsi support

Hard drive

The VirtIO hard drive is mapped to /dev/vda.

GRUB

To install GRUB change your /boot/grub/device.map:

FILE /boot/grub/device.map
(hd0) /dev/vda

Also specify the device.map when setup GRUB to the MBR:

root #grub-install --device-map=/boot/grub/device.map /dev/vda

Optional Post Install Guest IPv6 Setup

For IPv6 networking see the IPv6 subarticle.