QEMU - Running Debian in Debian


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


<script type=text/javascript charset=utf-8 src="http://static.bshare.cn/b/buttonLite.js#style=-1&uuid=&pophcol=3&lang=zh"></script> <script type=text/javascript charset=utf-8 src="http://static.bshare.cn/b/bshareC0.js"></script>
阅读(264) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~
评论热议
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值