kvm 学习(二)镜像
Linux下 如何通过命令行使用现有的镜像创建、启动kvm虚拟机
这里假定已经创建好了相应的镜像:
eg:我这里制作的镜像名称为zu1-centos7.img
# ls
zu1-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'></memory> ---当前虚拟机使用内存,看自己情况是否需要修改
<currentMemory unit='KiB'></currentMemory> ---当前虚拟机可以使用的最大内存,使用内存不得超过这个内存,当使用内存不足的时候,可以在虚拟机里面动态调整内存。
<vcpu placement='static'></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='' bus='' target='' unit=''/>
</disk>
<controller type='ide' index=''>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
</controller>
<controller type='usb' index='' model='piix3-uhci'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
</controller>
<controller type='pci' index='' 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=''>
<model name='isa-serial'/>
</target>
</serial>
<console type='pty'>
<target type='serial' port=''/>
</console>
<input type='tablet' bus='usb'>
<address type='usb' bus='' port=''/>
</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 ( bytes)
disk size: 18G
cluster_size:
Format specific information:
compat: 1.1
lazy 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'></memory>
<currentMemory unit='KiB'></currentMemory>
<vcpu placement='static'></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='' bus='' target='' unit=''/>
</disk>
<controller type='ide' index=''>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
</controller>
<controller type='usb' index='' model='piix3-uhci'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
</controller>
<controller type='pci' index='' 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=''>
<model name='isa-serial'/>
</target>
</serial>
<console type='pty'>
<target type='serial' port=''/>
</console>
<input type='tablet' bus='usb'>
<address type='usb' bus='' port=''/>
</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文件
kvm安装:
https://blog.51cto.com/zero01/2083896
kvm 学习(二)镜像的更多相关文章
- Docker入门之二镜像
Docker大部分的操作都是围绕三大核心概念:镜像.容器.仓库.学Docker首先得了解这几个词.这几个词可能平时也会有涉及,但Docker中可能不是同样得概念. 一.三大核心概念 镜像:可能在安装软 ...
- emberjs学习二(ember-data和localstorage_adapter)
emberjs学习二(ember-data和localstorage_adapter) 准备工作 首先我们加入ember-data和ember-localstorage-adapter两个依赖项,使用 ...
- ReactJS入门学习二
ReactJS入门学习二 阅读目录 React的背景和基本原理 理解React.render() 什么是JSX? 为什么要使用JSX? JSX的语法 如何在JSX中如何使用事件 如何在JSX中如何使用 ...
- TweenMax动画库学习(二)
目录 TweenMax动画库学习(一) TweenMax动画库学习(二) TweenMax动画库学习(三) Tw ...
- Hbase深入学习(二) 安装hbase
Hbase深入学习(二) 安装hbase This guidedescribes setup of a standalone hbase instance that uses the local fi ...
- Struts2框架学习(二) Action
Struts2框架学习(二) Action Struts2框架中的Action类是一个单独的javabean对象.不像Struts1中还要去继承HttpServlet,耦合度减小了. 1,流程 拦截器 ...
- Python学习二:词典基础详解
作者:NiceCui 本文谢绝转载,如需转载需征得作者本人同意,谢谢. 本文链接:http://www.cnblogs.com/NiceCui/p/7862377.html 邮箱:moyi@moyib ...
- Quartz学习--二 Hello Quartz! 和源码分析
Quartz学习--二 Hello Quartz! 和源码分析 三. Hello Quartz! 我会跟着 第一章 6.2 的图来 进行同步代码编写 简单入门示例: 创建一个新的java普通工程 ...
- SpringCloud学习(二):微服务入门实战项目搭建
一.开始使用Spring Cloud实战微服务 1.SpringCloud是什么? 云计算的解决方案?不是 SpringCloud是一个在SpringBoot的基础上构建的一个快速构建分布式系统的工具 ...
- DjangoRestFramework学习二之序列化组件、视图组件 serializer modelserializer
DjangoRestFramework学习二之序列化组件.视图组件 本节目录 一 序列化组件 二 视图组件 三 xxx 四 xxx 五 xxx 六 xxx 七 xxx 八 xxx 一 序列化组 ...
随机推荐
- windows环境下如何搭建Consul+Ocelot
下面的是markdown格式的文档,懒得排版了,有兴趣的话可以去github上看,有源码 Github:https://github.com/yuchengao0721/Consul-Ocelot.g ...
- 从零开始搭建一个简单的基于webpack的vue开发环境
原文地址:https://segmentfault.com/a/1190000012789253?utm_source=tag-newest 从零开始搭建一个简单的基于webpack的react开发环 ...
- Psychedelic therapy
Psychedelic therapy Psychedelic therapy早期在美国应该取得了相当大的成功,方法是在给予受试者充分的心理准备后,一次性运用极高剂量的LSD(0.3−0.6毫克),试 ...
- Jerry带您了解Restful ABAP Programming模型系列之二:Action和Validation的实现
相信通过Jerry的前一篇文章 30分钟用Restful ABAP Programming模型开发一个支持增删改查的Fiori应用,想必大家对Restful ABAP Programming模型已经有 ...
- 18C 新的发行版和补丁模型
18C 新的发行版和补丁模型 以后不再会有第一和第二个发行版,如12.1,12.2,以后只有18C,19C,20C 这样的发行版. 更少的One-Off 补丁 澄清1:版本家族 从生命周期支持上来说1 ...
- springboot系列(九)springboot使用druid数据源
Druid是阿里巴巴开源平台上一个数据库连接池实现,它结合了C3P0.DBCP.PROXOOL等DB池的优点,同时加入了日志监控,可以很好的监控DB池连接和SQL的执行情况,可以说是针对监控而生的DB ...
- 【异常】Maxwell异常 Exception in thread "main" net.sf.jsqlparser.parser.TokenMgrError: Lexical error at line 1, column 596. Encountered: <EOF> after : ""
1 详细异常 Exception in thread "main" net.sf.jsqlparser.parser.TokenMgrError: Lexical error at ...
- java - day012 - 异常 , throws, throw , IO ,RandomAccessFile
异常 封装错误信息的对象 错误信息 类型 例如: NullPointerExce 空指针 提示消息 出错的行号 异常的继承结构 Throwable | - Error 系统级错误 | ...
- Pyspark读取csv文件
#_*_coding:utf-8_*_ # spark读取csv文件 #指定schema: schema = StructType([ # true代表不为null StructField(" ...
- RT-Thread--线程间同步
线程间同步 一个线程从传感器中接收数据并且将数据写到共享内存中,同时另一个线程周期性的从共享内存中读取数据并发送去显示,下图描述了两个线程间的数据传递: 如果对共享内存的访问不是排他性的,那么各个线程 ...