3)修改vm.xml。此处需要注意,RHEL6.4使用的vm.xml和Ubuntu14.04上的略有不同。下面列出RHEL6.4上个的vm.xml(不同之处):
<domain type='kvm'>
<name>vm</name>
<uuid>...</uuid>
<memory unit='KiB'>4194304</memory>
<currentMemory unit='KiB'>4194304</currentMemory>
<vcpu placement='static'>4</vcpu>
<os>
<type arch='x86_64' machine='rhel6.4.0'>hvm</type>
<boot dev='hd'/>
</os>
<features>
<acpi/>
<apic/>
<pae/>
</features>
<clock offset='utc'/>
<!--
<clock offset='localtime'/>
-->
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<!-- diff below -->
<emulator>/usr/libexec/qemu-kvm</emulator>
<disk type='file' device='disk'>
<driver name='qemu' type='raw'/>
<source file='/var/lib/libvirt/images/vm.img'/>
<target dev='vda' bus='virtio'/>
</disk>
<disk type='block' device='cdrom'>
<driver name='qemu' type='raw'/>
<target dev='hdc' bus='ide'/>
<readonly/>
<address .../>
</disk>
...
<serial type='pty'>
<target port='0'/>
</serial>
<console type='pty'>
<target type='serial' port='0'/>
</console>
...
</devices>
</domain>
不同之处在于:
<emulator>/usr/libexec/qemu-kvm</emulator>
4)然后运行定义:
$ virsh define vm.xml
5)启动和关闭:
$ virsh start vm
$ virsh shutdown vm
下面说明如何virsh console登录虚拟机。首先需要在vm的/etc/init/下创建ttyS0.conf文件,内容如下:
# /etc/init/ttyS0.conf:
# ttyS0 - agetty
stop on runlevel [016]
start on runlevel [345]
instance ttyS0
respawn
pre-start exec /sbin/securetty ttyS0
exec /sbin/agetty /dev/ttyS0 115200 vt100-nav
由于我们此时还没有正确配置vm的网络,无法ssh到虚拟机。因此需要使用libguestfs-tools拷贝ttyS0.conf到vm中。
1)首先主机RHEL6.4上需要安装libguestfs-tools:
$ yum install libguestfs-tools
2)在主机上创建并编辑好:ttyS0.conf,然后拷贝到vm中:
$ virsh shutdown vm # 必须首先关闭虚拟机
$ virt-copy-in -d vm ttyS0.conf /etc/init
$ virt-ls -d vm /etc/init
$ virt-cat -d vm /etc/init/ttyS0.conf
3)启动并console到vm:
$ virsh start vm
$ virsh console vm
4)配置vm的网络。重启虚拟机。然后就可以ssh到vm上了。
大功告成!如果觉得 vm小,可以resize。
更多Ubuntu相关信息见Ubuntu 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=2
更多RedHat相关信息见RedHat 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=10
本文永久更新链接地址:http://www.linuxidc.com/Linux/2014-09/107389.htm
