首页 技术 正文
技术 2022年11月11日
0 收藏 722 点赞 2,285 浏览 3531 个字

主要为了看看图像显示是否有问题,跑起来系能如何,网络连接、文件共享是怎样的。

用的是雨林木风xp sp3的iso。为了提高性能,决定使用qcow2格式,预分配metadata,cache=none(查看:http://blog.csdn.net/jollyjumper/article/details/12379111),本来还想用vritio结果发现加上之后安装时检测不出硬盘。

kvm-img create -f qcow2 -o size=20G,preallocation=metadata xp.img

kvm -localtime -no-acpi  -localtime -m 512 -cdrom XP_SP3_YS5.6.iso -drive file=xp.img,index=0,media=disk,cache=none -boot d

从安装过程来看,cache=none和默认的writethrough相比的确快了不少,复制文件部分writethrough花了大约10分钟,none只花了5分钟(-m 1024会减少到3分钟)。

安装好了,可以上网、可以浏览网页,看看视频怎么样,结果发现视频可以放,但是没有声音,xp托盘上甚至没有soundman。搜了一下,发现需要加上hw参数。

列出所以可用声卡:

kvm -localtime -m 1024 -drive file=xp.img,index=0,media=disk,cache=none -soundhw ?

Unknown sound card name `b’
Valid sound card names (comma separated):
pcspk       PC speaker
sb16        Creative Sound Blaster 16
ac97        Intel 82801AA AC97 Audio
es1370      ENSONIQ AudioPCI ES1370
hda         Intel HD Audio

-soundhw all will enable all of the above

使用es1370:

kvm -localtime -m 1024 -drive file=xp.img,index=0,media=disk,cache=none -soundhw es1370

现在有声音了,可以看到视频画面不太流畅,远远不如virtualbox的表现。

看看网络是怎么回事,在xp中输入ipconfig,ip是10.0.2.15,网关是10.0.2.2可ping通,而host机上并没有新增10.0.2.2这个网卡。

原来默认是user mode networking就是这个设置,在10.0.2.2上是一个dhcp服务器,10.0.2.3是一个dns,10.0.2.4是一个samba服务器。user mode networking相当于是命令-net nic -net user。这个模式下网络比较受限,只支持tcp,udp(icmp就不行),并且从host无法访问guest(incoming traffic)。但是可以支持端口转发,以下命令添加共享文件夹:

kvm -localtime -m 1024 -drive file=xp.img,index=0,media=disk,cache=none -soundhw es1370 -redir tcp:5556::445 # 445是windows网络共享cifs协议端口

在guest中设置网络共享(在xp中需要去掉资源管理器中的文件->查看->简单文件共享)

….

sudo apt-get install cifs-utils  # 为了使用mount.cifs

sudo mount -t cifs //127.0.0.1/KVM_xpbox /mnt/qemu -o user=Administrator,pass=password,port=5556

进入该目录就可以执行读写了。

以下是虚拟机最最重要的部分:

可以桥接吗?

可以的。按照例子,对/etc/qemu-ifup进行替换:

#! /bin/bash


# script to bring up the tun device in QEMU in bridged mode 
# first parameter is name of tap device (e.g. tap0)
#
# some constants specific to the local host – change to suit your host
#
ETH0IPADDR=172.16.0.100
GATEWAY=172.16.0.1
BROADCAST=172.16.0.255
#
# First take eth0 down, then bring it up with IP address 0.0.0.0 
#
/sbin/ifdown eth0
/sbin/ifconfig eth0 0.0.0.0 promisc up
#
# Bring up the tap device (name specified as first argument, by QEMU)
#
/usr/sbin/openvpn –mktun –dev $1 –user `id -un`
/sbin/ifconfig $1 0.0.0.0 promisc up
#
# create the bridge between eth0 and the tap device
#
/sbin/brctl addbr br0 
/sbin/brctl addif br0 eth0
/sbin/brctl addif br0 $1

# only a single bridge so loops are not possible, turn off spanning tree protocol
#
/sbin/brctl stp br0 off 

# Bring up the bridge with ETH0IPADDR and add the default route 
#
/sbin/ifconfig br0 $ETH0IPADDR netmask 255.255.255.0 broadcast $BROADCAST
/sbin/route add default gw $GATEWAY
#
# stop firewall – comment this out if you don’t use Firestarter
#
#/usr/sbin/service firestarter stop

对/etc/qemu-ifdown进行替换:

#!/bin/sh 

# Script to bring down and delete bridge br0 when QEMU exits 

# Bring down eth0 and br0 
#
/sbin/ifdown eth0
/sbin/ifdown br0 
/sbin/ifconfig br0 down 

# Delete the bridge
#
sbin/brctl delbr br0 

# bring up eth0 in “normal” mode 
#
/sbin/ifconfig eth0 -promisc
/sbin/ifup eth0 
#
# delete the tap device
#
/usr/sbin/openvpn –rmtun –dev $1
#
# start firewall again

#/usr/bin/service firestarter start

要启动第一个虚拟机,执行:

sudo /etc/qemu-ifup tap0

sudo kvm -localtime -m 1024 -drive file=xp.img,index=0,media=disk,cache=none -soundhw es1370 -net nic -net tap,ifname=tap0,script=no,downscript=no

第二个虚拟机,需要指定mac地址,免得与第一个虚拟机冲突:

sudo /etc/qemu-ifup tap1

sudo kvm -localtime -m 1024 -drive file=xp1.img,index=0,media=disk,cache=none -soundhw es1370 -net nic,macaddr=DE:AD:AF:22:33:22 -net tap,ifname=tap1,script=no,downscript=no

可以看到主机是172.16.0.1,tap0和tap1在主机上只是链路层的网口,没有地址,而在虚拟机中它们使用隧道也完成各自IP的分配,IP分别是172.16.0.106和172.16.0.107。三台机器可以互相访问,太棒了。/etc/qemu-ifdown实际上没有多大机会执行。

几个待续:

host文件共享给guest

vnc

vga

run in background,no gui

参考:

http://en.wikibooks.org/wiki/QEMU/Networking

man kvm

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,083
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,558
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,407
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,180
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,816
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,899