Chinaunix首页 | 论坛 | 博客
  • 博客访问: 9393008
  • 博文数量: 1747
  • 博客积分: 12961
  • 博客等级: 上将
  • 技术积分: 20060
  • 用 户 组: 普通用户
  • 注册时间: 2009-01-09 11:25
个人简介

偷得浮生半桶水(半日闲), 好记性不如抄下来(烂笔头). 信息爆炸的时代, 学习是一项持续的工作.

文章分类

全部博文(1747)

文章存档

2024年(23)

2023年(26)

2022年(112)

2021年(217)

2020年(157)

2019年(192)

2018年(81)

2017年(78)

2016年(70)

2015年(52)

2014年(40)

2013年(51)

2012年(85)

2011年(45)

2010年(231)

2009年(287)

分类: LINUX

2009-03-13 14:46:47


sudo apt-get install libsdl1.2-dev zlib1g-dev libasound2-dev linux-kernel-headers pkg-config libgnutls-dev

下载安装 qemu, 最新版本为
./configure --cc=/usr/bin/gcc-x.x --host-cc=/usr/bin/gcc-x.x --target-list=xxx
make

arm 的 disk image (arm-test-0.2.tar.gz), 解壓後照著 README 指示即可執行



QEMU is well-known as a free replacement for VMware, allowing users to run a PC within a PC. What isn't so well known about QEMU is that, in addition to emulating x86 architectures, it can emulate AMD64, Sparc, MIPS, PPC and ARM CPUs.

In the case of the ARM architecture, QEMU provides a convenient, if slow, environment in which development can be done for embedded systems.

This article describes the process involved in building a Debian/ARM server running under QEMU. It assumes that Debian is also being used as the host server.

Since QEMU's arm emulator has no ability to emulate either IDE or SCSI disks, it will be necessary to install the server on an NFS exported partition.

Preparing the host server



Firstly, install the required packages on your host server:


host# apt-get qemu vde nfs-kernel-server debootstrap


debootstrap allows the creation of a base Debian or Ubuntu system, and is a very simple method for building chroots and virtual machines quickly.

is a virtual network emulator, much like user mode linux's uml_net, allowing a QEMU-emulated machine to connect to the host server's network through a tap interface.

Make sure that your host kernel has support for the "Universal TUN/TAP device driver"; the kernel configuration option for this is named "TUN". If you're running a modularised kernel, there's a good chance that it will
be named 'tun.o'.

Once you have a kernel with tun support, set up a tap interface for the emulated machine to communicate through. In /etc/network/interfaces on your host machine, add the following stanza:

auto tap0
iface tap0 inet static
address 10.1.6.1
netmask 255.255.255.0
network 10.1.6.0
broadcast 10.1.6.255
vde-switch vde-net


Ensure that /dev/net/tun is owned by group vde-net and that you are also a member of that group; add this to your host server's /etc/group file and log out and back in again, if necessary.

Then, bring up the interface:

host# ifup tap0


You'll need a partition with enough spare space on it to hold a basic Debian installation; make sure you have enough room on it to grow in the future. You can probably get away with 300Mb at the minimum. I placed my tree under /nfs/share/arm/.

Now, run debootstrap to download and install the base Debian/arm distribution, and copy a few of the files from your host system into it:

host# mkdir /nfs/share/arm
host# debootstrap --foreign --arch arm etch /nfs/share/arm
host# cd /nfs/share/arm
host# cp /etc/passwd etc/passwd
host# cp /etc/shadow etc/shadow
host# cp /etc/group etc/group
host# echo "proc /proc proc defaults 0 0" > etc/fstab
host# echo "10.1.6.1:/nfs/share/arm / nfs defaults 0 1" >> etc/fstab


debootstrap's --foreign option tells it to only perform the first stage of the bootstrap process, downloading and unpacking the packages. Since we're downloading Debian for a different architecture from that on which we're running on the host server, our host system would not be able to use this new system in a chroot to run the pre- and post-installation scripts.



We're going to use the same server that is being used as the host server for running QEMU as the NFS server for the guest server's root filesystem; an emulated system is slow enough as it is, we don't need to make things worse by having a real ethernet network in between the guest OS and its filesystem (as opposed to a virtual ethernet, in this case).

Share the new directory out via NFS, by adding the following entry to /etc/exports:

/nfs/share/arm 10.1.6.0/24(rw,no_root_squash,sync)


Then export the filesystem:

host# exportfs -a


Download a kernel for arm-linux; there's one provided in the arm-test files on the (and a copy .

Place the arm-linux zimage in /usr/local/etc/images/zImage.arm, and then create the following script as /usr/local/bin/start-qemu-arm:

#!/bin/sh

console="ttyAMA0" # serial console
nfsserver="10.1.6.1" # address of NFS server
nfsdir="/nfs/share/arm" # exported share where debian/arm is installed
address="10.1.6.50" # address for guest server
gateway="10.1.6.1" # default gateway
netmask="255.255.255.0" # subnet mask
hostname="arm.home" # hostname for guest server
device="eth0" # interface that guest server will use
mem=256 # memory for guest server in Mb
tap="/var/run/vde/tap0.ctl" # vde tap socket

kernel="/usr/local/etc/images/zImage.arm" # arm kernel
nfsopts="rsize=8192,wsize=8192,hard,intr,tcp,nolock" # nfs options

consoleopt="console=$console"
nfsrootopt="nfsroot=$nfsserver:$nfsdir,$nfsopts"
ipopt="ip=$address::$gateway:$netmask:$hostname:$device"

init=""

if [ "x$1" == "xsingle" ]
then
init="init=/bin/bash"
fi

vdeq qemu-system-arm -sock $tap -m $mem \
-kernel $kernel -nographic \
-append "$consoleopt root=/dev/nfs $nfsrootopt $ipopt $init"


Adjust the parameters at the top of the script to suit your requirements.



Configuring the guest server



Now, start the new arm server in single user mode - from your user account, since it does not need to be run as root:


host$ /usr/local/bin/start-qemu-arm single


The emulated guest server should start up and boot into a bash prompt. The filesystem will be mounted read-only, and it will be necessary to remount it read-write before any further work can be done on it:

guest# mount -n -o remount,rw /
guest# mount /proc


Now run the second stage of debootstrap, within the guest system, to finalise the installation:

guest# cd /
guest# ./debootstrap/debootstrap --second-stage


This will probably take a while to run; the emulator isn't particularly fast. When it's finished, adjust a few remaining files, such as /etc/hostname and /etc/resolv.conf; also install ssh:

guest# apt-get install ssh


Once this is done, you can shut the server down. It's safe to just kill the qemu process from the host machine - since its filesystem is mounted from an NFS server, there's no need to shut it down cleanly.

Now you can start it up completely:

host$ /usr/local/bin/start-qemu-arm


When it finishes booting, you should be able to ssh into it on 10.1.6.50, and you'll have a working Debian installation running on an emulated ARM processor.

Debian on an emulated ARM machine


Introduction

is a generic and open source processor emulator which can emulate i386, x86_64, ARM, MIPS, PowerPC and SPARC systems. In case of ARM, it can emulate an Integrator or a Versatile platform. The Versatile one is the most interesting as it includes a hard disk SCSI controller, an Ethernet card and a graphical display.

Using a kernel compiled with the right options, it is possible to install a distribution on such an emulated platform. That makes a cheap development platform. The emulated system running on an Athlon 64 X2 3800+ is around 20% faster than the popular and possibly with much more RAM (my emulated system has 256MiB of RAM).

This howto has been written for a host system, but could be easily adapted for other distributions.

Alternatively prebuilt images are also available.

Installing QEMU

is currently available as a in the distribution, you will need at least version 0.9.1. If you want to compile it yourself, here is the procedure:

wget

To build QEMU a few packages like SDL needs to be installed on your system. gcc version 3.4 is also needed, as some parts of QEMU do not build with newer gcc versions. As QEMU is present in the archive, just run:

$ su -c "apt-get build-dep qemu"

Then run the configure script:

$ cd qemu-0.9.1
$ ./configure

Then compile it:

$ make

And install it on your system:

$ su -c "make install"

Preparing the installation

First you need to create an image of the hard disk. In my case I have chosen to emulate a 10GB hard-disk, but this size could be changed to correspond to your needs. Note that the file is created in qcow format, so that only the non-empty sectors will be written in the file.

A small tip: create a directory to hold all the files related to the emulated ARM machine.

$ qemu-img create -f qcow hda.img 10G

Debian currently does not support the Versatile platform natively, that means there is no kernel available for this platform. However there is full support for this platform in the . You can either compile your own kernel (using a cross-compiler or an other ARM machine), or use the kernel I have built:

$ wget ~aurel32/arm-versatile/vmlinuz-2.6.18-6-versatile
$ wget ~aurel32/arm-versatile/initrd.img-2.6.18-6-versatile

You also need to get the initrd of the Debian-Installer:

$ wget http://ftp.de.debian.org/debian/dists/etch/main/installer-arm/current/images/rpc/netboot/initrd.gz

Installing Debian Etch

To start the installation process, use the following line:

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

After a few seconds you should see the kernel booting:

Debian-Installer booting

And then the first screen of the Debian-Installer:

First screen of Debian-Installer

Proceed as a normal installation, until you get to the following screen. If you need some documentation, please refer to the

Debian-Installer complains about missing kernel modules

Debian-Installer complains that it can't find kernel modules. This is normal because the initrd of another platform is used. This is not really a problem as the kernel I provide has been compiled with the network driver, the disk driver and ext3 support built-in. However that means you won't be able to install Debian on an XFS partition. This is a known limitation that will disappear if/when the Versatile kernel is integrated in the official Debian kernel.

So in short answer yes, contrarily to what is suggested.

During the installation, Debian installer will complain that it can not found a suitable kernel for this platform, as shown on the screenshot below. This is due to the fact that currently does not support the ARM Versatile platform; the support will be added post-Etch. An unofficial kernel being provided directly to , you can safely ignore this message and continue the installation.

Debian-Installer complains about missing bootloader

Near to the end of the installation you will get the following error screen:

Debian-Installer complains about missing bootloader

Again consider this message as harmless. There is no need for a bootloader, as QEMU is able to directly load a kernel and an initrd.

Then you will get to the end of the installation. Congratulations!

End of the installation

When the systems reboot, just exit QEMU. Different parameters have to be used to boot the installed system.

Using the system

First boot

To start the system use the following command:

$ 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"

After a few seconds the system should give you a login prompt:

Console login

The first thing to do is to install the kernel image corresponding to the running kernel. This will install all the modules that you may need.

$ apt-get install initramfs-tools
$ wget ~aurel32/arm-versatile/linux-image-2.6.18-6-versatile_2.6.18.dfsg.1-18etch1+versatile_arm.deb
$ su -c "dpkg -i linux-image-2.6.18-6-versatile_2.6.18.dfsg.1-18etch1+versatile_arm.deb"

Using Xorg

You now have a full Debian arm system that you can use for development or whatever. You can even run using the fb device. Note that you have to select a 256-color mode, with a resolution up to 1024x768.

Running Xorg

You can even chat on IRC :)

Running Xchat

QEMU without X

If you don't want to start QEMU in graphic mode, you can use the -nographic option, and ask the kernel to use ttyAMA0 as the console. The command to start the emulated machine then become:

$ qemu-system-arm -M versatilepb -kernel vmlinuz-2.6.18-6-versatile -initrd initrd.img-2.6.18-R-versatile -hda hda.img -append "root=/dev/sda1 console=ttyAMA0" -nographic
To set up a getty on the serial port, and be able to login, you must edit /etc/inittab and add the following line:
T0:23:respawn:/sbin/getty -L ttyAMA0 9600 vt100
All users except root should be able to login on this console. To alswo allow root login you must add the following line in /etc/securetty:
ttyAMA0

More RAM

By default QEMU emulate a machine with 128MiB of RAM. You can use the -m option to increase or decrease the size of the RAM. It is however limited to 256MiB, greater sizes will crash the kernel.

Connect your emulated machine to a real network

When no option is specified QEMU uses a non priviledged user mode network stack that gives the emulated machine access to the world. But you probably want to make your emulated machine accessible from the outside. It is possible by using the tap mode and bridging the tap interface with the network interface of the host machine.

The first thing to do is to active a bridge on your host machine. For that you have to modify the /etc/network/interfaces file as follow:

Before:
auto eth0
iface eth0 inet dhcp

After:
auto br0
iface br0 inet dhcp
  bridge_ports eth0
  bridge_maxwait 0

Then you need to install the bridge-utils package and restart your network interface:

# apt-get install bridge-utils
# ifdown eth0
# ifup br0

Create a script call /etc/qemu-ifup that will be executed upon the start of QEMU:

#!/bin/sh
echo "Executing /etc/qemu-ifup"
echo "Bringing up $1 for bridged mode..."
sudo /sbin/ifconfig $1 0.0.0.0 promisc up
echo "Adding $1 to br0..."
sudo /usr/sbin/brctl addif br0 $1
sleep 2

As you probably don't want to execute QEMU as root, you need to create a qemu user group and authorize the brctl and ifconfig commands for users of the qemu via sudo. You need to add the following lines to /etc/sudoers (edit the file using visudo):

...
Cmnd_Alias QEMU = /usr/sbin/brctl, /sbin/ifconfig
%qemu ALL=NOPASSWD: QEMU

Finally you can start your emulated machine using the following command

$ 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" -net nic,macaddr=00:16:3e:00:00:01 -net tap
You don't need to give a MAC address if you are emulating only one machine, as QEMU will use a default one. However if you have more than one emulated machine (don't forget QEMU can also emulate other architectures than ARM), you will have to specify a unique MAC address for each machine. I advise you to select an address from the range 00:16:3e:xx:xx:xx, which has been assigned to .

Other options

QEMU has a lot of other useful options. For a full list, please refer to the QEMU documentation.
阅读(5444) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~