This is Gentoo's testing wiki. It is a non-operational environment and its textual content is outdated.

Please visit our production wiki at https://wiki.gentoo.org

QEMU/Linux guest

From Gentoo Wiki (test)
< QEMU
Jump to:navigation Jump to: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 Gentoo-VM.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 start_Gentoo_VM.sh
#!/bin/bash
exec qemu-system-x86_64 -enable-kvm \
        -cpu host \
        -drive file=Gentoo-VM.img,if=virtio \
        -net nic -net user,hostname=Gentoo-VM \
        -m 256M \
        -monitor stdio \
        -name "Gentoo VM" \
        $@
Note
The above script uses the legacy syntax of -net.
-net nic -net user,hostname=Gentoo-VM
could also be written as
-netdev user,id=vmnic,hostname=Gentoo-VM -device virtio-net,netdev=vmnic

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

user $./start_Gentoo_VM.sh -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  --->
    [*] Block devices  --->
        <*>   Virtio block driver
    SCSI device support  --->
        [*] SCSI low-level drivers  --->
            [*]   virtio-scsi support
    [*] Network device support  --->
        [*] Network core driver support
            <*>   Virtio network driver
    Virtio drivers  --->
        <*>   PCI driver for virtio devices

Hard drive

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

GRUB

Note
The following might not be needed for the newer versions of grub. You may use grub-mkconfig normally and then install grub on /dev/vda without any options needed.

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.