歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> debian下qemu配置詳解

debian下qemu配置詳解

日期:2017/2/28 17:43:34   编辑:Linux教程
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接口通信的。
Copyright © Linux教程網 All Rights Reserved