主要用到 virsh 命令
本次以用模板安装 vm00002 ,安装路径/data1/domains/vm00002/
准备工作
根据之前用图形安装的vm00001为模板,这个虚拟机是标准的rhel5.3系统
获取正在运行的vm00001的模板文件vm00001.xml 和vm00001的系统盘root.img
#显示正在运行的虚拟机
[root@localhost vm000001]# virsh list
Id Name State
----------------------------------------------------
52 vm00001 running
1.导出vm00001的xml格式的模板 命名为vm00001.xml
[root@localhost ~]# virsh dumpxml vm00001 >vm00001.xml
[root@localhost ~]# ls
anaconda-ks.cfg install.log install.log.syslog vm00001.xml
2.把这个模板放到/data1/domains/vm00002/ ,并改名为vm00002.xml
[root@localhost ~]# mkdir /data1/domains/vm000002 -p
[root@localhost ~]# mv vm00001.xml /data1/domains/vm000002/vm00002.xml
3.把vm00001的系统盘复制到/data1/domains/vm00002/
[root@localhost ~]# cp /data1/domains/vm000001/root.img /data1/domains/vm000002/
[root@localhost ~]# ls /data1/domains/vm000002/
root.img vm00002.xml
4.修改vm00002.xml 4个参数:name 、uuid、source file、mac分别在 第2、3、24、45行,因为这4个参数与别的虚拟机不能冲突,保存。
[root@localhost ~]# vim /data1/domains/vm000002/vm00002.xml
1 <domain type='qemu' id='52'>
2 <name>vm00001</name> #修改name为vm00002
3 <uuid>1b77f768-d75b-60bc-0b4c-27b108cc1155</uuid>#修改uuid,在最后一位数5变成6即可
4 <memory unit='KiB'>1048576</memory>
5 <currentMemory unit='KiB'>1048576</currentMemory>
6 <vcpu placement='static'>1</vcpu>
7 <os>
8 <type arch='x86_64' machine='rhel6.4.0'>hvm</type>
9 <boot dev='hd'/>
10 </os>
11 <features>
12 <acpi/>
13 <apic/>
14 <pae/>
15 </features>
16 <clock offset='utc'/>
17 <on_poweroff>destroy</on_poweroff>
18 <on_reboot>restart</on_reboot>
19 <on_crash>restart</on_crash>
20 <devices>
21 <emulator>/usr/libexec/qemu-kvm</emulator>
22 <disk type='file' device='disk'>
23 <driver name='qemu' type='raw' cache='none'/>
24 <source file='/data1/domains/vm000001/root.img'/>#系统盘路径改 成/data1/domains/vm00002/root.img
25 <target dev='hda' bus='ide'/>
26 <alias name='ide0-0-0'/>
27 <address type='drive' controller='0' bus='0' target='0' unit='0'/>
28 </disk>
29 <disk type='block' device='cdrom'>
30 <driver name='qemu' type='raw'/>
31 <target dev='hdc' bus='ide'/>
32 <readonly/>
33 <alias name='ide0-1-0'/>
34 <address type='drive' controller='0' bus='1' target='0' unit='0'/>
35 </disk>
36 <controller type='usb' index='0'>
37 <alias name='usb0'/>
38 <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
39 </controller>
40 <controller type='ide' index='0'>
41 <alias name='ide0'/>
42 <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
43 </controller>
44 <interface type='bridge'>
45 <mac address='52:54:00:97:73:92'/> #修改mac adress,最有一位2变为3即可
46 <source bridge='br0'/>
47 <target dev='vnet0'/>
48 <alias name='net0'/>
49 <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
50 </interface>
51 <serial type='pty'>
52 <source path='/dev/pts/1'/>
53 <target port='0'/>
54 <alias name='serial0'/>
55 </serial>
56 <console type='pty' tty='/dev/pts/1'>
57 <source path='/dev/pts/1'/>
58 <target type='serial' port='0'/>
59 <alias name='serial0'/>
60 </console>
61 <input type='mouse' bus='ps2'/>
62 <graphics type='vnc' port='5900' autoport='yes' listen='127.0.0.1' keymap='en-us'>
63 <listen type='address' address='127.0.0.1'/>
64 </graphics>
65 <sound model='ich6'>
66 <alias name='sound0'/>
67 <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
68 </sound>
69 <video>
70 <model type='cirrus' vram='9216' heads='1'/>
71 <alias name='video0'/>
72 <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
73 </video>
74 <memballoon model='virtio'>
75 <alias name='balloon0'/>
76 <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
77 </memballoon>
78 </devices>
79 <seclabel type='dynamic' model='selinux' relabel='yes'>
80 <label>system_u:system_r:svirt_t:s0:c167,c901</label>
81 <p_w_picpathlabel>system_u:object_r:svirt_p_w_picpath_t:s0:c167,c901</p_w_picpathlabel>
82 </seclabel>
83 </domain>
84
修改vm00002.xml后,文件参数变为以下内容
1 <domain type='qemu' id='52'>
2 <name>vm00002</name>
3 <uuid>1b77f768-d75b-60bc-0b4c-27b108cc1156</uuid>
4 <memory unit='KiB'>1048576</memory>
5 <currentMemory unit='KiB'>1048576</currentMemory>
6 <vcpu placement='static'>1</vcpu>
7 <os>
8 <type arch='x86_64' machine='rhel6.4.0'>hvm</type>
9 <boot dev='hd'/>
10 </os>
11 <features>
12 <acpi/>
13 <apic/>
14 <pae/>
15 </features>
16 <clock offset='utc'/>
17 <on_poweroff>destroy</on_poweroff>
18 <on_reboot>restart</on_reboot>
19 <on_crash>restart</on_crash>
20 <devices>
21 <emulator>/usr/libexec/qemu-kvm</emulator>
22 <disk type='file' device='disk'>
23 <driver name='qemu' type='raw' cache='none'/>
24 <source file='/data1/domains/vm000002/root.img'/>
25 <target dev='hda' bus='ide'/>
26 <alias name='ide0-0-0'/>
27 <address type='drive' controller='0' bus='0' target='0' unit='0'/>
28 </disk>
29 <disk type='block' device='cdrom'>
30 <driver name='qemu' type='raw'/>
31 <target dev='hdc' bus='ide'/>
32 <readonly/>
33 <alias name='ide0-1-0'/>
34 <address type='drive' controller='0' bus='1' target='0' unit='0'/>
35 </disk>
36 <controller type='usb' index='0'>
37 <alias name='usb0'/>
38 <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
39 </controller>
40 <controller type='ide' index='0'>
41 <alias name='ide0'/>
42 <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
43 </controller>
44 <interface type='bridge'>
45 <mac address='52:54:00:97:73:93'/>
46 <source bridge='br0'/>
47 <target dev='vnet0'/>
48 <alias name='net0'/>
49 <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
50 </interface>
51 <serial type='pty'>
52 <source path='/dev/pts/1'/>
53 <target port='0'/>
54 <alias name='serial0'/>
55 </serial>
56 <console type='pty' tty='/dev/pts/1'>
57 <source path='/dev/pts/1'/>
58 <target type='serial' port='0'/>
59 <alias name='serial0'/>
60 </console>
61 <input type='mouse' bus='ps2'/>
62 <graphics type='vnc' port='5900' autoport='yes' listen='127.0.0.1' keymap='en-us'>
63 <listen type='address' address='127.0.0.1'/>
64 </graphics>
65 <sound model='ich6'>
66 <alias name='sound0'/>
67 <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
68 </sound>
69 <video>
70 <model type='cirrus' vram='9216' heads='1'/>
71 <alias name='video0'/>
72 <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
73 </video>
74 <memballoon model='virtio'>
75 <alias name='balloon0'/>
76 <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
77 </memballoon>
78 </devices>
79 <seclabel type='dynamic' model='selinux' relabel='yes'>
80 <label>system_u:system_r:svirt_t:s0:c167,c901</label>
81 <p_w_picpathlabel>system_u:object_r:svirt_p_w_picpath_t:s0:c167,c901</p_w_picpathlabel>
82 </seclabel>
83 </domain>
84
5.启动vm00002
[root@localhost ~]# cd /data1/domains/vm000002/
[root@localhost vm000002]# virsh create vm00002.xml
Domain vm00002 created from vm00002.xml
6.查看运行的虚拟机状态
[root@localhost vm000002]# virsh list
Id Name State
----------------------------------------------------
52 vm00001 running
53 vm00002 running
7.virt-manager图形查看
[root@localhost vm000002]# virt-manager
Xlib: extension "RANDR" missing on display "localhost:12.0".
双击vm00002,查看是否正在启动
启动完毕后,这个vm00002与vm00001除了那4个参数不一样,其他都是一样的
结束。