runqemu with kas-container and kvm from host

33 views
Skip to first unread message

João Henrique Freitas

unread,
Oct 26, 2023, 5:06:46 PM10/26/23
to kas-devel

Hi,

Is it possible to access /dev/kvm from kas-container when using runqemu with kvm option ?

I use to build and run qemu inside kas-container. And I'm trying to figure out what would be the necessary --runtime-args to enable using kvm there.

Thanks.

Jose Quaresma

unread,
Oct 27, 2023, 3:24:15 AM10/27/23
to João Henrique Freitas, kas-devel
Hi João,

João Henrique Freitas <joa...@gmail.com> escreveu no dia quinta, 26/10/2023 à(s) 22:06:

Hi,

Is it possible to access /dev/kvm from kas-container when using runqemu with kvm option ?

yes, it's possible with "runqemu kvm ..."
 

I use to build and run qemu inside kas-container. And I'm trying to figure out what would be the necessary --runtime-args to enable using kvm there.

Afaik running with --privileged is enough but you can also be more strict and mount just /dev/kvm

Jose


Thanks.

--
You received this message because you are subscribed to the Google Groups "kas-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kas-devel+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kas-devel/f79403bc-fc64-4ee3-a343-dd86edfef3e2n%40googlegroups.com.


--
Best regards,

José Quaresma

Jörg Sommer

unread,
Oct 30, 2023, 4:14:41 AM10/30/23
to João Henrique Freitas, kas-devel
On 26.10.23 23:06, João Henrique Freitas wrote:
>
> Hi,
>
> Is it possible to access /dev/kvm from kas-container when using runqemu
> with kvm option ?

Maybe, only as a hint, you want to start the built image. I'm doing this with

```
OECORE_NATIVE_SYSROOT=/ PATH=$PWD/ayers-3rdparty/poky/scripts:$PATH \
runqemu build/tmp/deploy/images/qemux86-64/…-qemux86-64.qemuboot.conf \
kvm nographic slirp
```

layers-3rdparty/poky contains the poky layer


Kind regards

Jörg Sommer
--
Navimatix GmbH
Tatzendpromenade 2
D-07745 Jena
Geschäftsführer: Steffen Späthe, Jan Rommeley
Registergericht: Amtsgericht Jena, HRB 501480

João Henrique Freitas

unread,
Nov 2, 2023, 7:51:56 PM11/2/23
to kas-devel

Hi,

Some additional info:

I'm using the following command to start kas-container:

kas/kas-container --runtime-args "--privileged" shell

Which gave me the `docker run` with '--privileged' argument as expected:

docker run -v /home/joaohf/work/opensource/kas-meta-erlang:/repo:rw -v /home/joaohf/work/opensource/kas-meta-erlang:/work:rw -e KAS_WORK_DIR=/work \
-v /home/joaohf/work/opensource/kas-meta-erlang/build:/build:rw --workdir=/repo -e KAS_BUILD_DIR=/build -e USER_ID=1000 -e GROUP_ID=1000 --rm \
--init -t -i -e TERM=screen-256color -e SHELL=/bin/bash --log-driver=none --user=root --privileged ghcr.io/siemens/kas/kas:4.1 shell

However, I can start runqemu with kvm flag, I got:

runqemu core-image-minimal slirp nographic serialstdio kvm

runqemu - INFO - Running bitbake -e  core-image-minimal...
runqemu - ERROR - You have no read or write permission on /dev/kvm.
runqemu - ERROR - Please change the ownership of this file as described at:
runqemu - ERROR - https://wiki.yoctoproject.org/wiki/How_to_enable_KVM_for_Poky_qemu
runqemu - INFO - Cleaning up
runqemu - INFO - Host uptime: 8024.49

Some details from /dev/kvm on kas container:

builder@9231d7110d3b:/build$ ls -l /dev/kvm
crw-rw---- 1 root 109 10, 232 Nov  2 21:13 /dev/kvm
builder@9231d7110d3b:/build$ id
uid=1000(builder) gid=1000(builder) groups=1000(builder)
builder@9231d7110d3b:/build$

And, from my host Linux (Ubuntu):

joaohf@porco:~/work/opensource/kas-meta-erlang$ ls /dev/kvm  -l
crw-rw----+ 1 root kvm 10, 232 nov  2 17:46 /dev/kvm

joaohf@porco:~/work/opensource/kas-meta-erlang$ id
uid=1000(joaohf) gid=1000(joaohf) groups=1000(joaohf),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),109(kvm),123(lpadmin),132(lxd),133(sambashare),998(docker)

I think there is something configuration missing in my host or missing more runtime-args.

Any hint ?

Thanks.

Jose Quaresma

unread,
Nov 3, 2023, 8:19:26 AM11/3/23
to João Henrique Freitas, kas-devel
Can you try with: sudo runqemu ...
 

Thanks.

Em segunda-feira, 30 de outubro de 2023 às 05:14:41 UTC-3, Jörg Sommer escreveu:
On 26.10.23 23:06, João Henrique Freitas wrote:
>
> Hi,
>
> Is it possible to access /dev/kvm from kas-container when using runqemu
> with kvm option ?

Maybe, only as a hint, you want to start the built image. I'm doing this with

```
OECORE_NATIVE_SYSROOT=/ PATH=$PWD/ayers-3rdparty/poky/scripts:$PATH \
runqemu build/tmp/deploy/images/qemux86-64/…-qemux86-64.qemuboot.conf \
kvm nographic slirp
```

layers-3rdparty/poky contains the poky layer


Kind regards

Jörg Sommer
--
Navimatix GmbH
Tatzendpromenade 2
D-07745 Jena
Geschäftsführer: Steffen Späthe, Jan Rommeley
Registergericht: Amtsgericht Jena, HRB 501480

--
You received this message because you are subscribed to the Google Groups "kas-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kas-devel+...@googlegroups.com.

João Henrique Freitas

unread,
Nov 3, 2023, 8:39:30 PM11/3/23
to Jose Quaresma, kas-devel

Hi,

Sure. Here is the result:

builder@e5e78630cfb2:/build$ sudo runqemu core-image-minimal kvm nographic serialstdio
sudo: runqemu: command not found

builder@e5e78630cfb2:/build$ whereis runqemu
runqemu: /work/poky/scripts/runqemu
builder@e5e78630cfb2:/build$ sudo /work/poky/scripts/runqemu core-image-minimal kvm nographic serialstdio
Traceback (most recent call last):
  File "/work/poky/scripts/runqemu", line 1738, in main
    config.check_args()
  File "/work/poky/scripts/runqemu", line 573, in check_args
    s = re.search('^DEPLOY_DIR_IMAGE="(.*)"', self.bitbake_e, re.M)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/re/__init__.py", line 176, in search
    return _compile(pattern, flags).search(string)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: expected string or bytes-like object, got 'NoneType'

runqemu - INFO - Cleaning up
runqemu - INFO - Host uptime: 6230.00


--
João Henrique Ferreira de Freitas - joaohf_at_gmail.com
Campinas-SP-Brasil

Jörg Sommer

unread,
Nov 6, 2023, 3:13:27 AM11/6/23
to João Henrique Freitas, Jose Quaresma, kas-devel
On 04.11.23 01:39, João Henrique Freitas wrote:
>
> Hi,
>
> Sure. Here is the result:
>
> builder@e5e78630cfb2:/build$ sudo runqemu core-image-minimal kvm
> nographic serialstdio
> sudo: runqemu: command not found

Can you try `sudo -E runqemu …`? This should use PATH from your calling
environment.

João Henrique Freitas

unread,
Nov 12, 2023, 7:14:12 PM11/12/23
to Jörg Sommer, Jose Quaresma, kas-devel
Hi,

No success so far:

builder@5d94f447224c:/build$ sudo -E runqemu core-image-minimal slirp nographic serialstdio kvm

sudo: runqemu: command not found

builder@5d94f447224c:/build$ sudo -E env
SHELL=/bin/bash
OE_ADDED_PATHS=/work/poky/scripts:/work/poky/bitbake/bin:
BB_ENV_PASSTHROUGH_ADDITIONS=ALL_PROXY BBPATH_EXTRA BB_LOGCONFIG BB_NO_NETWORK BB_NUMBER_THREADS BB_SETSCENE_ENFORCE BB_SRCREV_POLICY DISTRO FTPS_PROXY FTP_PROXY GIT_PROXY_COMMAND HTTPS_PROXY HTTP_PROXY MACHINE NO_PROXY PARALLEL_MAKE SCREENDIR SDKMACHINE SOCKS5_PASSWD SOCKS5_USER SSH_AGENT_PID SSH_AUTH_SOCK STAMPS_DIR TCLIBC TCMODE all_proxy ftp_proxy ftps_proxy http_proxy https_proxy no_proxy  SSTATE_DIR SSTATE_MIRRORS DL_DIR TMPDIR
LANGUAGE=en_US:en
PWD=/build
HOME=/tmp/tmpfd4ka937
LANG=en_US.UTF-8
BBPATH=/build
GIT_PROXY_COMMAND=oe-git-proxy
TERM=screen-256color
NO_PROXY=*
SHLVL=2
LC_ALL=en_US.UTF-8
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
BUILDDIR=/build
OLDPWD=/work/poky
_=/usr/bin/sudo
LOGNAME=root
USER=root
SUDO_COMMAND=/usr/bin/env
SUDO_USER=builder
SUDO_UID=1000
SUDO_GID=1000

builder@5d94f447224c:/build$ sudo -E /work/poky/scripts/runqemu core-image-minimal slirp nographic serialstdio kvm

Traceback (most recent call last):
  File "/work/poky/scripts/runqemu", line 1738, in main
    config.check_args()
  File "/work/poky/scripts/runqemu", line 573, in check_args
    s = re.search('^DEPLOY_DIR_IMAGE="(.*)"', self.bitbake_e, re.M)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/re/__init__.py", line 176, in search
    return _compile(pattern, flags).search(string)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: expected string or bytes-like object, got 'NoneType'
runqemu - INFO - Cleaning up
runqemu - INFO - Host uptime: 33574.42

Jörg Sommer

unread,
Nov 13, 2023, 4:07:03 AM11/13/23
to João Henrique Freitas, Jose Quaresma, kas-devel
On 13.11.23 01:13, João Henrique Freitas wrote:
> Hi,
>
> No success so far:
>
> builder@5d94f447224c:/build$ sudo -E runqemu core-image-minimal slirp
> nographic serialstdio kvm
> sudo: runqemu: command not found

Oh sorry, I didn't try it. sudo resets the path due to secure_path in /etc/sudoers. You have to call it with:

sudo env PATH=/usr/local/sbin:/usr/local/bin:$PATH runqemu core-image-minimal slirp nographic serialstdio kvm

João Henrique Freitas

unread,
Nov 14, 2023, 8:02:29 PM11/14/23
to Jörg Sommer, Jose Quaresma, kas-devel
Hi Jörg,

Here is the result. I also tried the previous command after removing secure_path from /etc/sudoers. No success.

builder@a68562a634fb:/build$ sudo env PATH=/usr/local/sbin:/usr/local/bin:$PATH runqemu core-image-minimal slirp nographic serialstdio kvm

runqemu - INFO - Running bitbake -e  core-image-minimal...
ERROR:  OE-core's config sanity checker detected a potential misconfiguration.
    Either fix the cause of this error or at your own risk disable the checker (see sanity.conf).
    Following is the list of potential problems / advisories:

    Do not use Bitbake as root.
runqemu - WARNING - Couldn't run 'bitbake -e  core-image-minimal' to gather environment information, maybe the target wasn't an image name, will retry with virtual/kernel as a target:

Summary: There was 1 ERROR message, returning a non-zero exit code.

ERROR:  OE-core's config sanity checker detected a potential misconfiguration.
    Either fix the cause of this error or at your own risk disable the checker (see sanity.conf).
    Following is the list of potential problems / advisories:

    Do not use Bitbake as root.
runqemu - WARNING - Couldn't run 'bitbake -e  virtual/kernel' to gather environment information, giving up with 'bitbake -e':

Summary: There was 1 ERROR message, returning a non-zero exit code.

runqemu - WARNING - Can't find qemuboot conf file, DEPLOY_DIR_IMAGE is NULL!
runqemu - INFO - Running bitbake -e  None...
ERROR:  OE-core's config sanity checker detected a potential misconfiguration.
    Either fix the cause of this error or at your own risk disable the checker (see sanity.conf).
    Following is the list of potential problems / advisories:

    Do not use Bitbake as root.
runqemu - WARNING - Couldn't run 'bitbake -e  None' to gather environment information, maybe the target wasn't an image name, will retry with virtual/kernel as a target:

Summary: There was 1 ERROR message, returning a non-zero exit code.

ERROR:  OE-core's config sanity checker detected a potential misconfiguration.
    Either fix the cause of this error or at your own risk disable the checker (see sanity.conf).
    Following is the list of potential problems / advisories:

    Do not use Bitbake as root.
runqemu - WARNING - Couldn't run 'bitbake -e  virtual/kernel' to gather environment information, giving up with 'bitbake -e':

Summary: There was 1 ERROR message, returning a non-zero exit code.

runqemu - ERROR - Failed to boot, QB_SYSTEM_NAME is NULL!

runqemu - INFO - Cleaning up
runqemu - INFO - Host uptime: 13859.28

Jörg Sommer

unread,
Nov 15, 2023, 2:48:30 AM11/15/23
to João Henrique Freitas, Jose Quaresma, kas-devel
On 15.11.23 02:02, João Henrique Freitas wrote:
> Hi Jörg,
>
> Here is the result. I also tried the previous command after removing
> secure_path from /etc/sudoers. No success.
>
> builder@a68562a634fb:/build$ sudo env
> PATH=/usr/local/sbin:/usr/local/bin:$PATH runqemu core-image-minimal
> slirp nographic serialstdio kvm
> runqemu - INFO - Running bitbake -e  core-image-minimal...
> ERROR:  OE-core's config sanity checker detected a potential
> misconfiguration.
>     Either fix the cause of this error or at your own risk disable the
> checker (see sanity.conf).
>     Following is the list of potential problems / advisories:
>
>     Do not use Bitbake as root.

Yes, right. Why do you run runqemu as root? Why not call it without?

Jose Quaresma

unread,
Nov 15, 2023, 6:40:06 AM11/15/23
to Jörg Sommer, João Henrique Freitas, kas-devel
Last time I used runqemu I thought sudo is required but this is not true anymore so apologize for my suggestion,
please just follow the https://wiki.yoctoproject.org/wiki/How_to_enable_KVM_for_Poky_qemu

The following works for me:

cat <<'EOF' > poky-runqemu.yml
header:
  version: 8

local_conf_header:
  extras: |
    IMAGE_FEATURES += "allow-empty-password"
    IMAGE_FEATURES += "empty-root-password"
    INHERIT:remove = "create-spdx"

  sstate: |
    BB_HASHSERVE_UPSTREAM = "hashserv.yocto.io:8687"
    SSTATE_MIRRORS += "file://.* http://cdn.jsdelivr.net/yocto/sstate/all/PATH;downloadfilename=PATH"

distro: poky
machine: qemux86-64
target: core-image-minimal

repos:
  poky:
    branch: nanbield
    url: https://git.yoctoproject.org/git/poky
    layers:
      meta:
      meta-poky:
      meta-yocto-bsp:
EOF

KAS_CONTAINER_IMAGE=ghcr.io/siemens/kas/kas:4.1 kas-container build poky-runqemu.yml
KAS_CONTAINER_IMAGE=ghcr.io/siemens/kas/kas:4.1 kas-container --runtime-args --privileged shell -c "runqemu kvm slirp nographic" poky-runqemu.yml

Login as root and check KVM

root@qemux86-64:~# dmesg |grep KVM
[    0.000000] Hypervisor detected: KVM
[    0.003736] Booting paravirtualized kernel on KVM

Jose

João Henrique Freitas

unread,
Nov 20, 2023, 7:22:23 PM11/20/23
to Jose Quaresma, Jörg Sommer, kas-devel
Thanks,

That worked.

Even following the wiki instructions, I had to adjust the permissions of /dev/kvm (chmod 0666 /dev/kvm). I suspected that it was something related to user mapping inside the kas-container.

BR,
Reply all
Reply to author
Forward
0 new messages