kvm 學習(二)

Linux下 如何通過命令行使用現有的鏡像創建、啟動kvm虛擬機

這里假定已經創建好了相應的鏡像:

eg:我這里制作的鏡像名稱為zu1-centos7.img

# lszu1-centos7.img  

1、拷貝這個鏡像到某一個目錄

cp zu1-centos7.img /data2/

2、編寫鏡像的配置文件,當然一般情況是從其他鏡像的配置文件拷貝一份,重新命名在修改

# cd /etc/libvirt/qemu   進入到鏡像配置文件目錄
# cp test2.xml test3.xml   test2.xml是其他鏡像存在的配置文件,test3.xml是當前準備啟動的鏡像的配置文件

test2.xml配置文件大體如下:

<!--
WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
OVERWRITTEN AND LOST. Changes to this xml configuration should be made using:virsh edit test2
or other application using the libvirt API.
--><domain type='kvm'><name>test2</name>                     ---虛擬機名字,記得修改,隨便起什么名字都行,只要不跟其他虛擬機名字一樣就行<uuid>92047c95-c5b8-4e4d-916c-fb2218ca055f</uuid>    --uuid  記得修改,一般來說,把最好的四位數字重新修改一下,例如我把最后四位改成0001,具體效果看下個test3.xml文件<memory unit='KiB'>10485760</memory>      ---當前虛擬機使用內存,看自己情況是否需要修改<currentMemory unit='KiB'>10485760</currentMemory>   ---當前虛擬機可以使用的最大內存,使用內存不得超過這個內存,當使用內存不足的時候,可以在虛擬機里面動態調整內存。<vcpu placement='static'>1</vcpu><os><type arch='x86_64' machine='rhel6.6.0'>hvm</type>   ---架構,一般不用修改<boot dev='hd'/></os><features><acpi/><apic/><pae/></features><clock offset='utc'/><on_poweroff>destroy</on_poweroff><on_reboot>restart</on_reboot><on_crash>restart</on_crash><devices><emulator>/usr/libexec/qemu-kvm</emulator><disk type='file' device='disk'><driver name='qemu' type='qcow2' cache='none'/>   ---driver類型,需要跟鏡像的文件格式一致。以前老版本默認是raw類型,現在默認是qcow2類型。查看鏡像的文件格式在該配置文件的下面:<source file='/data1/iso/zu1-centos7.img'/>        --- 鏡像文件路徑<target dev='vda' bus='virtio'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/></disk><disk type='block' device='cdrom'><driver name='qemu' type='qcow2'/><target dev='hdc' bus='ide'/><readonly/><address type='drive' controller='0' bus='1' target='0' unit='0'/></disk><controller type='ide' index='0'><address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/></controller><controller type='usb' index='0' model='piix3-uhci'><address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/></controller><controller type='pci' index='0' model='pci-root'/><interface type='bridge'><mac address='52:54:00:5a:07:de'/><source bridge='br0'/><model type='virtio'/><address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>   ---這里的slot號記得修改  把最后兩位改成其他的就行,但不要跟其他的虛擬機配置的值一樣,同時,這個值不超過 0x0f</interface><serial type='pty'><target type='isa-serial' port='0'><model name='isa-serial'/></target></serial><console type='pty'><target type='serial' port='0'/></console><input type='tablet' bus='usb'><address type='usb' bus='0' port='1'/></input><input type='mouse' bus='ps2'/><input type='keyboard' bus='ps2'/><memballoon model='virtio'><address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/></memballoon></devices>
</domain>

3、查看鏡像的driver類型

# qemu-img info /data1/zu1-centos7.img
image: /data1/virtcentos/pool/zu1-centos7.img
file format: qcow2     ----這里就是鏡像的文件格式
virtual size: 20G (21474836480 bytes)
disk size: 18G
cluster_size: 65536
Format specific information:compat: 1.1lazy refcounts: true

4、修改test3.xml文件,如下:

<!--
WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
OVERWRITTEN AND LOST. Changes to this xml configuration should be made using:virsh edit test2
or other application using the libvirt API.
--><domain type='kvm'><name>yjt</name>    ---這里改成了yjt<uuid>92047c95-c5b8-4e4d-916c-fb2218ca0001</uuid><memory unit='KiB'>10485760</memory><currentMemory unit='KiB'>10485760</currentMemory><vcpu placement='static'>1</vcpu><os><type arch='x86_64' machine='rhel6.6.0'>hvm</type><boot dev='hd'/></os><features><acpi/><apic/><pae/></features><clock offset='utc'/><on_poweroff>destroy</on_poweroff><on_reboot>restart</on_reboot><on_crash>restart</on_crash><devices><emulator>/usr/libexec/qemu-kvm</emulator><disk type='file' device='disk'><driver name='qemu' type='qcow2' cache='none'/><source file='/data2/zu1-centos7.img'/>    ---這里修改了鏡像的路徑<target dev='vda' bus='virtio'/><address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/></disk><disk type='block' device='cdrom'><driver name='qemu' type='qcow2'/><target dev='hdc' bus='ide'/><readonly/><address type='drive' controller='0' bus='1' target='0' unit='0'/></disk><controller type='ide' index='0'><address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/></controller><controller type='usb' index='0' model='piix3-uhci'><address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/></controller><controller type='pci' index='0' model='pci-root'/><interface type='bridge'><mac address='52:54:00:5a:07:de'/><source bridge='br0'/><model type='virtio'/><address type='pci' domain='0x0000' bus='0x00' slot='0x10' function='0x0'/>   這里改成了0x10,注意,該值不得超過0x0f</interface><serial type='pty'><target type='isa-serial' port='0'><model name='isa-serial'/></target></serial><console type='pty'><target type='serial' port='0'/></console><input type='tablet' bus='usb'><address type='usb' bus='0' port='1'/></input><input type='mouse' bus='ps2'/><input type='keyboard' bus='ps2'/><memballoon model='virtio'><address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/></memballoon></devices>
</domain>

5、定義虛擬機

# virsh define test3.xml  ---定義虛擬機跟上對應的文件即可

6、啟動虛擬機

virsh start yjt   ---yjt這個名字在配置文件定義的,也就是虛擬機的名字。

到這里就ok了。

如果虛擬機不要用了,可以使用如下方法銷毀

7、停止虛擬機

# virsh shutdown yjt   ---正常停止
# virsh destroy yjt    ---強制停止

8、取消虛擬機的定義,也就是刪除

# virsh undefine yjt   ---默認會刪除/etc/libvirt/qemu下的test3.xml文件

?

轉載于:https://www.cnblogs.com/yjt1993/p/10833641.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/275167.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/275167.shtml
英文地址,請注明出處:http://en.pswp.cn/news/275167.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

字節內部前端開發手冊(完整版)開放下載!

備戰2022&#xff0c;準備好了嗎&#xff1f;據字節HR部門發布的最新信息&#xff0c;2019年以來字節連續3年擴招&#xff0c;而即將到來的2022年春招前端崗位數不低于3000&#xff0c;雖連年擴招&#xff0c;但是報錄比卻從2019年的3%下降到今年的1%。BAT等一線大廠同樣有類似…

EBS中Java并發程序筆記(1)

在Oracle EBS中的Java并發程序&#xff08;Java Concurrent Program&#xff09;是系統功能中的一個亮點&#xff0c;它的出現使得用戶可以在ERP系統中運行自己定義的Java程序。本文為學習筆記&#xff0c;所以不會介紹太多背景知識。 使用Java并發程序的好處&#xff1a; 當遇…

figma設計_5位來自雜亂無章的設計師的Figma技巧

figma設計When starting a design project, a fast pace and multiple design iterations can easily lead to a cluttered mess. Taking the time in the beginning to build good organizational habits will save you time later. You’ll thank your past self when you do…

hello,你知道獲取元素有哪幾種方式嗎?

收下我的小心心&#xff01;&#xff08;害羞臉&#xff09; 根據id屬性的值獲取元素&#xff0c;返回來的是一個元素對象 document.getElementById("id屬性的值") 根據標簽名獲取元素&#xff0c;返回來的是一個偽數組&#xff0c;里面保存了多個的DOM對象 documen…

設計和實現一個 Chrome 插件提升登錄效率

大家好&#xff0c;我是若川。最近組織了源碼共讀活動&#xff0c;感興趣的可以點此加我微信ruochuan12 進群參與&#xff0c;每周大家一起學習200行左右的源碼&#xff0c;共同進步。已進行4個月了&#xff0c;很多小伙伴表示收獲頗豐。前言在我們的工作過程中&#xff0c;每當…

[待總結]redmine

先列出來&#xff0c;有空再總結轉載于:https://www.cnblogs.com/gracexiao/archive/2011/11/18/2253834.html

qq空間網頁設計_網頁設計中的負空間

qq空間網頁設計重點 (Top highlight)Because screens are limited, web design is also limited. It can be said that in the small box of the screen, each pixel is a piece of real estate.由于屏幕有限&#xff0c;因此網頁設計也受到限制。 可以說&#xff0c;在屏幕的小…

前端組件化-抽象公共組件類

優化上次的組件化小demo 上次的組件化demo只是為了簡單的實現前端組件化的思想&#xff0c;這次我們稍微優化一下抽離公共類 下面代碼 html <div id"wrapper"></div> 復制代碼js /* DOM字符串轉DOM節點 */ const createStringToDom str > {const ele…

時隔一年半,我,一個卑微的前端菜雞,又來寫面經了

大家好&#xff0c;我是若川。最近組織了源碼共讀活動&#xff0c;感興趣的可以點此加我微信ruochuan12 進群參與&#xff0c;每周大家一起學習200行左右的源碼&#xff0c;共同進步。已進行4個月了&#xff0c;很多小伙伴表示收獲頗豐。作者&#xff1a;刮涂層_贏大獎原文地址…

javascript模版引擎-tmpl的bug修復與性能優化

http://www.planeart.cn/?p1594 http://ejohn.org/blog/javascript-micro-templating http://bbs.phpchina.com/thread-224712-1-1.html [ Noevil: 下面直接貼出改進好的MicroTemp&#xff0c;但是還是建議看一下原文&#xff0c;里面有詳細的改進細節&#xff0c;和改進前后的…

2019.5.8_此書真乃寶書也_從定位參數到僅限關鍵字參數

《摘自流暢的Python》 此書真乃寶書也,雖說還是有點兒沒懂 從定位參數到僅限關鍵字參數 Python最好的特性之一是提供了極為靈活的參數處理機制&#xff0c;而且Python3進一步提供了僅限關鍵字參數(keyword-only argument)。與之密切相關的是&#xff0c;調用函數時使用*和**“展…

用戶體驗與可用性測試_可用性作為用戶體驗的原則

用戶體驗與可用性測試Every UX Designer has his views and best practices. We all have a guide book created through time and experience. I want to share mine with you.每個UX設計器都有他的觀點和最佳實踐。 我們都有一本通過時間和經驗編寫的指南。 我想和你分享我的…

Jenkins插件之Deploy

deploy插件&#xff1a; Deploy Plugindeploy插件支持將War/Jar部署到遠程的應用服務器上&#xff0c;例如Tomcat,JBoss,Glassfish。正在尋找或開發.NET web 應用的自動發布插件。如何回滾或重新部署先前的build&#xff1a;0&#xff09; 需要被deploy的job的結果要存檔&#…

受美國法律保護美國妞_為什么美國法律有效地要求所有軟件設計都要響應

受美國法律保護美國妞Smashing Magazine defines “responsive design” as an approach where design responds to the user’s behavior and environment based on screen size, platform, and orientation. In responsive design, a breakpoint is the “point” at which a…

源碼群友問:你這么多項目是怎么進行技術選型的?

大家好&#xff0c;我是若川。最近組織了源碼共讀活動&#xff0c;感興趣的可以點此加我微信ruochuan12 進群參與&#xff0c;每周大家一起學習200行左右的源碼&#xff0c;共同進步。已進行4個月了&#xff0c;很多小伙伴表示收獲頗豐。源碼群有群友提問我是怎么找到那么多npm…

iOS開發之打包上傳報錯: ERROR ITMS-90087/ERROR ITMS-90125

制作好的framework在打包上傳至AppStore如果出現以下錯誤&#xff0c;則說明這個SDK里面包含了x86_64, i386 架構&#xff0c;當然這個AppStore是不允許的&#xff0c;所以會在上傳的時候報錯&#xff0c;解決辦法就是要這個SDK剔除掉x86_64, i386這兩個架構 解決辦法&#xff…

[轉]cocos2d游戲開發,常用工具集合

cocos2d游戲開發&#xff0c;常用工具集合 原文地址&#xff1a;http://www.cocoachina.com/bbs/read.php?tid-68951.html 位圖字體工具Bitmap Font ToolsBMFont (Windows)FonteditorGlyph DesignerHieroLabelAtlasCreator粒子編輯工具Particle Editing ToolsParticleCreat…

拓展視野學習前端,我推薦這些

眾所周知&#xff0c;關注公眾號可以了解學習掌握技術方向&#xff0c;學習優質好文&#xff0c;落實到自己項目中。還可以結交圈內好友&#xff0c;讓自己融入到積極上進的技術氛圍&#xff0c;促進自己的技術提升。話不多說&#xff0c;推薦這些優質前端公眾號前端下午茶拓寬…

ios 動畫設計_動畫和講故事在設計中的力量

ios 動畫設計As human beings, we’ve always been fond of storytelling. Just think of campfire stories, Santa Claus, or that thrilling book you just finished. Here’s how you can use the power of storytelling to make your designs better.作為人類&#xff0c;我…

poj 2696 A Mysterious Function

A Mysterious FunctionTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 3517 Accepted: 2398Description For any integers p and q with q > 0, define p mod q to be the integer r with 0 < r < q ?1 such that p?r is divisible by q. For example,…