使用命令創建虛擬機uos,自動化創建


1、qemu-img create -f qcow2 ./1020uos.qcow2 70G    (1)生成硬盤鏡像文件     用qemu創建一塊硬盤,作為系統盤用來裝OS
  qemu-img create -f  raw 1020-uos-2.img 70G     (1)生成硬盤鏡像文件     用qemu創建一塊硬盤,作為系統盤用來裝OS
qemu-img info 1020uos.qcow2 查看你的鏡像文件 2、編寫xml配置文件1020-uos-2.xml
<domain type='kvm'> <name>test1-1020</name> //虛擬機名稱 <memory>1048576</memory> //最大內存,單位k <currentMemory>1048576</currentMemory> //可用內存,單位k <vcpu>1</vcpu> //虛擬cpu個數 <os> <type arch='x86_64' machine='pc'>hvm</type> <boot dev='cdrom'/> //光盤啟動 </os> <features> <acpi/> <apic/> <pae/> </features> <clock offset='localtime'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>destroy</on_crash> <devices> <emulator>/usr/bin/qemu-system-x86_64</emulator> <disk type='file' device='cdrom'> <source file='/home/tarzan/Downloads/image/uniontechos-20-desktop-professional-1020-amd64.iso'/> //光盤鏡像路徑 <target dev='hdb' bus='ide'/> </disk> <disk type="file" device="disk"> <driver name="qemu" type="raw"/> <source file="/home/tarzan/Downloads/image/virsh_test/1020-uos-2.img"/> //這里把硬盤位置放上 <target dev="sda" bus="virtio"/> <alias name="virtio-disk0"/> </disk> <input type='mouse' bus='ps2'/> <graphics type='vnc' port='-1' listen = '0.0.0.0' keymap='en-us'/>//vnc方式登錄,端口號自動分配,自動加1,可以通過virsh vncdisplay來查詢 </devices> </domain> 3、創建並運行虛擬機 sudo apt-get install qemu-kvm virsh create ./1020-uos-2.xml //創建虛擬機 3.1 查看虛擬機 $ virsh list Id Name State ---------------------------- 1 test1-1020 running 4、查看你的虛擬機端口 virsh vncdisplay --domain test1-1020 :0 //我們剛查到虛擬機的vnc端口為0,qemu會給端口補個590也就是,我們這里鏈接5900 這里還有一個方法查看: $ virsh Welcome to virsh, the virtualization interactive terminal. Type: 'help' for help with commands 'quit' to quit virsh # list Id Name State ---------------------------- 1 test1-1020 running virsh # vncdisplay 1 :0 5、連接虛擬機 vncviewer localhost:0

 

(1)生成硬盤鏡像文件     用qemu創建一塊硬盤,作為系統盤用來裝OS


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM