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 一 序列化组 ...
随机推荐
- .NetCore/ .NetFramework 机制
1.每来一个请求,会启动一个线程. 可以通过下面代码打印出来. 这个线程是主线程,如果用异步,会等待异步线程执行完毕才会返回. 这有个现象,用stmp 发邮件的时候,即使用异步,也会比较卡(选用的邮件 ...
- Java内存模型之从JMM角度分析DCL
DCL,即Double Check Lock,中卫双重检查锁定.其实DCL很多人在单例模式中用过,LZ面试人的时候也要他们写过,但是有很多人都会写错.他们为什么会写错呢?其错误根源在哪里?有什么解决方 ...
- English-培训6-Do you like rap?
- sql server 游标和with as使用
) --声明变量,需要读取的数据 DECLARE cur CURSOR --去掉STATIC关键字即可 FOR WITH Emp AS (SELECT acc.* FROM GXSpreadDB.db ...
- mysql存储过程事务
之前在写一个存储过程的时候由于不仔细导致数据库锁死,这里反省一下. 存储过程是这样的:把数据按顺序插入三张表,如果其中任何一处出错,就把前面已经做了的操作进行回滚,存储过程里面是用事务实现的,我是这么 ...
- Android笔记(十) Android中的布局——表格布局
TableLayout运行我们使用表格的方式来排列控件,它的本质依然是线性布局.表格布局采用行.列的形式来管理控件,TableLayout并不需要明确的声明包含多少行多少列,而是通过添加TableRo ...
- 爬虫:selenium请求库
一.介绍 二.安装 三.基本使用 四.选择器 五.等待元素被加载 六.元素交互操作 七.其他 八.项目练习 一.介绍 # selenium最初是一个自动化测试工具,而爬虫中使用它主要是为了解决requ ...
- 版本问题---Bazel与tensorflow的对应关系
源码安装tf的时候,会用到Bazel,版本不对应,后面会引起好多麻烦. echo "deb [arch=amd64] http://storage.googleapis.com/bazel- ...
- Topshelf 使用
前言 在写后台代码的过程中,经常会遇到要写一些单独的服务.以前呢,直接用的是 .NET 下的 “Windows 服务” 控件开发的. 这个传统的控件开发起来很不方面,使用也不友好.发现有用 Topsh ...
- 解决在jenkins中无法打开robot framework report.html log.html的问题
问题描述: Opening Robot Framework report failed Verify that you have JavaScript enabled in your browser. ...