install debian mips on linux host

来源:互联网 发布:成都软件开发工作室 编辑:程序博客网 时间:2024/06/05 10:20

Introduction

QEMU is a generic and open source processor emulator which can emulate i386, x86_64, MIPS, MIPSEL, PowerPC and SPARC systems. In case of MIPS or MIPSEL, it can emulate a platform with an IDE controller, and IDE hard disk, an Ethernet card and a serial port. It still lacks a graphic card and screen support, so the installation is done through the emulated serial port.

The Debian Etch distribution provides kernel support this emulated platform. That makes a cheap development platform. The emulated system running on an Athlon 64 X2 3800+ is around 10% faster than an SGI Indy with and R4400SC 200MHz, and possibly with much more RAM (my emulated system has 512MiB of RAM).

This howto has been written for a Debian host system, but could be easily adapted for other distributions. It also has been written for a MIPS emulated system, but there are very few differences compared to a MIPSEL emulated system. They simply differ by the endianess (MIPS is big endian, MIPSEL is little endian). When not explicitely specified in this howto, just replace mips by mipsel.

Alternatively prebuilt images are also available.

Installing QEMU

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

wget http://fabrice.bellard.free.fr/qemu/qemu-0.9.1.tar.gz

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 MIPS machine.

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

It is necessary to have a MIPS or MIPSEL kernel image to pass to QEMU and an initrd image of the Etch Debian-Installer.

For MIPS:

$ wget http://ftp.de.debian.org/debian/dists/etch/main/installer-mips/current/images/qemu/netboot/vmlinux-2.6.18-6-qemu 
$ wget http://ftp.de.debian.org/debian/dists/etch/main/installer-mips/current/images/qemu/netboot/initrd.gz

And for MIPSEL:

$ wget http://ftp.de.debian.org/debian/dists/etch/main/installer-mipsel/current/images/qemu/netboot/vmlinux-2.6.18-6-qemu 
$ wget http://ftp.de.debian.org/debian/dists/etch/main/installer-mipsel/current/images/qemu/netboot/initrd.gz

Installing Debian Etch

To start the installation process, use the following line for MIPS:

$ qemu-system-mips -M mips -kernel vmlinux-2.6.18-6-qemu -initrd initrd.gz -hda hda.img -append "root=/dev/ram console=ttyS0" -nographic

And this one for MIPSEL:

$ qemu-system-mipsel -M mips -kernel vmlinux-2.6.18-6-qemu -initrd initrd.gz -hda hda.img -append "root=/dev/ram console=ttyS0" -nographic

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 exacty as with a normal installation, until you get to the following screen. If you need some documentation, please refer to the Debian installation guide.

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

Debian-Installer complains about missing bootloader

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 as different parameters have to be used to boot the installed system. Personally, I use killall qemu-system-mips, but other methods could also work.

Using the system

First boot

To start the system use the following command:

$ qemu-system-mips -M mips -kernel vmlinux-2.6.18-6-qemu -hda hda.img -append "root=/dev/hda1 console=ttyS0" -nographic

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

Console login

Enjoy your new MIPS or MIPSEL platform:

Console showing /proc/cpuinfo

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 512MiB; if you try to use more memory, the additional memory will not be visible.

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 viasudo. 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-mips -M mips -kernel vmlinux-2.6.18-3-qemu -hda hda.img -append "root=/dev/hda1 console=ttyS0" -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 MIPS), 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 Xen.

Other options

QEMU has a lot of other useful options. For a full list, please refer to the QEMU documentation.

Links

  • QEMU
  • QEMU project on savannah
  • Debian-Installer
  • Debian-Installer manual
  • debian-mips mailing list
  • The QCOW Image Format



==Building Debian Images for QEMU==

Install qemu and debootstrap:

apt-get install qemu debootstrap

Create image:

qemu-img create disk.img 512M

Associate image file with a loopback device:

losetup.orig -f # take note of the filename returned
losetup.orig /dev/loop0 disk.img # replace with name returned above

Create a ext2 filesystem on the image:

mkfs.ext3 /dev/loop0

Mount the image:

mkdir -p /mnt 
mount /dev/loop0 /mnt

Run debootstrap to install the Debian system :

debootstrap etch /mnt ftp://ftp.de.debian.org/debian/

Create a basic /mnt/etc/fstab on the image so the init scripts do not complain:

proc /proc proc defaults 0 0
/dev/sda / ext3 defaults,errors=remount-ro 0 1

== Compile kernel ==

Download and uncompress kernel source :

cd ~
wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.32.tar.bz2
tar -xvjf linux-2.6.32.tar.bz2

Compile kernel :

cd linux-2.6.32 # inside kernel tree 
make defconfig # make default configuration 
make menuconfig # add what you want to use 
make # compile kernel 
make modules # compile modules 
make modules_install INSTALL_MOD_PATH=/mnt # install modules in filesystem

== Booting ==

Umount filesystem:

umount /mnt

Detach loopback device:

losetup -d /dev/loop0

Done! You can run QEMU using the following command:

qemu -hda image.raw -kernel ~/linux-2.6.32/arch/i386/boot/bzImage -append “root=/dev/sda”


== Connecting host<->guest ==

Recompile the kernel with the network drivers available. I don’t remember the correct option, so active all in :

-> Device Drivers 
-> Network device support (NETDEVICES [=y]) 
-> Ethernet (10 or 100Mbit) (NET_ETHERNET [=y])

Define ip used by host(real machine) in (/etc/qemu-ifup) :

#!/bin/sh
sudo -p “Password for $0:” /sbin/ifconfig $1 192.168.0.1

Boot up your virtual system again adding(-net tap -net nic)

sudo qemu -net tap -net nic -hda image.raw -kernel linus-2.6/arch/i386/boot/bzImage -append “root=/dev/sda”

Define the ip and route used by guest(virtual machine):

ifconfig eth0 182.168.0.2 netmask 255.255.255.0 
route add default gw 192.168.0.1

Test it:

ping 192.168.0.1

Define DNS servers:

scp 192.168.0.1:/etc/resolv.conf /etc/resolv.conf



Index of /debian/dists/squeeze/main/installer-mipsel/current/images/malta/netboot

http://ftp.de.debian.org/debian/dists/squeeze/main/installer-mipsel/current/images/malta/netboot/

Index of /~aurel32/qemu

https://people.debian.org/~aurel32/qemu/

0 0
原创粉丝点击