Bug 3184 - running an image with kvm enabled fails if the runqemu command is used
Summary: running an image with kvm enabled fails if the runqemu command is used
Status: VERIFIED FIXED
Alias: None
Product: OE-Core
Classification: Build System, Metadata & Runtime
Component: virtual machines (show other bugs)
Version: unspecified
Hardware: x86 Multiple
: Medium+ normal
Target Milestone: 1.3 M5
Assignee: Cristian Iorga
QA Contact:
URL:
Whiteboard: 4b5d9da07c2b4946cf2321ce537047bd61366a6e
Depends on:
Blocks:
 
Reported: 2012-09-26 22:29 UTC by Laurentiu Serban
Modified: 2012-10-08 14:35 UTC (History)
5 users (show)

See Also:
OS type for building Yocto: ---
Type of Regression: ---
Verified:
Documentation change: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Laurentiu Serban 2012-09-26 22:29:59 UTC
Following the wiki
https://wiki.yoctoproject.org/wiki/Running_an_x86_Yocto_Linux_image_under_QEMU_KVM
causes this error while starting the machine:

lserban@computer1:~/work/master/build$ runqemu tmp/deploy/images/bzImage-qemux86.bin tmp/deploy/images/core-image-minimal-qemux86-20120926220014.rootfs.ext3 kvm nographic
Set MACHINE to [qemux86] based on kernel [tmp/deploy/images/bzImage-qemux86.bin]

Continuing with the following parameters:
KERNEL: [tmp/deploy/images/bzImage-qemux86.bin]
ROOTFS: [tmp/deploy/images/core-image-minimal-qemux86-20120926220014.rootfs.ext3]
FSTYPE: [ext3]
Setting up tap interface under sudo
Acquiring lockfile for tap0...
WARNING: distccd not present, no distcc support loaded.
Running qemu-system-i386...
/home/lserban/work/master/build/tmp/sysroots/x86_64-linux/usr/bin/qemu-system-i386 -kernel tmp/deploy/images/bzImage-qemux86.bin -net nic,model=virtio -net tap,vlan=0,ifname=tap0,script=no,downscript=no,vhost=on -drive file=tmp/deploy/images/core-image-minimal-qemux86-20120926220014.rootfs.ext3,if=virtio -show-cursor -usb -usbdevice wacom-tablet -vga vmware -no-reboot -nographic -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 console=ttyS0"
qemu-system-i386: -net tap,vlan=0,ifname=tap0,script=no,downscript=no,vhost=on: vhost-net requested but could not be initialized
qemu-system-i386: -net tap,vlan=0,ifname=tap0,script=no,downscript=no,vhost=on: Device 'tap' could not be initialized
Set 'tap0' nonpersistent
Releasing lockfile of preconfigured tap device 'tap0'


if the command /home/lserban/work/master/build/tmp/sysroots/x86_64-linux/usr/bin/qemu-system-i386 -kernel tmp/deploy/images/bzImage-qemux86.bin -net nic,model=virtio -net tap,vlan=0,ifname=tap0,script=no,downscript=no,vhost=on -drive file=tmp/deploy/images/core-image-minimal-qemux86-20120926220014.rootfs.ext3,if=virtio -show-cursor -usb -usbdevice wacom-tablet -vga vmware -no-reboot -nographic -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 console=ttyS0" is run with sudo the machine starts.

This is an incorrect behavior, the sudo password should be asked when the machine starts
Comment 1 Cristian Iorga 2012-09-27 06:35:54 UTC
Hello,

This is the key:

"vhost-net requested but could not be initialized"

This is not a problem of poky, Yocto Linux or qemu.

This basically means that the user did not configure properly vhost-net driver in order to be run also under a user without administrative rights.

See this part from the guide:

 Change the kvm dev ownership for non-root user

qemu is started as non-root user in poky, but /dev/kvm from some distribution remains root:root that only allow root to use KVM. To work around this, we need create a new group named kvm, and make both /dev/kvm and the non-root user belongs to it.

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

The output of "ls -l /dev/kvm" should be like this:

crw-rw----+ 1 root kvm 10, 232 2010-07-02 09:27 /dev/kvm

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 (i-e for ubuntu add a line to /etc/udev/rules.d/40-permissions.rules).

KERNEL=="kvm", GROUP="kvm"

Something similar must be done for vhost-net!!


Note

    You need log out then log in the non-root user to take the effect
    Some distributions have already made this, so that we can skip this step 

And also:

Basically, follow the same guide as for enabling KVM on the host (step 1.), but replace kvm with vhost_net 


Or course that running under sudo solves the issue.
And if someone authenticated himself/herself to run something under sudo, there a limited period of time in which the system does not ask you again for your password.
Comment 2 Alexandru Damian 2012-10-02 11:14:41 UTC
Please document all this with the ready-to-run copy-paste scripts in the Wiki page.
The wiki page is not clear on what you are supposed to do.


Please detect in the runqemu script when this error is triggered, and provide an informative message with a link to the wiki page.
Comment 3 Cristian Iorga 2012-10-02 11:17:52 UTC
Agreed.

1. Online guide will be updated.
2. Reported error will be clarified and a link to the online guide will be provided.

Regards,
Cristian
Comment 4 Cristian Iorga 2012-10-03 10:55:24 UTC
Patch submitted for review.
Comment 5 Cristian Iorga 2012-10-03 10:56:03 UTC
Online guide has been updated and clarified.

See: https://wiki.yoctoproject.org/wiki/Running_an_x86_Yocto_Linux_image_under_QEMU_KVM
Comment 6 Cristian Iorga 2012-10-04 06:26:54 UTC
Fixed.
Comment 7 Alexandru Georgescu 2012-10-08 14:35:42 UTC
Verified.
Following the wiki could help me boot qemu kvm enabled.