yocto-第2篇-qemux86-64虚拟机运行演示

By: fu linux
E-mail: fulinux@sina.com
Blog: https://blog.csdn.net/fulinus
喜欢的盆友欢迎点赞和订阅!
你的喜欢就是我写作的动力!

返回总目录 Yocto开发讲解系列 - 总目录

编译完成运行

继续上一篇,今天已经编译完成了,运行虚拟机:

$ cd poky/
$ source oe-init-build-env
$ runqemu qemux86
runqemu - INFO - Running MACHINE=qemux86 bitbake -e ...
runqemu - ERROR - /home/peeta/poky/build/tmp/deploy/images/qemux86 not a directory valid DEPLOY_DIR_IMAGE
ls: 无法访问'/home/peeta/poky/build/tmp/deploy/images/qemux86/*.qemuboot.conf': 没有那个文件或目录
runqemu - ERROR - Command 'ls -t /home/peeta/poky/build/tmp/deploy/images/qemux86/*.qemuboot.conf' returned non-zero exit status 2
runqemu - INFO - Cleaning up
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

提示无法访问/home/peeta/poky/build/tmp/deploy/images/qemux86/*.qemuboot.conf文件,查找原因:

$ ls -l /home/peeta/poky/build/tmp/deploy/images/qemux86/*.qemuboot.conf
ls: 无法访问'/home/peeta/poky/build/tmp/deploy/images/qemux86/*.qemuboot.conf': 没有那个文件或目录
  • 1
  • 2

原因是没有这个路径或者文件,但是有

/home/peeta/poky/build/tmp/deploy/images/qemux86-64/
  • 1

运行qemux86-64

我们在运行runqemu后面的目标机器错了,不是 qemux86 而是 qemux86-64 (后者是64位的),因此,前面的命令修改运行如下:

$ runqemu qemux86-64
runqemu - INFO - Running MACHINE=qemux86-64 bitbake -e ...
runqemu - INFO - Continuing with the following parameters:
KERNEL: [/home/peeta/poky/build/tmp/deploy/images/qemux86-64/bzImage--5.4.50+git0+416566e1f0_94667198aa-r0-qemux86-64-20201003082353.bin]
MACHINE: [qemux86-64]
FSTYPE: [ext4]
ROOTFS: [/home/peeta/poky/build/tmp/deploy/images/qemux86-64/core-image-sato-qemux86-64-20201003082353.rootfs.ext4]
CONFFILE: [/home/peeta/poky/build/tmp/deploy/images/qemux86-64/core-image-sato-qemux86-64-20201003082353.qemuboot.conf]

runqemu - INFO - Setting up tap interface under sudo
[sudo] peeta 的密码: (提示输入超级用户密码)
runqemu - INFO - Network configuration: ip=192.168.7.2::192.168.7.1:255.255.255.0
runqemu - INFO - Running /home/peeta/poky/build/tmp/work/x86_64-linux/qemu-helper-native/1.0-r1/recipe-sysroot-native/usr/bin/qemu-system-x86_64 -device virtio-net-pci,netdev=net0,mac=52:54:00:12:34:02 -netdev tap,id=net0,ifname=tap0,script=no,downscript=no -drive file=/home/peeta/poky/build/tmp/deploy/images/qemux86-64/core-image-sato-qemux86-64-20201003082353.rootfs.ext4,if=virtio,format=raw -show-cursor -usb -device usb-tablet -object rng-random,filename=/dev/urandom,id=rng0 -device virtio-rng-pci,rng=rng0   -cpu core2duo -m 512 -serial mon:vc -serial null -kernel /home/peeta/poky/build/tmp/deploy/images/qemux86-64/bzImage--5.4.50+git0+416566e1f0_94667198aa-r0-qemux86-64-20201003082353.bin -append 'root=/dev/vda rw  mem=512M ip=192.168.7.2::192.168.7.1:255.255.255.0 oprofile.timer=1 '

runqemu - ERROR - Failed to run qemu: Could not initialize SDL(x11 not available) - exiting

runqemu - INFO - Cleaning up
Set 'tap0' nonpersistent
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

上面运行的结果显示失败了,重点关注下这个错误提示:

runqemu - ERROR - Failed to run qemu: Could not initialize SDL(x11 not available) - exiting
  • 1

其中关键词 x11 通常就是与显示相关的内容,说明失败的原因是 run qemu qemux86-64 机器需要在ubuntu桌面环境下才能运行,不能在 secureCRT 或其他第三方linux终端中运行。

不依赖桌面环境运行QEMU

由于我使用的是 secureCRT 登录远程Ubuntu服务器的场景,因此,首先尝试不依赖于Ubuntu桌面环境的情况下运行 qemux86-64 。下面是启动虚拟机的配置信息

-device virtio-net-pci,netdev=net0,mac=52:54:00:12:34:02 -netdev tap,id=net0,ifname=tap0,script=no,downscript=no -drive file=/home/peeta/poky/build/tmp/deploy/images/qemux86-64/core-image-sato-qemux86-64-20201003082353.rootfs.ext4,if=virtio,format=raw -show-cursor -usb -device usb-tablet -object rng-random,filename=/dev/urandom,id=rng0 -device virtio-rng-pci,rng=rng0   -cpu core2duo -m 512 -serial mon:vc -serial null -kernel /home/peeta/poky/build/tmp/deploy/images/qemux86-64/bzImage--5.4.50+git0+416566e1f0_94667198aa-r0-qemux86-64-20201003082353.bin -append 'root=/dev/vda rw  mem=512M ip=192.168.7.2::192.168.7.1:255.255.255.0 oprofile.timer=1 '
  • 1

我们现在使用的机器 MACHINE 名字是 qemux86-64 ,对应的 MACHINE 配置文件是:

meta/conf/machine/qemux86-64.conf
  • 1

在这里插入图片描述
红框中是其他一个配置文件,相当于头文件。
meta/conf/machine/include/qemu.inc 文件中有这样一个配置:

MACHINE_FEATURES = "alsa bluetooth usbgadget screen vfat" 
  • 1

其中有个 screen ,我们的qemux86-64机器有 screen 特性 FEATURES ,这里我们删除 screen 试试看:

MACHINE_FEATURES = "alsa bluetooth usbgadget vfat"
  • 1

在poky/build/conf/local.conf文件中发现这一段话:
在这里插入图片描述
与上面错误提示“Could not initialize SDL”中的SDL对上了,看看能不能去掉,试试屏蔽该行:

#PACKAGECONFIG_append_pn-qemu-system-native = " sdl"
  • 1

然后,重新source和编译:

$ source oe-init-build-env
$ bitbake core-image-sato
  • 1
  • 2

编译完成后运行,这次就没有出错了:
在这里插入图片描述

从图中可以看到 qemux86-64 虚拟机的网络地址是 192.168.7.2 , 而且我的Ubuntu系统可以ping通这个虚拟机(Ubuntu系统自身的网络地址:10.66.10x.xxx,说明qemu虚拟机模拟出来的网卡是可以访问到的,不必考虑是否有相同网关),ping过程如下:

在这里插入图片描述

登录qemux86-64虚拟机

不过突然想到有了网络可以尝试用telnet或者ssh登录,果然是可以的,打开另外一个终端,输入如下命令即可登录:

$ ssh root@192.168.7.2
  • 1

在这里插入图片描述
登录后简单了解下这个虚拟机:

root@qemux86-64:/# cat /proc/cmdline 
root=/dev/vda rw  mem=512M ip=192.168.7.2::192.168.7.1:255.255.255.0 oprofile.timer=1 
root@qemux86-64:/# mount
/dev/root on / type ext4 (rw,relatime)
devtmpfs on /dev type devtmpfs (rw,relatime,size=244932k,nr_inodes=61233,mode=755)
proc on /proc type proc (rw,relatime)
tmpfs on /mnt/.psplash type tmpfs (rw,relatime,size=40k)
sysfs on /sys type sysfs (rw,relatime)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
tmpfs on /run type tmpfs (rw,nosuid,nodev,mode=755)
tmpfs on /var/volatile type tmpfs (rw,relatime)
devpts on /dev/pts type devpts (rw,relatime,gid=5,mode=620,ptmxmode=000)
nfsd on /proc/fs/nfsd type nfsd (rw,relatime)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

这样我们使用yocto构建的第一个qemux86-64虚拟机就跑起来了,是不是很顺利呢?

在Ubuntu桌面环境中运行

$ runqemu qemux86-64
  • 1

启动界面:
在这里插入图片描述

看这个启动log, qemux86-64 是没有使用 uboot 的,而是自带的 seaBIOS 引导了内核启动。
在这里插入图片描述

随后出现 yocto 画面:
在这里插入图片描述

启动完成的画面:
在这里插入图片描述

任意操作:
在这里插入图片描述

打开终端应用:
在这里插入图片描述
打开文件管理器,在/home/root下创建文件:
在这里插入图片描述

To be continue~

希望帮我点个赞加关注,你的喜欢就是我持续更新的动力!