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.mzph.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,…