Chinaunix首页 | 论坛 | 博客
  • 博客访问: 45338
  • 博文数量: 21
  • 博客积分: 1425
  • 博客等级: 上尉
  • 技术积分: 175
  • 用 户 组: 普通用户
  • 注册时间: 2009-01-11 20:51
文章分类

全部博文(21)

文章存档

2013年(1)

2010年(12)

2009年(8)

我的朋友

分类: LINUX

2010-02-07 16:54:22


==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
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


阅读(486) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~