:qemu启动xv6问题记录

Posted seasonhai

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了:qemu启动xv6问题记录相关的知识,希望对你有一定的参考价值。

最近在学习《操作系统原型--xv6分析与实验》,第一章安装qemu和启动xv6就遇到很多障碍,特此记录一下解决办法。

版本信息
系统:Ubuntu 22.04.1 LTS
xv6:rev9
qemu:6.2
gcc:11.2.0

操作步骤
ubuntu勾选了完整安装,默认自带gcc、make等构建工具。


  1. 首先将用到的xv6下载下来解压,我下载的是rev9版本。
tar -xvf xv6-public-xv6-rev9.tar.gz
cd xv6-public-xv6-rev9/

  1. 编译xv6
make

编译报错:

usertests.c: In function ‘sbrktest’:
usertests.c:1461:13: error: writing 1 byte into a region of size 0 [-Werror=stringop-overflow=]

[-Werror=stringop-overflow=]是由于gcc版本过高导致的,换低版本gcc即可解决(如gcc 8)。
但是更换gcc比较麻烦,这个是将警告当做报错了,因此跳过它即可。观察命令行参数有个-Werror,编辑当前目录下的Makefile文件,去掉命令行参数-Werror即可。

vim Makefile
# 搜索Werror,找到后删除
/Werror

重新执行make,编译完成,生成了xv6.img文件。

make
ll xv6.img


  1. 接下来启动qemu
    make qemu

报错信息:

***
*** Error: Couldn\'t find a working QEMU executable.
*** Is the directory containing the qemu binary in your PATH
*** or have you tried setting the QEMU variable in Makefile?
***
serial mon:stdio -drive file=fs.img,index=1,media=disk,format=raw -drive file=xv6.img,index=0,media=disk,format=raw -smp 2 -m 512 
make: serial: No such file or directory
make: [Makefile:216: qemu] Error 127 (ignored)

这是由于没有安装qemu导致的。
安装qemu:

# 安装qemu
sudo apt-get install qemu
# 安装x86架构的qemu(xv6 rev9版本要求x86架构)
sudo apt-get install qemu-system-x86
# 验证安装成功
qemu-system-i386

执行qemu-system-i386会弹出qemu,说明安装完成。

重新使用qemu启动xv6
make qemu

问题:qemu界面一直闪烁,卡在 Booting from Hard Disk...
一开始以为是qemu的版本问题,装了ubuntu 18和qemu 4版本,发现也不行。
最后搜到这个解决办法:
https://www.cnblogs.com/zsmumu/p/12622898.html
看不懂是什么原因,照着做即可。
定位到xv6目录下的kernel.ld的第25行:

/* Include debugging information in kernel memory */
	.stab : 

.stab : 改成.stab : AT(LOADADDR(.rodata) + SIZEOF(.rodata))
重新执行make qemu

qemu启动成功

MIT6.828centos7下使用Qemu搭建xv6运行环境


title:【MIT6.828】centos7下使用Qemu搭建xv6运行环境
date: "2020-05-05"

【MIT6.828】centos7下使用Qemu搭建xv6运行环境

1. 基础依赖

yum install libX11 libX11-devel SDL2 SDL2-devel -y

2. 编译和安装 QEMU

~]# wget https://download.qemu.org/qemu-4.2.0.tar.xz
~]# xz -d qemu-4.2.0.tar.xz && tar xf qemu-4.2.0.tar
~]# cd qemu-4.2.0/
~]# cat VERSION
~]# 4.2.0
~]# ./configure --help 
~]# ./configure --prefix=/usr/local  --enable-kvm --enable-debug --enable-debug-info --enable-curl  
--enable-sdl   --enable-vhost-net  --enable-vnc    
--enable-gtk --target-list=i386-softmmu

正确显示如下

No C++ compiler available; disabling C++ specific optional code
Install prefix    /usr/local
BIOS directory    /usr/local/share/qemu
firmware path     /usr/local/share/qemu-firmware
binary directory  /usr/local/bin
library directory /usr/local/lib
module directory  /usr/local/lib/qemu
libexec directory /usr/local/libexec
include directory /usr/local/include
config directory  /usr/local/etc
local state directory   /usr/local/var
Manual directory  /usr/local/share/man
ELF interp prefix /usr/gnemul/qemu-%M
Source path       /root/qemu-4.2.0
GIT binary        git
GIT submodules
C compiler        cc
Host C compiler   cc
C++ compiler
Objective-C compiler cc
ARFLAGS           rv
CFLAGS            -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -g
QEMU_CFLAGS       -I/usr/include/pixman-1   -I$(SRC_PATH)/dtc/libfdt   -pthread -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include   -fPIE -DPIE -m64 -mcx16 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -fno-common -fwrapv -std=gnu99  -Wendif-labels -Wno-missing-include-dirs -Wempty-body -Wnested-externs -Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers -Wold-style-declaration -Wold-style-definition -Wtype-limits -fstack-protector-strong -Wno-missing-braces -I/usr/include/libpng15   -I$(SRC_PATH)/capstone/include
LDFLAGS           -Wl,--warn-common -Wl,-z,relro -Wl,-z,now -pie -m64 -g
QEMU_LDFLAGS      -L$(BUILD_DIR)/dtc/libfdt
make              make
install           install
python            python3 -B (3.6.8)
slirp support     internal
smbd              /usr/sbin/smbd
module support    no
host CPU          x86_64
host big endian   no
target list       i386-softmmu
gprof enabled     no
sparse enabled    no
strip binaries    yes
profiler          no
static build      no
SDL support       yes (2.0.10)
SDL image support no
GTK support       no
GTK GL support    no
VTE support       no
TLS priority      NORMAL
GNUTLS support    no
libgcrypt         no
nettle            no
libtasn1          no
PAM               no
iconv support     yes
curses support    no
virgl support     no
curl support      yes
mingw32 support   no
Audio drivers      oss
Block whitelist (rw)
Block whitelist (ro)
VirtFS support    no
Multipath support no
VNC support       yes
VNC SASL support  no
VNC JPEG support  no
VNC PNG support   yes
xen support       no
brlapi support    no
bluez  support    no
Documentation     no
PIE               yes
vde support       no
netmap support    no
Linux AIO support no
ATTR/XATTR support yes
Install blobs     yes
KVM support       yes
HAX support       no
HVF support       no
WHPX support      no
TCG support       yes
TCG debug enabled no
TCG interpreter   no
malloc trim support yes
RDMA support      no
PVRDMA support    no
fdt support       git
membarrier        no
preadv support    yes
fdatasync         yes
madvise           yes
posix_madvise     yes
posix_memalign    yes
libcap-ng support no
vhost-net support yes
vhost-crypto support yes
vhost-scsi support yes
vhost-vsock support yes
vhost-user support yes
vhost-user-fs support yes
Trace backends    log
spice support     no
rbd support       no
xfsctl support    no
smartcard support no
libusb            no
usb net redir     no
OpenGL support    no
OpenGL dmabufs    no
libiscsi support  no
libnfs support    no
build guest agent yes
QGA VSS support   no
QGA w32 disk info no
QGA MSI support   no
seccomp support   no
coroutine backend ucontext
coroutine pool    yes
debug stack usage no
mutex debugging   no
crypto afalg      no
GlusterFS support no
gcov              gcov
gcov enabled      no
TPM support       yes
libssh support    no
QOM debugging     yes
Live block migration yes
lzo support       no
snappy support    no
bzip2 support     no
lzfse support     no
NUMA host support no
libxml2           no
tcmalloc support  no
jemalloc support  no
avx2 optimization yes
replication support yes
VxHS block device no
bochs support     yes
cloop support     yes
dmg support       yes
qcow v1 support   yes
vdi support       yes
vvfat support     yes
qed support       yes
parallels support yes
sheepdog support  yes
capstone          internal
libpmem support   no
libudev           no
default devices   yes
plugin support    no
cross containers  no

然后安装

make && make install

3. xv6运行

git clone https://github.com/yaoliu/xv6-public
cd xv6-public
make
运行方式
make qemu 
或者使用make-gdb的方式运行
使用qemu-system-i386 -serial mon:stdio -hdb fs.img xv6.img -smp 1 -m 512
以上三种均可

以上是关于:qemu启动xv6问题记录的主要内容,如果未能解决你的问题,请参考以下文章

MIT6.828centos7下使用Qemu搭建xv6运行环境

xv6 + Qemu 在Ubuntu下编译运行教程

运行xv6

关于操作系统项目课的环境搭建——在ubuntu上,安装xv6和qemu

MIT6.828准备:MacOS下搭建xv6和risc-v环境

MIT6.828准备:MacOS下搭建xv6和risc-v环境