ubuntu server 8.04 kvm 问题总结
1、virt-install出错,
问题在于:you need to run virt-install. On Ubuntu Hardy, with KVM-62, install of windows XP doesn't work when accelerated (ie, using --accelerate), so run install without that argument, and replace qemu by kvm in the XML defintiion file (in /etc/libvirt/qemu) after the first reboot.
我一直用--accelerate参数导致virt-install出错(我以为是X环境没有的原因)
2、远程无法挂载cdrom
因为本地没有安装x环境,安装时比较麻烦,参见这段说明
Another problem is that after the first reboot, in the process of the installation, the windows installer will complain that it can not see the disk anymore. In the XML definition of the VM again, add this to the list of devices:
<domain type='kvm'> [...] <devices> [...] <disk type='file' device='cdrom'> <source file='/home/yhamon/windowsxpsp2.iso'/> <target dev='hdc' bus='ide'/> <readonly/> </disk> </devices></domain>
Redefine the VM in virsh (sudo virsh define /etc/libvirt/qemu/xpsp2.xml) and restart the VM - it should work fine.
如果闲麻烦,可以在远程主机安装virt-manger,然后打开X11主机ssh转发功能
安装服务器:apt-get ssh
打开服务端的X11转发功能,修改/etc/ssh/sshd_config文件,把 X11Forwarding no改成X11Forwarding yes,就启用了ssh的X11转发功能。
客户端操作命令:
ssh -Y username@host_address
这 种方式虽然速度稍微慢了一些,但是如果客户端是Linux的话,在局域网中应该是非常方便的,因为客户端不用再配置X。如果客户端是 windows,putty,好像也有这个功能,至少在Connection->SSH->Tunnels中有X11 forwarding的配置,但是可能需要安装X for windows才能使用。
大致步骤:
1、ubuntu server 8.04.2初始安装,装ssh
2、安装 kvm
$ sudo apt-get install kvm libvirt-bin ubuntu-vm-builder qemu bridge-utils
$ sudo usermod -aG libvirtd `id -un`
...,配网桥(/etc/network/interfaces)
auto lo
iface lo inet loopback
auto eth0iface eth0 inet manual auto br0
#iface eth0 inet dhcp
iface br0 inet static
address 192.168.1.105
network 192.168.1.0
netmask 255.255.255.0
broadcast 192.168.1.255
gateway 192.168.1.1
bridge_ports eth0
bridge_fd 9
bridge_hello 2
bridge_maxage 12
bridge_stp off
3、装sudo apt-get install xorg
sudo apt-get install gnome-core
4、开ssh 的X11转发
修改/etc/ssh/sshd_config文件,把 X11Forwarding no改成X11Forwarding yes
5、建立虚拟机
Install virt-install:
sudo apt-get install python-virtinstsudo virt-install --connect qemu:///system -n kf01 -r 256 \ -f ./kvm/kfxp01.qcow2 -s 4 -c winxpsp3.iso --vnc --noautoconsole \ --os-type windows --os-variant winxp
进入/etc/libvirt/qemu/目录,打开虚拟机的配置xml文件
找到
<devices>
<emulator>
/usr/bin/kvm</emulator>
<disk type='file' device='disk'>
<source file='/home/hjzx/kvm/kfxp01.qcow2'/>
<target dev='hda' bus='ide'/>
</disk>
段,把/usr/bin/qemu 改为/usr/bin/kvm,打开cpu硬件加速
sudo virsh define /etc/libvirt/qemu/kf01.xml 更新qemu虚拟机数据库
5、装virt-manger
sudo apt-get install virt-manger
配置X11转发(默认ubuntuserver 8.04是开启的)
修改/etc/ssh/sshd_config文件,把 X11Forwarding no改成X11Forwarding yes,就启用了ssh的X11转发功能
退出ssh后用 ssh -Y 用户名@远程主机ip 格式重新登录,启动virt-manger
6、克隆虚拟机
命令:
sudo virt-clone -o web_devel -n database_devel -f /path/to/database_devel.img --connect=qemu:///system
例一:
sudo virt-clone -o kf01 -n kf03 -f /home/kfxp03.qcow2 --connect=qemu:///system
- 最新评论