qemu模拟arm64一直卡住不动

问题描述

运行qemu-system-aarch64后一直卡在那里不动,终端无信息输出

PC机:Ubuntu 16.04系统
Kernel镜像:下载Kernel 4.9.4源码,自行编译arm64镜像
qemu-system-aarch64版本:Ubuntu系统自带,应为2.5版本
运行命令:qemu-system-aarch64 -machine virt -cpu cortex-a57 -machine type=virt -nographic -m 2048 -smp 2 -kernel arch/arm64/boot/Image --append “rdinit=/linuxrc console=ttyAMA0”
大部分操作参考《奔跑吧Linux内核》,之前有尝试运行32位arm虚拟机,可以成功运行。

做过的尝试

起初怀疑命令行参数有问题,有尝试过修改ram大小,cpu型号等,都没有效果。
后来把kernel 4.9.4改成4.0,下载源码编译后还是有问题;然后就直接使用奔跑吧的github上的4.0,还是有问题。
在微信群里求教,也没有得到有用的答复。
最后怀疑是笔记本配置太低,带不起来,这个问题就此搁置了一段时间。
这个问题最麻烦的是没有输出,也不知道该如何调试。

解决方法

发现编译内核方法有问题

今天心血来潮,换了个配置较高的台式机,重装个ubuntu 16.04系统,想再跑一跑,看是否真和电脑配置有关系。实验下来,发现也不行。所以,和电脑配置没有关系。
在实验过程中,发现网上有人说一种编译方法,和我之前的操作不太一样,引起了我的关注。使用这个方法在4.0内核上就可以运行了。
我之前的编译内核方法:
1.下载内核源码(https://mirrors.edge.kernel.org/pub/linux/kernel/v4.x/)
2.解压tar.gz文件
3.把编译好的64位busybox拷贝到代码中,也就是把_install_arm64目录拷贝到代码根目录下
4.创建文件节点
$ cd _install_arm64/dev
$ sudo mknod console c 5 1
$ sudo mknod null c 1 3
5. 配置环境变量
$ export ARCH=arm64
$ export CROSS_COMPILE=aarch64-linux-gnu-
6. make menuconfig (照书中所述,把_install_arm64配置到Initramfs source file中)
7. make -j4
新的编译方式中,我会在6之前先执行make defconfig,然后再make menuconfig
(请原谅一个新手吧:连linux如何编译也没有搞清楚)
虽然只增加了make defconfig,我发现两点变化:一是编译时间特别短,5分钟基本就已经编译完成,而我之前要编译半小时以上;对于kernel 4.0,qemu可以运行起来了,不过kernel 4.9还是会卡在那里不动。

更新qemu到3.0解决问题

既然发现问题与kernel版本有关,我又试了几个版本,发现kernel 4.4也可以,4.6就不行。这么无头绪地试了试。后来突然想到会不会和qemu有关,所以去官网上下载、编译和安装最新的3.0版本,果然解决问题。
下载网页:https://www.qemu.org/download/
解压后的编译命令:
$ ./configure --target-list=aarch64-softmmu
$ make
$ sudo make install
其中,configure时遇到了这个错误
ERROR: glib-2.40 gthread-2.0 is required to compile QEMU
解决方法:
$ sudo apt-get install libglib2.0-dev
重新运行又遇到这个错误
ERROR: pixman >= 0.21.8 not present.
Please install the pixman devel package.
解决方法:
$ sudo apt-get install libpixman-1-dev

make完成后,会生成bin文件,可以看下新的版本号
$ ./aarch64-softmmu/qemu-system-aarch64 --version
QEMU emulator version 3.0.0
Copyright © 2003-2017 Fabrice Bellard and the QEMU Project developers

sudo make install之后,需要重新打开个终端,就能看到版本已经是3.0。
./qemu-system-aarch64 -machine virt -cpu cortex-a57 -machine type=virt -nographic -m 2048 -smp 2 -kernel arch/arm64/boot/Image --append “rdinit=/linuxrc console=ttyAMA0”

其它

在老版本的kernel中,碰到输出的日志前面没有时间信息的问题,是因为默认没有打开一个配置:
Kernel hacking —>
printk and dmesg options —>
Show timing information on printks

额,最后贴你行成功运行后输出的日志吧。
[ 0.000000] Booting Linux on physical CPU 0x0
[ 0.000000] Linux version 4.9.4 (yutao@yutao) (gcc version 5.4.0 20160609 (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.9) ) #1 SMP PREEMPT Wed Oct 3 23:06:09 CST 2018
[ 0.000000] Boot CPU: AArch64 Processor [411fd070]
[ 0.000000] efi: Getting EFI parameters from FDT:
[ 0.000000] efi: UEFI not found.
[ 0.000000] cma: Reserved 16 MiB at 0x00000000bf000000
[ 0.000000] psci: probing for conduit method from DT.
[ 0.000000] psci: PSCIv0.2 detected in firmware.
[ 0.000000] psci: Using standard PSCI v0.2 function IDs
[ 0.000000] psci: Trusted OS migration not required
[ 0.000000] percpu: Embedded 21 pages/cpu @ffff80007efbf000 s47896 r8192 d29928 u86016
[ 0.000000] Detected PIPT I-cache on CPU0
[ 0.000000] CPU features: enabling workaround for ARM erratum 832075
[ 0.000000] CPU features: enabling workaround for ARM erratum 834220
[ 0.000000] Built 1 zonelists in Zone order, mobility grouping on. Total pages: 516096
[ 0.000000] Kernel command line: rdinit=/linuxrc console=ttyAMA0
[ 0.000000] PID hash table entries: 4096 (order: 3, 32768 bytes)
[ 0.000000] Dentry cache hash table entries: 262144 (order: 9, 2097152 bytes)
[ 0.000000] Inode-cache hash table entries: 131072 (order: 8, 1048576 bytes)
[ 0.000000] Memory: 2028240K/2097152K available (8380K kernel code, 858K rwdata, 3644K rodata, 2112K init, 280K bss, 52528K reserved, 16384K cma-reserved)
[ 0.000000] Virtual kernel memory layout:
[ 0.000000] modules : 0xffff000000000000 - 0xffff000008000000 ( 128 MB)
[ 0.000000] vmalloc : 0xffff000008000000 - 0xffff7dffbfff0000 (129022 GB)
[ 0.000000] .text : 0xffff000008080000 - 0xffff0000088b0000 ( 8384 KB)
[ 0.000000] .rodata : 0xffff0000088b0000 - 0xffff000008c50000 ( 3712 KB)
[ 0.000000] .init : 0xffff000008c50000 - 0xffff000008e60000 ( 2112 KB)
[ 0.000000] .data : 0xffff000008e60000 - 0xffff000008f36a00 ( 859 KB)
[ 0.000000] .bss : 0xffff000008f36a00 - 0xffff000008f7cc3c ( 281 KB)
[ 0.000000] fixed : 0xffff7dfffe7fd000 - 0xffff7dfffec00000 ( 4108 KB)
[ 0.000000] PCI I/O : 0xffff7dfffee00000 - 0xffff7dffffe00000 ( 16 MB)
[ 0.000000] vmemmap : 0xffff7e0000000000 - 0xffff800000000000 ( 2048 GB maximum)
[ 0.000000] 0xffff7e0000000000 - 0xffff7e0002000000 ( 32 MB actual)
[ 0.000000] memory : 0xffff800000000000 - 0xffff800080000000 ( 2048 MB)
[ 0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=2, Nodes=1

  • 7
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值