QEMU模拟ARM64运行linux
安装qemu
$ sudo dnf install -y qemu
下载busybox
https://busybox.net/downloads/
下载busybox-1.32.1.tar.bz2
编译busybox
- 解压缩busybox-1.32.1.tar.bz2
$ mkdir ~/qemu-image
$ cp busybox-1.32.1.tar.bz2 ~/qemu-image
$ cd ~/qemu-image
$ tar xjvf busybox-1.32.1.tar.bz2
$ cd busybox-1.32.1
$ make ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu- defconfig
$ make menuconfig //设置CONFIG_STATIC=y
$ make ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu- install
制作文件系统
$ cd ~/qemu-image/
$ mkdir rootfs
cp -rf busybox-1.32.1/_install/* rootfs/
cd rootfs
mkdir dev etc proc
cd etc
vim inittab
添加文件inittab,内容为:
::sysinit:/etc/init.d/rcS
::respawn:-/bin/sh
::askfirst:-/bin/sh
::ctrlaltdel:/bin/umount -a -r
mkdir init.d
cd init.d
vim rcS
创建文件rcS,内容为:
#!/bin/sh
mount -t proc proc /proc
cd ../..
find . | cpio -o -H newc > rootfs.img
编译内核
$ cp linux-5.4.tar ~/qemu-image
$ cd ~/qemu-image
$ tar xvf linux-5.4.tar
$ cd linux-5.4
$ make ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu- defconfig
$ make ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu- Image -j8
运行qemu
qemu-system-aarch64 -machine virt -cpu cortex-a53 -machine type=virt -nographic -m 2048 -smp 2 -kernel linux-5.4/arch/arm64/boot/Image -initrd ./rootfs/rootfs.img -append "root=/dev/ram0 rootfstype=ramfs rdinit=/linuxrc console=ttyAMA0"