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 一 序列化组 ...
随机推荐
- Springboot2.x整合Redis以及连接哨兵模式/集群模式
依赖: <!--spirngboot版本为2.x--><!-- 加载spring boot redis包,springboot2.0中直接使用jedis或者lettuce配置连接池, ...
- 链接标签<a>去掉下划线
1.去掉下划线 text-decoration:none:
- cell上的按钮点击和左滑冲突
cell上的某个按钮的点击事件,当cell左滑的时候,只要活动的区域也在按钮上,那么按钮的点击事件也会调用. fix: 给按钮添加一个手势(TapGesture)那么当点击的时候就会响应点击手势的方法 ...
- Vue学习官网和Vue的书籍 目录结构
Vue基础知识学习网站[中文] https://cn.vuejs.org/v2/guide/ Vue路由知识学习网站[中文] https://router.vuejs.org/zh/guide/ V ...
- SHA256WithRSA
在上文中了解到SHA和RSA,工作中恰好用到扩展应用:SHA256WithRSA,本文总结下学习过程,备忘の 再提供另外一种方法,实现Java版pem密钥和.Net版xml密钥相互转换的方法 密钥转换 ...
- 【nodejs代理服务器四】代理服务器增加频繁访问的ip加入黑名单
问题 渗透者在扫站的时候会频繁请求,我们可以做一些策略来封堵这些频繁访问的ip,把ip加入黑名单. 策略 2秒之内访问次数超过100,加入黑名单. 实现思路 初次访问把访问Ip作为键,访问ip,时间, ...
- java steam List指定字段去重
如:角色去重处理 baseRoleList = baseRoleList.stream().collect(Collectors.collectingAndThen(Collectors.toColl ...
- JAVA 判断给定目录的大小
题目:给定一个目录,判断该目录的大小,单位为G 思路: 递归拿到目录的子文件,然后取长度,累加 public class FileDemo02 { public static void main(St ...
- c# 值传递
- IPC——概述
现代操作系统下的内存 现在的OS都引入了虚拟内存机制.我们说的内存空间,实际上虚拟内存空间,CPU执行PC指向的命令,PC指向的就是虚拟内存空间地址.虚拟内存机制只不过是OS为我们做了一层虚拟内存地址 ...