Running an x86 Yocto Linux image under QEMU KVM: Difference between revisions

From Yocto Project
Jump to navigationJump to search
(Created page with "== Host OS preparation (VM manager host OS) == 1. Enable KVM on the host machine, according to the guide below: https://wiki.yoctoproject.org/wiki/How_to_enable_KVM_for_Poky_qe...")
 
No edit summary
 
(28 intermediate revisions by 2 users not shown)
Line 1: Line 1:
== Host OS preparation (VM manager host OS) ==
== Host OS preparation (VM manager host OS) ==
Steps:
   
   
1. Enable KVM on the host machine, according to the guide below:
1.[https://wiki.yoctoproject.org/wiki/How_to_enable_KVM_for_Poky_qemu Enable KVM] on the host machine
https://wiki.yoctoproject.org/wiki/How_to_enable_KVM_for_Poky_qemu
   
   
2. Enable vhost-net to mitigate overheads on virtualization environment.
2. Enable on host OS vhost-net virtio networking accelerator to mitigate overhead on QEMU virtualization environment.
Load vhost-net module on KVM Host.
<br/>Load vhost_net module on KVM Host.
[root@dlp ~]#modprobe vhost_net
ubik@sentry:~$ sudo modprobe vhost_net
[root@dlp ~]#lsmod | grep vhost
ubik@sentry:~$ lsmod | grep vhost
The result of running the commands should be similar to the following:
vhost_net              32359  0
macvtap                18528  1 vhost_net
 
In order for an user to use vhost-net module enter the following commands:
sudo addgroup --system vhost-net
sudo adduser $USER vhost-net
sudo chown root:vhost-net /dev/vhost-net
sudo chmod 0660 /dev/vhost-net
 
Modify /etc/modules so that vhost_net module is automatically loaded at boot time:
sudo vim /etc/modules
For example:
<br/>File: /etc/modules
<br/>Content:
# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
   
   
vhost_net 24241 0
lp
macvtap 7867 1 vhost_net
rtc
tun16825 3 vhost_net
vhost_net
 
Basically, follow the same guide as for enabling KVM on the host (step 1.), but replace kvm with vhost_net
On a system that runs udev, you will probably need to add the following line somewhere in your udev configuration so it will automatically give the right group to the newly created device.
<br/>For example:
<br/>File: /etc/udev/rules.d/40-permissions.rules
<br/>Content:
 
KERNEL=="vhost-net", GROUP="vhost-net", MODE="0660"
 
Restart udev:
ubik@sentry:~$ sudo restart udev
[sudo] password for ubik:
udev start/running, process 28404
 
<b>Note</b>
* You need log out then log in the non-root user to take the effect
   
   
3. Start the VM using the line below:
3. Start the VM using the line below:
   
   
ubik@sentry:~/yoctoproject/build$ sudo kvm -kernel /home/ubik/yoctoproject/build/tmp/deploy/images/bzImage-qemux86.bin -net nic,model=virtio -net tap,vlan=0,ifname=tap0,script=no,downscript=no,vhost=on -drive file=/home/ubik/yoctoproject/build/tmp/deploy/images/core-image-core-qemux86.ext3,if=virtio -show-cursor -usb -usbdevice wacom-tablet -vga vmware -no-reboot -enable-kvm -cpu host -m 128 --append "vga=0 root=/dev/vda rw mem=128M ip=192.168.7.2::192.168.7.1:255.255.255.0 oprofile.timer=1 "
ubik@sentry:~/yoctoproject/build$ sudo kvm -kernel /home/ubik/yoctoproject/build/tmp/deploy/images/bzImage-qemux86.bin -net nic,model=virtio -net \
    tap,vlan=0,ifname=tap0,script=no,downscript=no,vhost=on -drive file=/home/ubik/yoctoproject/build/tmp/deploy/images/core-image-core-qemux86.ext3,if=virtio \
KVM version:
    -show-cursor -usb - usbdevice wacom-tablet -vga vmware -no-reboot -enable-kvm -cpu host -m 128 --append "vga=0 root=/dev/vda rw mem=128M \
ubik@sentry:~/yoctoproject/build$ kvm --version
    ip=192.168.7.2::192.168.7.1:255.255.255.0 oprofile.timer=1 "  
QEMU emulator version 1.0 (qemu-kvm-1.0), Copyright (c) 2003-2008 Fabrice Bellard
   
   
This is an example of running a virtualized Yocto image, with KVM active, cpu host features exported in the Yocto VM, paravirtualization enabled, and using virtio interfaces for disk access and networking.
This is an example of running a virtualized Yocto image, with KVM active, cpu host features exported in the Yocto VM, paravirtualization enabled, and using virtio interfaces for disk access and networking.
On my machine, a Core i7 2600 (3.4GHz, 4 cores, 8 threads)/8 GB RAM/Intel SSD G3 120GB it start in around 7 seconds for a core-image-core. The same image boots in 20 seconds without virtualization optimization and it feels slower in usage.
On a machine equipped with a Core i7 2600 (3.4GHz, 4 cores, 8 threads)/8 GB RAM/Intel SSD G3 120GB qemux86 Yocto Linux boots in around 7 seconds for a core-image-x11. The same image boots in 20 seconds without virtualization optimizations and feels slower in usage.
 
See attached screenshots for VM running and proof of concept.
Also attached is the patch for running our runqemu script with KVM and paravirt and virtio tech.
In order to run it, use:
runqemu qemux86 core-image-core kvm
Log:
ubik@sentry:~/yoctoproject/build$ runqemu qemux86 core-image-core kvm
Assuming core-image-core really means /home/ubik/yoctoproject/build/tmp/deploy/images/core-image-core-qemux86.ext3
Continuing with the following parameters:
KERNEL: [/home/ubik/yoctoproject/build/tmp/deploy/images/bzImage-qemux86.bin]
ROOTFS: [/home/ubik/yoctoproject/build/tmp/deploy/images/core-image-core-qemux86.ext3]
FSTYPE: [ext3]
Setting up tap interface under sudo
[sudo] password for ubik:
Acquiring lockfile for tap0...
WARNING: distccd not present, no distcc support loaded.
Running qemu...
/home/ubik/yoctoproject/build/tmp/sysroots/x86_64-linux/usr/bin/qemu -kernel /home/ubik/yoctoproject/build/tmp/deploy/images/bzImage-qemux86.bin -net nic,model=virtio -net tap,vlan=0,ifname=tap0,script=no,downscript=no,vhost=on -drive file=/home/ubik/yoctoproject/build/tmp/deploy/images/core-image-core-qemux86.ext3,if=virtio -show-cursor -usb -usbdevice wacom-tablet -vga vmware -no-reboot -enable-kvm -cpu host -m 128 --append "vga=0 root=/dev/vda rw mem=128M ip=192.168.7.2::192.168.7.1:255.255.255.0 oprofile.timer=1 "
vmsvga_value_write: guest runs Linux.
Set 'tap0' nonpersistent
Releasing lockfile of preconfigured tap device 'tap0'
ubik@sentry:~/yoctoproject/build$
== Guest OS preparation ==
== Guest OS preparation ==
   
   
The following kernel configs needs to be enabled:
The following kernel configs needs to be enabled for Yocto Linux guest OS:
   
 
CONFIG_PARAVIRT_GUEST=y
  [...]
# CONFIG_PARAVIRT_TIME_ACCOUNTING is not set
CONFIG_PARAVIRT_GUEST=y
# CONFIG_XEN_PRIVILEGED_GUEST is not set
CONFIG_KVM_CLOCK=y
CONFIG_KVM_CLOCK=y
CONFIG_KVM_GUEST=y
CONFIG_KVM_GUEST=y
CONFIG_PARAVIRT=y
# CONFIG_LGUEST_GUEST is not set
CONFIG_PARAVIRT_CLOCK=y
CONFIG_PARAVIRT=y
CONFIG_VIRTIO_MMIO=y
# CONFIG_PARAVIRT_SPINLOCKS is not set
[..]
CONFIG_PARAVIRT_CLOCK=y
 
# CONFIG_PARAVIRT_DEBUG is not set
Screenshots example:
CONFIG_VIRTIO_MMIO=y
[[File:Core-image-x11.png|thumb|upright=2|left|Yocto Linux guest running under QEMU KVM with paravirtualization and virtio tech.]]
[[File:YL-guest-QEMU-cpu-host.png|thumb|left|upright=2|CPU host features exported to Yocto Linux guest.]]

Latest revision as of 10:38, 3 October 2012

Host OS preparation (VM manager host OS)

Steps:

1.Enable KVM on the host machine

2. Enable on host OS vhost-net virtio networking accelerator to mitigate overhead on QEMU virtualization environment.
Load vhost_net module on KVM Host.

ubik@sentry:~$ sudo modprobe vhost_net
ubik@sentry:~$ lsmod | grep vhost

The result of running the commands should be similar to the following:

vhost_net              32359  0 
macvtap                18528  1 vhost_net

In order for an user to use vhost-net module enter the following commands:

sudo addgroup --system vhost-net
sudo adduser $USER vhost-net
sudo chown root:vhost-net /dev/vhost-net
sudo chmod 0660 /dev/vhost-net

Modify /etc/modules so that vhost_net module is automatically loaded at boot time:

sudo vim /etc/modules

For example:
File: /etc/modules
Content:

# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.

lp
rtc
vhost_net

On a system that runs udev, you will probably need to add the following line somewhere in your udev configuration so it will automatically give the right group to the newly created device.
For example:
File: /etc/udev/rules.d/40-permissions.rules
Content:

KERNEL=="vhost-net", GROUP="vhost-net", MODE="0660"

Restart udev:

ubik@sentry:~$ sudo restart udev
[sudo] password for ubik: 
udev start/running, process 28404

Note

  • You need log out then log in the non-root user to take the effect

3. Start the VM using the line below:

ubik@sentry:~/yoctoproject/build$ sudo kvm -kernel /home/ubik/yoctoproject/build/tmp/deploy/images/bzImage-qemux86.bin -net nic,model=virtio -net \
    tap,vlan=0,ifname=tap0,script=no,downscript=no,vhost=on -drive file=/home/ubik/yoctoproject/build/tmp/deploy/images/core-image-core-qemux86.ext3,if=virtio \
   -show-cursor -usb - usbdevice wacom-tablet -vga vmware -no-reboot -enable-kvm -cpu host -m 128 --append "vga=0 root=/dev/vda rw mem=128M \
   ip=192.168.7.2::192.168.7.1:255.255.255.0 oprofile.timer=1 " 

This is an example of running a virtualized Yocto image, with KVM active, cpu host features exported in the Yocto VM, paravirtualization enabled, and using virtio interfaces for disk access and networking. On a machine equipped with a Core i7 2600 (3.4GHz, 4 cores, 8 threads)/8 GB RAM/Intel SSD G3 120GB qemux86 Yocto Linux boots in around 7 seconds for a core-image-x11. The same image boots in 20 seconds without virtualization optimizations and feels slower in usage.

Guest OS preparation

The following kernel configs needs to be enabled for Yocto Linux guest OS:

[...]
CONFIG_PARAVIRT_GUEST=y
CONFIG_KVM_CLOCK=y
CONFIG_KVM_GUEST=y
CONFIG_PARAVIRT=y
CONFIG_PARAVIRT_CLOCK=y
CONFIG_VIRTIO_MMIO=y
[..]

Screenshots example:

Yocto Linux guest running under QEMU KVM with paravirtualization and virtio tech.
CPU host features exported to Yocto Linux guest.