KVM gust 模板安裝

來源:互聯網
上載者:User

標籤:虛擬機器

主要用到 virsh 命令

本次以用模板安裝 vm00002 ,安裝路徑/data1/domains/vm00002/

準備工作

根據之前用圖形安裝的vm00001為模板,這個虛擬機器是標準的rhel5.3系統

擷取正在啟動並執行vm00001的模板檔案vm00001.xml 和vm00001的系統硬碟root.img

 #顯示正在啟動並執行虛擬機器

[[email protected] vm000001]# virsh list

 Id    Name                           State

----------------------------------------------------

 52    vm00001                        running

1.匯出vm00001的xml格式的模板 命名為vm00001.xml

[[email protected] ~]# virsh dumpxml vm00001 >vm00001.xml

[[email protected] ~]# ls

anaconda-ks.cfg  install.log  install.log.syslog  vm00001.xml

2.把這個模板放到/data1/domains/vm00002/ ,並改名為vm00002.xml

[[email protected] ~]# mkdir /data1/domains/vm000002 -p

[[email protected] ~]# mv vm00001.xml /data1/domains/vm000002/vm00002.xml 

3.把vm00001的系統硬碟複製到/data1/domains/vm00002/

[[email protected] ~]# cp /data1/domains/vm000001/root.img /data1/domains/vm000002/

[[email protected] ~]# ls /data1/domains/vm000002/

root.img  vm00002.xml

4.修改vm00002.xml 4個參數:name 、uuid、source file、mac分別在 第2、3、24、45行,因為這4個參數與別的虛擬機器不能衝突,儲存。

[[email protected] ~]# 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     <imagelabel>system_u:object_r:svirt_image_t:s0:c167,c901</imagelabel>

 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     <imagelabel>system_u:object_r:svirt_image_t:s0:c167,c901</imagelabel>

 82   </seclabel>

 83 </domain>

 84 

 5.啟動vm00002

[[email protected] ~]# cd /data1/domains/vm000002/

[[email protected] vm000002]# virsh create vm00002.xml 

Domain vm00002 created from vm00002.xml

6.查看啟動並執行虛擬機器狀態

[[email protected] vm000002]# virsh list

 Id    Name                           State

----------------------------------------------------

 52    vm00001                        running

 53    vm00002                        running

7.virt-manager圖形查看

[[email protected] vm000002]# virt-manager 

Xlib:  extension "RANDR" missing on display "localhost:12.0".

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/45/DF/wKioL1PsvD7w7BUeAAEigqHC28s717.jpg" title="QQ20140814183412.png" alt="wKioL1PsvD7w7BUeAAEigqHC28s717.jpg" />

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

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/45/DF/wKioL1PsvG6hGlrjAAO230nQq0I770.jpg" title="QQ20140814183423.png" alt="wKioL1PsvG6hGlrjAAO230nQq0I770.jpg" />啟動完畢後,這個vm00002與vm00001除了那4個參數不一樣,其他都是一樣的

結束。

本文出自 “夢三國” 部落格,謝絕轉載!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.