感谢支持
我们一直在努力

debian下qemu配置详解

1、kqemu模块的加载

在/etc/modules上增加kqemu,让系统启动时自动加载kqemu模块。

然后udev会自动生成一个叫做kqemu的设备:
xuwei@XIAO:~$ ls -l /dev | grep kqemu
crw-rw-rw- 1 root root 10, 63 2006-12-19 09:28 kqemu

2、配置qemu使用tap/tun模式

tap/tun模式需要内核支持tun模块,请先确认。

2.6.18 及以上版本内核,由于修改了对tun模块的执行权限,需要增加一个脚本。详细请参阅http://kidsquid.com/cgi- bin/moin.cgi/FrequentlyAskedQuestions#head-989268518a820a9f33477d3b99754ab5113aa2a3。在此也把该faq贴过来。

I’m using a kernel >=2.6.18 and am having problems with tun/tap and qemu
Starting with 2.6.18 a user process must be root to manage tap interfaces. One way to make qemu behave as before is to wrap the process in a that manages the interface:

qemu-tap

#!/bin/sh# to manage tap interface allocation# for linux kernels >= 2.6.18# set up a tap interface for qemu# USERID – uid qemu is being run under.USERID=`whoami`iface=`sudo tunctl -b -u $USERID`# generate a random mac address for the qemu nic# shell borrowed from user pheldens @ qemu forumranmac=$(echo -n DE:AD:BE:EF ; for i in `seq 1 2` ; \do echo -n `echo “:$RANDOM$RANDOM” | cut -n -c -3` ;done)# specify which NIC to use – see qemu.org for othersmodel=ne2k_pci# model=ne2k_isa# start qemu with our parametersqemu $@ -net nic,vlan=0,macaddr=$ranmac,model=$model \ -net tap,vlan=0,ifname=$iface# qemu has stopped – no longer using tap interfacesudo tunctl -d $iface &> /dev/null
You would then start qemu using this wrapper: ./qemu-tap -hda deb-sid.img -localtime

You need tunctl, a program from the usermode linux project, to make this work. On debian the package is called uml-utilities.

Please feel free to modify the .

然后,设置/etc/qemu-ifup
xuwei@XIAO:~$ cat /etc/qemu-ifup
#!/bin/sh
sudo -p “Password for $0:” /sbin/ifconfig $1 172.20.0.1
并且,把该脚本设置成可执行权限:
xuwei@XIAO:~$ ls -l /etc | grep qemu
-rwxr-xr-x 1 root root 66 2006-12-17 11:17 qemu-ifup

这就搞定了。直接qemu-tap .img就可开启虚拟机,并且使用tap/tun模式。开启虚拟机以后,ifconfig可以看到生成了一个tap0接口。host和guest正是通过该tap0接口通信的。3、配置guest上网

debian etch提供了很方便的途径。可以直接修改/etc/rc.local,添加如下信息:
echo “1” > /proc/sys/net/ipv4/ip_forward
iptables -F -t nat
iptables -X -t nat
iptables -Z -t nat
iptables -t nat -P PREROUTING ACCEPT
iptables -t nat -P POSTROUTING ACCEPT
iptables -t nat -P OUTPUT ACCEPT
iptables -t nat -A POSTROUTING -o eth0 -s 172.20.0.0/16 -j MASQUERADE

这样,系统启动时自动设置到guest的地址转换。

网上有几篇介绍的文章,都说先要配置bridge接口,然后再去写脚本加载这些模块,感觉没有必要这么麻烦。

赞(0) 打赏
转载请注明出处:服务器评测 » debian下qemu配置详解
分享到: 更多 (0)

听说打赏我的人,都进福布斯排行榜啦!

支付宝扫一扫打赏

微信扫一扫打赏