用qemu-system-aarch64起Linux虚拟机

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

第一步:安装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 是一个通用的开源机器模拟器和虚拟化器,它支持多种架构,包括 ARM64(aarch64)。`qemu-system-aarch64` 是 QEMU 中用于模拟 ARM64 架构的虚拟机的命令行工具。通过这个工具,用户可以在非 ARM64 的宿主机上模拟 ARM64 环境,例如在 x86_64 架构的宿主机上运行 ARM64 Linux 内核。 以下是使用 `qemu-system-aarch64` 启动 ARM64 Linux 内核的一些关键步骤和参数: 1. **查看版本号**: ```shell qemu-system-aarch64 --version ``` 这个命令用于查看当前安装的 `qemu-system-aarch64` 版本信息。 2. **启动 ARM64 Linux 内核**: ```shell qemu-system-aarch64 -M virt -cpu cortex-a53 -nographic -kernel linux-6.7/arch/arm64/boot/Image --append "console=ttyAMA0" -initrd ./rootfs.cpio ``` 这个命令启动了一个虚拟机,其中 `-M virt` 指定了使用虚拟的机器类型,`-cpu cortex-a53` 指定了 CPU 类型,`-nographic` 表示不使用图形界面,`-kernel` 指定了内核映像的路径,`--append` 用于添加启动参数,`-initrd` 指定了初始 RAM 磁盘的路径。 3. **退出 QEMU 虚拟机**: 在 QEMU 虚拟机运行时,同时按下 `ctrl + a`,然后松开,再按下 `x`,即可退出虚拟机回到原本的终端窗口。 4. **启动带有 virtio 设备的虚拟机**: ```shell qemu-system-aarch64 -name vm2 -daemonize -enable-kvm -M virt -cpu host -smp 2 -m 4096 -global virtio-blk-device.scsi=off -device virtio-scsi-device,id=scsi -kernel vmlinuz-4.18 --append "console=ttyAMA0 root=UUID=6a09973e-e8fd-4a6d-a8c0-1deb9556f477" -initrd initramfs-4.18 -drive file=vhuser-test1.qcow2 -netdev user,id=unet,hostfwd=tcp:127.0.0.1:1122-:22 -device virtio-net-device,netdev=unet -vnc :10 ``` 这个命令启动了一个带有 virtio 设备的虚拟机,其中 `-enable-kvm` 表示启用 KVM 加速,`-M virt` 指定了使用虚拟的机器类型,`-cpu host` 表示使用宿主机的 CPU 类型,`-smp` 指定了虚拟 CPU 的数量,`-m` 指定了内存大小,`-drive` 指定了磁盘镜像文件,`-netdev` 和 `-device` 用于配置网络设备。 5. **环境信息**: 用户的环境信息包括宿主机硬件平台为 x86_64,宿主机操作系统为 Ubuntu 20.04,QEMU 版本为 qemu-4.2.1,实验内核为 linux-5.19,busybox 版本为 busybox-1.35.0。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值