用qemu-system-aarch64起Linux虚拟机

本文介绍如何使用 QEMU 进行 aarch64 架构的系统仿真。首先通过 apt-get 安装 qemu,然后下载预构建的 build-root kernel 镜像,并使用 qemu-system-aarch64 启动虚拟机。文章还提供了构建 QEMU 的详细步骤及所需依赖。

第一步:安装qemu

apt-get -y qemu 

第二步:下载build-root kernel镜像,并用qemu-system-aarch64 起虚拟机

wget http://people.linaro.org/~alex.bennee/images/aarch64-linux-3.15rc2-buildroot.img
qemu-system-aarch64 -machine virt -cpu cortex-a57 -machine type=virt -nographic -smp 1 -m 2048 -kernel aarch64-linux-3.15rc2-buildroot.img  --append "console=ttyAMA0"

来源:

Running Linux in QEMU’s aarch64 system emulation mode

Since I started working on aarch64 support for QEMU the most frequently asked question I got was “when can I run aarch64 system emulation on QEMU?”. Well wait no more as support for a VIRT-IO based aarch64 board was recently merged into the master branch of QEMU. In this post I’ll talk about building QEMU, a rootfs and a kernel that will allow you to start experimenting with the architecture.

Quick start

Let’s first start with building and running QEMU with some pre-built images.

BUILD DEPENDANCIES

As has been noted in the comments the configure script will automatically enable features as long as the pre-requisite developer libraries are installed on your sytem. With a Debian/Ubuntu system this is easily achieved by running:

sudo apt-get build-dep qemu  

Of course if you want to enable a feature (either a bleeding edge or non-standard) that requires additional libraries then you will need to install the appropriate development packages manually. The config.log file is usually a useful first step in working out what headers are being looked for.

BUILDING QEMU
git clone git://git.qemu.org/qemu.git qemu.git
cd qemu.git
./configure --target-list=aarch64-softmmu
make

Assuming the build ran without any problems you should now have an executable ./aarch64-softmmu/qemu-system-aarch64 in your build directory. Grab a pre-built image from here and we’ll check it works. The image is a kernel that has been combined with an initial RAM disk (initrd) with a basic root file-system. I go into more details on how to create this later on.

Be aware the command line is quite long so make sure you copy it all 

### 功能 `qemu-system-aarch64.exe` 是 QEMU 模拟器的一部分,主要用于模拟 ARM64(AArch64)架构的计算机系统。借助该工具可在不同架构的物理机上运行 ARM64 架构的操作系统和应用程序,常用于开发、测试和调试基于 ARM64 架构的软件,例如在非 ARM64 架构的机器上测试 ARM64 版本的 Linux 系统、开发 ARM64 架构的嵌入式软件等 [^1]。 ### 使用方法 #### 简单启动示例 ```bash qemu-system-aarch64 -hda /path/to/your/arm64_image.qcow2 -m 2048 -smp 2 ``` 上述命令中,`-hda` 指定要使用的磁盘镜像文件,`-m` 设置虚拟机的内存大小为 2048MB,`-smp` 设置虚拟机的 CPU 核心数为 2 [^1]。 #### 指定 BIOS 启动 使用 `qemu-system-aarch64` 启动 ARM 架构的 qcow2 镜像时,若出现卡在 `qemu monitor` 的情况,需指定 `qemu_efi.fd` 的 EFI 文件,示例如下: ```bash qemu-system-aarch64 -hda /path/to/your/arm64_image.qcow2 -m 2048 -smp 2 -bios ./QEMU_EFI.fd ``` #### 特定版本及参数启动 切换到 `qemu-system-aarch64-3.1.0` 版本,并使用特定参数启动的示例如下: ```bash qemu-3.1.0/aarch64-softmmu/qemu-system-aarch64 -machine virt,gic_version=3 -machine virtualization=true -cpu cortex-a57 -machine type=virt -m 4096 -smp 4 -bios u-boot.bin -device loader,file=xen,force-raw=on,addr=0x49000000 -device loader,file=Image.gz,addr=0x47000000 -device loader,file=virt-gicv3.dtb,addr=0x44000000 -device loader,file=rootfs.img.gz,addr=0x42000000 -nographic -no-reboot -chardev socket,id=qemu-monitor,host=localhost,port=7777,server,nowait,telnet -mon qemu-monitor,mode=readline ``` ### 常见问题 #### 卡在 qemu monitor 使用 `qemu-system-aarch64` 启动 ARM 架构的 qcow2 镜像时,若一直卡在 `qemu monitor` 中,是因为没有指定 BIOS,需指定 `qemu_efi.fd` 的 EFI 文件来解决该问题 [^1]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值