一键编译并启动一个 ARM Linux qemu 虚拟机

需要事先自己编译 qemu-system-arm 可执行文件;

1,编译创建ARM 虚拟机

1.1 一起从头开始版

cd 进一个空文件夹,然后

$ vim buildup.sh

$ bash buildup.sh

访问github网络没什么问题:

硬编码了一个路径/home/hipper/ex_vexpress/ 两处,

改成自己的当前路径即可,懒得改了,见谅见笑了 ^^

buildup.sh:

#!/usr/bin/bash
mkdir workspace
cd workspace
git clone https://github.com/qemu/qemu.git
cd qemu/
git checkout v9.0.0
mkdir build_arm/
cd ./build_arm/
../configure --target-list="arm-softmmu,arm-linux-user" --prefix=/home/hipper/ex_vexpress/workspace/qemu-bin-arm/
make -j
make install
cd ../../
sudo ls
sudo apt-get install gcc-arm-linux-gnueabi
wget https://mirrors.edge.kernel.org/pub/linux/kernel/v5.x/linux-5.10.tar.gz
tar zxf linux-kernel-v5.10.tar.gz 
cd linux-5.10/
make CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm vexpress_defconfig
make CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm -j
cd ../
wget https://ftp.denx.de/pub/u-boot/u-boot-2020.10.tar.bz2
tar xf u-boot-2020.10.tar.bz2 
cd u-boot-2020.10/
make vexpress_ca9x4_defconfig
make CROSS_COMPILE=arm-linux-gnueabi- all
cd ../
wget https://busybox.net/downloads/busybox-1.36.0.tar.bz2
tar xf busybox-1.36.0.tar.bz2 
cd busybox-1.36.0/
make defconfig
make CROSS_COMPILE=arm-linux-gnueabi-
make install CROSS_COMPILE=arm-linux-gnueabi-
cd ../
mkdir -p rootfs/{dev,etc/init.d,lib,proc,sys,root,home}
sudo cp busybox-1.36.0/_install/* -r rootfs/
sudo cp -P /usr/arm-linux-gnueabi/lib/* rootfs/lib/
sudo mknod rootfs/dev/tty1 c 4 1 && sudo mknod rootfs/dev/tty2 c 4 2 && sudo mknod rootfs/dev/tty3 c 4 3 && sudo mknod rootfs/dev/tty4 c 4 4
dd if=/dev/zero of=a9rootfs.ext3 bs=1M count=1024
mkfs.ext3 a9rootfs.ext3
sudo mkdir tmpfs && sudo mount -t ext3 a9rootfs.ext3 tmpfs/ -o loop && sudo cp -r rootfs/*  tmpfs/ && sudo umount tmpfs
/home/hipper/ex_vexpress/workspace/qemu-bin-arm/bin/qemu-system-arm -M vexpress-a9 -m 512M \
-kernel ./linux-5.10/arch/arm/boot/zImage \
-dtb    ./linux-5.10/arch/arm/boot/dts/vexpress-v2p-ca9.dtb \
-nographic -append "root=/dev/mmcblk0  console=ttyAMA0" -sd a9rootfs.ext3

运行效果:

1.2 如果系统中已经安装了qemu-system-arm

$ vim buildup_haveqemuarm.sh

$ bash ./buildup_haveqemuarm.sh

其中:

buildup_haveqemuarm.sh:

bash 复制代码
#!/usr/bin/bash 
 sudo ls
 sudo apt-get install gcc-arm-linux-gnueabi
 mkdir workspace
 cd workspace/
 wget https://mirrors.edge.kernel.org/pub/linux/kernel/v5.x/linux-5.10.tar.gz
 tar zxf linux-5.10.tar.gz 
 cd linux-5.10/
 make CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm vexpress_defconfig
 make CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm -j
 cd ../
 wget https://ftp.denx.de/pub/u-boot/u-boot-2020.10.tar.bz2
 tar xf u-boot-2020.10.tar.bz2 
 cd u-boot-2020.10/
 make vexpress_ca9x4_defconfig
 make CROSS_COMPILE=arm-linux-gnueabi- all
 cd ../
 wget https://busybox.net/downloads/busybox-1.36.0.tar.bz2
 tar xf busybox-1.36.0.tar.bz2 
 cd busybox-1.36.0/
 make defconfig
 make CROSS_COMPILE=arm-linux-gnueabi-
 make install CROSS_COMPILE=arm-linux-gnueabi-
 cd ../
 mkdir -p rootfs/{dev,etc/init.d,lib,proc,sys,root,home}
 sudo cp busybox-1.36.0/_install/* -r rootfs/
 sudo cp -P /usr/arm-linux-gnueabi/lib/* rootfs/lib/
 sudo mknod rootfs/dev/tty1 c 4 1 && sudo mknod rootfs/dev/tty2 c 4 2 && sudo mknod rootfs/dev/tty3 c 4 3 && sudo mknod rootfs/dev/tty4 c 4 4
 dd if=/dev/zero of=a9rootfs.ext3 bs=1M count=1024
 mkfs.ext3 a9rootfs.ext3
 sudo mkdir tmpfs && sudo mount -t ext3 a9rootfs.ext3 tmpfs/ -o loop && sudo cp -r rootfs/*  tmpfs/ && sudo umount tmpfs
 qemu-system-arm -M vexpress-a9 -m 512M -kernel ./linux-5.10/arch/arm/boot/zImage -dtb    ./linux-5.10/arch/arm/boot/dts/vexpress-v2p-ca9.dtb -nographic -append "root=/dev/mmcblk0  console=ttyAMA0" -sd a9rootfs.ext3

启动后的虚拟机:

2, 编译新的可执行文件

vim ../ex/hello.c

cpp 复制代码
#include <stdio.h>

int main()
{
	printf("Hello Test Kernel ll\n");

	return 0;

}

3,在虚拟机中添加新的可执行文件

cp ../ex/hello busybox-1.36.0/_install/bin/

然后执行 update_exe_arm.sh:

bash 复制代码
 rm -rf a9rootfs.ext3
 sudo rm rootfs/* -rf
 mkdir -p rootfs/{dev,etc/init.d,lib,proc,sys,root,home}
 sudo cp busybox-1.36.0/_install/* -r rootfs/
 sudo cp -P /usr/arm-linux-gnueabi/lib/* rootfs/lib/
 sudo mknod rootfs/dev/tty1 c 4 1 && sudo mknod rootfs/dev/tty2 c 4 2 && sudo mknod rootfs/dev/tty3 c 4 3 && sudo mknod rootfs/dev/tty4 c 4 4
 dd if=/dev/zero of=a9rootfs.ext3 bs=1M count=1024
 mkfs.ext3 a9rootfs.ext3
 rm -rf tmpfs/
 sudo mkdir tmpfs && sudo mount -t ext3 a9rootfs.ext3 tmpfs/ -o loop && sudo cp -r rootfs/*  tmpfs/ && sudo umount tmpfs
 /home/hipper/ex_systemc_qemu/qemu-bin-v9-arm/bin/qemu-system-arm -M vexpress-a9 -m 512M -kernel ./linux-5.10/arch/arm/boot/zImage -dtb    ./linux-5.10/arch/arm/boot/dts/vexpress-v2p-ca9.dtb -nographic -append "root=/dev/mmcblk0  console=ttyAMA0" -sd a9rootfs.ext3

虚拟机中执行hello;

相关推荐
soulteary1 小时前
突破内存限制:Mac Mini M2 服务器化实践指南
运维·服务器·redis·macos·arm·pika
byte轻骑兵1 天前
嵌入式 ARM Linux 系统构成全解:从硬件到应用层层剖析
linux·arm开发·arm·嵌入式开发
Linux运维技术栈1 天前
基于CVE安全公告号,全面修复麒麟ARM系统OpenSSH漏洞
安全·系统安全·arm
TeYiToKu2 天前
笔记整理—linux驱动开发部分(13)块设备
linux·c语言·驱动开发·笔记·嵌入式硬件·arm
fareast_mzh4 天前
no matching manifest for linux/amd64 in the manifest list entries
docker·arm·raspberry·busybox
yanlaifan5 天前
ARM(安谋) China处理器
arm
Linux运维技术栈7 天前
企业生产环境-麒麟V10(ARM架构)操作系统部署Zookeeper单节点&集群版
linux·运维·zookeeper·架构·arm
Linux运维技术栈7 天前
企业生产环境-麒麟V10(ARM架构)操作系统部署kafka高可用集群
linux·运维·架构·kafka·arm
嵌入式小能手9 天前
CAN编程示例之socket CAN
linux·arm
Chervin10 天前
Windows,虚拟机Ubuntu和开发板三者之间的NFS服务器搭建
linux·单片机·ubuntu·arm