KVM gust 模板安裝

主要用到 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".

wKioL1PsvD7w7BUeAAEigqHC28s717.jpg

雙擊vm00002,查看是否正在啓動

wKioL1PsvG6hGlrjAAO230nQq0I770.jpg啓動完畢後,這個vm00002與vm00001除了那4個參數不一樣,其他都是一樣的

結束。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章