QEMU/Linux guest

From Gentoo Wiki
Jump to: navigation, search

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



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
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" \
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.



If you use genkernel do not build the VirtIO drivers as modules, compile them into the 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
    SCSI device support  --->
        [*] SCSI low-level drivers  --->
            [*]   virtio-scsi support
    [*] Network device support  --->
        [*] Network core driver support
            <*>   Virtio network driver

Hard drive

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


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.