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接口,然后再去写脚本加载这些模块,感觉没有必要这么麻烦。
debian下qemu配置详解
转载请注明出处:服务器评测 » debian下qemu配置详解
相关推荐
- Hivelocity黑色星期五钜惠:专属服务器享终身35%优惠或前半年5折抢购!
- 65美元/月:八核三十六G强劲配置,支持/24 IPv4子网租用。
- 新加坡/印尼独立服务器 ⚡ 今日下单仅 $49.5 ⚡ 限时特惠
- HC ★ AMD高性能独立服务器 ★ 覆盖阿什本、阿姆斯特丹、达拉斯、纽约、斯德哥尔摩、东京等多节点
- AMD EPYC 新加坡专用服务器限量 50% 折扣 – RACKH
- ███ 16C/32T – 64GB RAM – 2x500GB SSD – 10Gbit端口 – 49美元███
- OwnWebServers 万圣节促销:专用服务器 55% 折扣 – 现在 47.25 美元/月。即时设置
- 专用服务器仅需 65 美元/月 – 8 核 – 36GB RAM – 最多 /24 个 IPv4 子网可用
服务器评测





