使用QEMU仿真ARM Linux系统

本文介绍如何使用 QEMU 模拟 ARM 架构并安装 Debian 系统。包括创建虚拟硬盘、安装 Linux 系统及运行步骤。此外还提供了安装过程中所需的内核、initrd 文件下载链接。

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

使用方法,网上有很多文章可以参考:
http://www.aurel32.net/info/debian_arm_qemu.php
http://qemu-forum.ipi.fi/viewtopic.php?p=11353
http://jun7903.blog.sohu.com/rss
http://en.opensuse.org/MicroSUSE_System_Builder%27s_Guide

创建一个虚拟硬盘
$ qemu-img create -f qcow hda.img 10G

创建文件系统
sudo dd if=/dev/zero of=rootfs.img bs=1M count=100
sudo mkfs.ext2 -N 512 rootfs.img


安装Linux系统
$ qemu-system-arm -M versatilepb -kernel vmlinuz-2.6.18-6-versatile -initrd initrd.gz -hda hda.img -append "root=/dev/ram"


运行Linux系统
$ qemu-system-arm -M versatilepb -kernel vmlinuz-2.6.18-6-versatile -initrd initrd.img-2.6.18-6-versatile -hda hda.img -append "root=/dev/sda1"


qemu-system-arm -kernel zImage.integrator -initrd arm_root.img -nographic -append "console=ttyAMA0"


qemu-system-arm -kernel <path to the kernel image>/zImage-<kernel version>-qemu-arm -initrd ususe.img -nographic -append console=ttyAMA0

Framebuffer console:

qemu-system-arm -kernel <path to the kernel image>/zImage-<kernel version>-qemu-arm -initrd ususe.img -append console=tty1



转载示例
先安装Qemu,因为sdl很难搞定.linux建议下载qemu-0.8.2-i386.tar.gz,在根目录下解压即可,自动安装到bin.
创建模拟盘
sudo qemu-img create -f qcow hda.img 1G
下载kernel
sudo wget http://people.debian.org/~aurel32/arm-versatile/vmlinuz-2.6.18-2-versatile
sudo wget http://people.debian.org/~aurel32/arm-versatile/initrd.img-2.6.18-2-versatile
下载initrd安装文件
sudo wget http://ftp.nl.debian.org/debian/dists/testing/main/installer-arm/rc1/images/rpc/netboot/initrd.gz
安装Debian Etch(在桌面环境下)
sudo qemu-system-arm -M versatilepb -kernel vmlinuz-2.6.18-2-versatile -initrd initrd.gz -hda hda.img -append "root=/dev/ram"
跳过安装
运行(在桌面环境下)
sudo qemu-system-arm -M versatilepb -kernel vmlinuz-2.6.18-2-versatile -initrd initrd.img-2.6.18-2-versatile -hda hda.img -append "root=/dev/sda1"
出现login之后退出
安装相应的内核
sudo apt-get install initramfs-tools
sudo wget http://people.debian.org/~aurel32/arm-versatile/linux-image-2.6.18-2-versatile_2.6.18-5+versatile_arm.deb
sudo dpkg -i linux-image-2.6.18-2-versatile_2.6.18-5+versatile_arm.deb
然后重新运行qemu
进入命令行,输入dmeg出现 arm的提示就ok





如下是qemu-system-arm的帮助文件:
QEMU PC emulator version 0.9.0, Copyright (c) 2003-2007 Fabrice Bellard
usage: qemu [options] [disk_image]

'disk_image' is a raw hard image image for IDE hard disk 0

Standard options:
-M machine select emulated machine (-M ? for list)
-fda/-fdb file use 'file' as floppy disk 0/1 image
-hda/-hdb file use 'file' as IDE hard disk 0/1 image
-hdc/-hdd file use 'file' as IDE hard disk 2/3 image
-cdrom file use 'file' as IDE cdrom image (cdrom is ide1 master)
-boot [a|c|d|n] boot on floppy (a), hard disk (c), CD-ROM (d), or network (n)
-snapshot write to temporary files instead of disk image files
-no-quit disable SDL window close capability
-m megs set virtual RAM size to megs MB [default=128]
-smp n set the number of CPUs to 'n' [default=1]
-nographic disable graphical output and redirect serial I/Os to console
-k language use keyboard layout (for example "fr" for French)
-localtime set the real time clock to local time [default=utc]
-full-screen start in full screen
-usb enable the USB driver (will be the default soon)
-usbdevice name add the host or guest USB device 'name'

Network options:
-net nic[,vlan=n][,macaddr=addr][,model=type]
create a new Network Interface Card and connect it to VLAN 'n'
-net user[,vlan=n][,hostname=host]
connect the user mode network stack to VLAN 'n' and send
hostname 'host' to DHCP clients
-net tap[,vlan=n][,fd=h][,ifname=name][,script=file]
connect the host TAP network interface to VLAN 'n' and use
the network script 'file' (default=/etc/qemu-ifup);
use 'script=no' to disable script execution;
use 'fd=h' to connect to an already opened TAP interface
-net socket[,vlan=n][,fd=h][,listen=[host]:port][,connect=host:port]
connect the vlan 'n' to another VLAN using a socket connection
-net socket[,vlan=n][,fd=h][,mcast=maddr:port]
connect the vlan 'n' to multicast maddr and port
-net none use it alone to have zero network devices; if no -net option
is provided, the default is '-net nic -net user'

-tftp prefix allow tftp access to files starting with prefix [-net user]
-smb dir allow SMB access to files in 'dir' [-net user]
-redir [tcp|udp]:host-port:[guest-host]:guest-port
redirect TCP or UDP connections from host to guest [-net user]

Linux boot specific:
-kernel bzImage use 'bzImage' as kernel image
-append cmdline use 'cmdline' as kernel command line
-initrd file use 'file' as initial ram disk

Debug/Expert options:
-monitor dev redirect the monitor to char device 'dev'
-serial dev redirect the serial port to char device 'dev'
-parallel dev redirect the parallel port to char device 'dev'
-pidfile file Write PID to 'file'
-S freeze CPU at startup (use 'c' to start execution)
-s wait gdb connection to port 1234
-p port change gdb connection port
-d item1,... output log to /tmp/qemu.log (use -d ? for a list of log items)
-hdachs c,h,s[,t] force hard disk 0 physical geometry and the optional BIOS
translation (t=none or lba) (usually qemu can guess them)
-L path set the directory for the BIOS, VGA BIOS and keymaps
-no-reboot exit instead of rebooting
-loadvm file start right away with a saved state (loadvm in monitor)
-vnc display start a VNC server on display
-daemonize daemonize QEMU after initializing
-option-rom rom load a file, rom, into the option ROM space

During emulation, the following keys are useful:
ctrl-alt-f toggle full screen
ctrl-alt-n switch to virtual console 'n'
ctrl-alt toggle mouse and keyboard grab

When using -nographic, press 'ctrl-a h' to get some help.

 

### 关于Linux设备驱动开发中使用QEMU模拟ARM的相关资料 #### QEMU简介及其在ARM环境下的应用 QEMU是一个开源的仿真器和虚拟机监视器,支持多种架构。对于ARM平台而言,QEMU能够提供一个完整的硬件抽象层来运行未经修改的操作系统镜像[^1]。 #### 安装与配置QEMU用于ARM Linux平台 为了利用QEMU进行ARM Linux平台上的工作,在本地环境中需先完成QEMU软件包的获取与设置: - 下载并安装适合操作系统QEMU版本; - 验证安装是否成功通过命令`qemu-system-arm --version`查看版本号; 上述过程确保了后续实验的基础环境搭建完毕。 #### 编译适用于QEMUARM内核 针对特定需求定制化的Linux内核编译是必要的步骤之一。这涉及到几个方面的工作: - 获取目标平台对应的内核源码树; - 对其进行适当配置以适应所选的机器类型(如Versatile Express等); - 执行实际构建流程得到可用于加载执行的目标文件uImage或zImage形式; 此阶段完成后即可准备启动测试实例。 ```bash make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- ``` #### 构建最小化根文件系统 创建精简版rootfs有助于减少不必要的复杂度,并加快迭代速度。BusyBox项目提供了便捷的方式实现这一点: - 解压官方发布的预构建tarball至指定位置作为初始模板; - 修改其中的关键路径指向以便匹配预期布局; - 将调整后的结构打包成img格式供下一步骤调用; 最终产物应当包含基本shell工具集以及任何额外依赖项。 #### 启动QEMU会话连接到新建立的ARM环境 借助之前准备工作积累下来的资源,现在可以尝试开启一次交互式的session来进行初步验证: ```bash qemu-initrd rootfs.img -append "console=ttyAMA0,38400 kgdboc=ttyAMA0,38400" -serial stdio ``` 这条指令指定了要使用的machine model、kernel image还有ramdisk archive的同时也设置了串口重定向方便观察输出日志流。 #### 加入外设驱动的支持 当基础框架已经稳固下来以后,则可进一步探索如何集成自定义硬件组件的能力。具体做法如下所示: - 移步至对应driver source code所在的位置; - 应用交叉编译链生成适配当前体系结构的对象; - 把产出物安置进先前预备好的filesystem内部相应地方去; 如此这般便实现了功能扩展的目的[^3]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值