[转] Snapshotting with libvirt for qcow2 images
http://kashyapc.com/2011/10/04/snapshotting-with-libvirt-for-qcow2-images/
Libvirt 0.9.6 was recently out. Take a look at 0.9.5 changelog for truckload of features/bugfixes/cleanups(specifically snapshot related) from the libvirt team.
So, I grabbed the F14 srpm from Libvirt ftp, and made a quick Fedora koji scratch build of libvirt-0.9.6 for Fedora 15 and gave the snapshot features a whirl. Here it goes:
(Also noted below is some very useful discussion I had(on #virt, OFTC) with Eric Blake (Upstream/Red Hat’s Libvirt dev, very friendly guy.) on snapshots. It was way informative not to capture it.)
Context on types of snapshots
At the moment, snapshotting in KVM/QEMU/Libvirt land is supported primarily for QCOW2 disk images. I briefly discussed about Qcow2 previously here.
There are several different types of snapshots possible. Some idea on that:
Internal snapshot: A type of snapshot, where a single QCOW2 file will hold both the ‘saved state’ and the ‘delta’ since that saved point. ‘Internal snapshots’ are very handy because it’s only a single file where all the snapshot info. is captured, and easy to copy/move around the machines.
External snapshot: Here, the ‘original qcow2 file’ will be in a ‘read-only’ saved state, and the new qcow2 file(which will be generated once snapshot is created) will be the delta for the changes. So, all the changes will now be written to this delta file. ‘External Snapshots’ are useful for performing backups. Also, external snapshot creates a qcow2 file with the original file as its backing image, and the backing file can be /read/ in parallel with the running qemu.
VM State: This will save the guest/domain state to a file. So, if you take a snapshot including VM state, we can then shut off that guest and use the freed up memory for other purposes on the host or for other guests. Internally this calls qemu monitor’s ‘savevm’ command. Note that this only takes care of VM state(and not disk snapshot). To try this out:
#------------------------------------------------
# Memory before saving the guest f15vm3
$ free -m
total used free shared buffers cached
Mem: 10024 5722 4301 0 164 4445
-/+ buffers/cache: 1112 8911
Swap: 0 0 0
#------------------------------------------------
$ virsh list
Id Name State
----------------------------------
5 f15guest running
6 f15vm3 running
#------------------------------------------------
# Save the guest f15vm3 to a file 'foof15vm3'
$ virsh save f15vm3 foof15vm3
Domain f15vm3 saved to foof15vm3
#------------------------------------------------
# Now, f15vm3 is gracefully saved/shutdown.
$ virsh list
Id Name State
----------------------------------
5 f15guest running
#------------------------------------------------
# Notice the RAM being freed
$ free -m
total used free shared buffers cached
Mem: 10024 5418 4605 0 164 4493
-/+ buffers/cache: 760 9263
Swap: 0 0 0
#------------------------------------------------
# Let's restore the guest back from the file 'foof15vm3'
$ virsh restore foof15vm3
Domain restored from foof15vm3
#------------------------------------------------
# List the status. f15vm3 is up and running.
$ virsh list
Id Name State
----------------------------------
5 f15guest running
7 f15vm3 running
#------------------------------------------------
For brevity, let’s try out internal disk snapshots where all the snapshot info. (like disk and VM state info) are stored in a single qcow2 file.
Virsh(libvirt shell interface to manage guests) has some neat options for snapshot supports. So, I’ve got an F15 guest (Qcow2 disk image).
Internal Disk Snapshots when the guest is online/running
For illustration purpose, let’s use a Fedora-15 guest called ‘f15guest’ .
$ virsh list
Id Name State
----------------------------------
4 f15guest running $
For clarity, ensure there are no prior snapshot instances around.
$ virsh snapshot-list f15guest
Name Creation Time State
------------------------------------------------------------ $
Before creating a snapshot, we need to create a snapshot xml file with 2 simple elements (name and description) if you need sensible name for the snapshot. Note that only these two fields are user settable. Rest of the info. will be filled by Libvirt.
$ cat /var/tmp/snap1-f15guest.xml
<domainsnapshot>
<name>snap1-f15pki </name>
<description>F15 system with dogtag pki packages </description>
</domainsnapshot>
$
Eric Blake noted that, the domainsnapshot xml file is optional now for ‘snapshot-create’ if you don’t need a description for the snapshot. And if it’s okay with libvirt generating the snapshot name for us. (More on this, refer below)
Now, I’m taking a snapshot while the ‘guest’ is running live. Here, Eric noted that, especially when running/live, the more RAM the guest has, and the more active the guest is modifying that RAM, the longer the it will take to create a snapshot. This was a guest was mostly an idle guest.
$ virsh snapshot-create f15guest /var/tmp/snap1-f15guest.xml
Domain snapshot snap1-f15pki created from '/var/tmp/snap1-f15guest.xml'
$
While the snapshot-creation is in progress on the live guest, the state of the guest will be ‘paused’.
$ virsh list
Id Name State
----------------------------------
4 f15guest paused $
Once, the snapshot is created, list the snapshots of f15guest
$ virsh snapshot-list f15guest
Name Creation Time State
------------------------------------------------------------
snap1-f15pki 2011-10-04 19:04:00 +0530 running $
Internal snapshot while the guest is offline
For fun, I created another snapshot, but after shutting down the guest. Now, the snapshot creation is just instantaneous.
$ virsh list
Id Name State
---------------------------------- $ virsh snapshot-create f15guest
Domain snapshot 1317757628 created
List the snapshots of ‘f15guest’ using virsh.
$ virsh snapshot-list f15guest
Name Creation Time State
------------------------------------------------------------
1317757628 2011-10-05 01:17:08 +0530 shutoff
snap1-f15pki 2011-10-04 19:04:00 +0530 running
To see some information about the VM size, snapshot info:
$ qemu-img info /export/vmimgs/f15guest.qcow2
image: /export/vmimgs/f15guest.qcow2
file format: qcow2
virtual size: 8.0G (8589934592 bytes)
disk size: 3.2G
cluster_size: 65536
Snapshot list:
ID TAG VM SIZE DATE VM CLOCK
1 snap1-f15pki 1.7G 2011-10-04 19:04:00 32:06:34.974
2 1317757628 0 2011-10-05 01:17:08 00:00:00.000
$
To revert to a particular snapshot, virsh snapshot-revert domain snapshotname
Also, discussed with Eric, in what cases does virsh invoke Qemu’s ‘savevm‘ and ‘qemu-img snapshot -c‘ commands while creating different types of snapshots discussed earlier above. Here is the outline:
- it uses ‘qemu-img snapshot -c‘ if the domain is offline and –disk-only was not specified
- it uses qemu’s ‘savevm‘ if the domain is online and –disk-only was not specified
- it uses qemu’s ‘snapshot_blkdev‘ if the domain is online and –disk-only is specified
(Note: –disk-only is an option to capture only ‘disk state’ but not VM state. This option is available w/ virsh ‘snapshot-create’ or ‘snapshot-create-as’ commands.)
[转] Snapshotting with libvirt for qcow2 images的更多相关文章
- 别以为真懂Openstack: 虚拟机创建的50个步骤和100个知识点(3)
四.Nova-compute 步骤17:nova-compute接收到请求后,通过Resource Tracker将创建虚拟机所需要的资源声明占用 步骤18:调用Neutron API配置Networ ...
- linux kvm虚拟机快速构建及磁盘类型
KVM命令管理 virsh命令:用来管理各虚拟机的接口命令查看/创建/停止/关闭...支持交互模式格式:virsh 控制指令 [虚拟机名称] [参数] [root@room1pc01 桌面]# vir ...
- kvm网络虚拟化管理
1. Linux Bridge网桥管理 一个网桥上添加多个虚拟机,虚拟机之间是可以相互通信的的,同时虚拟机也都可以通外网. kvm的网桥管理可以通过brctl命令 [root@localhost ~] ...
- linux初学者-虚拟机管理篇
linux初学者-虚拟机管理篇 之前已经介绍过,在linux系统的学习中,一般需要在虚拟机中进行操作,但是虚拟机是如何安装的呢?又是如何管理的呢?下文将对虚拟机的安装和管理进行一个简要的介绍. 1.虚 ...
- qcow2磁盘加密及libvirt访问
1.创建qcow2加密磁盘[root@Coc-5 test_encrypt]# qemu-img convert -f qcow2 -O qcow2 -o encryption template_ ...
- Nova 操作汇总(限 libvirt 虚机) [Nova Operations Summary]
本文梳理一下 Nova 主要操作的流程. 0. Nova REST-CLI-Horizon 操作对照表 Nova 基本的 CRUD 操作和 extensions: # 类别 Nova V2 REST ...
- KVM 介绍(8):使用 libvirt 迁移 QEMU/KVM 虚机和 Nova 虚机 [Nova Libvirt QEMU/KVM Live Migration]
学习 KVM 的系列文章: (1)介绍和安装 (2)CPU 和 内存虚拟化 (3)I/O QEMU 全虚拟化和准虚拟化(Para-virtulizaiton) (4)I/O PCI/PCIe设备直接分 ...
- KVM 介绍(7):使用 libvirt 做 QEMU/KVM 快照和 Nova 实例的快照 (Nova Instances Snapshot Libvirt)
学习 KVM 的系列文章: (1)介绍和安装 (2)CPU 和 内存虚拟化 (3)I/O QEMU 全虚拟化和准虚拟化(Para-virtulizaiton) (4)I/O PCI/PCIe设备直接分 ...
- KVM 介绍(6):Nova 通过 libvirt 管理 QEMU/KVM 虚机 [Nova Libvirt QEMU/KVM Domain]
学习 KVM 的系列文章: (1)介绍和安装 (2)CPU 和 内存虚拟化 (3)I/O QEMU 全虚拟化和准虚拟化(Para-virtulizaiton) (4)I/O PCI/PCIe设备直接分 ...
随机推荐
- Java I/O (1) - 输入/输出流
先说概念: Java API中,可以从其中读入一个字节序列的对象叫做输入流,可以向其中写入一个字节序列的对象叫做输出流.这些字节序列的来源地 和 目的地 可以文件.网络连接甚至内存块.抽象类Input ...
- Python学习笔记5程序的控制结构
1.分支结构 (1)单分支结构 (2)二分支结构 (3)多分支结构 条件判断 (4)程序的异常处理 2.实例:身体质量指数BMI 思路一(国内,稍作修改就是国际): 思路二: height,weigh ...
- zabbix基础使用--添加ping监控
1.添加item key值表示的含义:icmpping[<target>,<packets>,<interval>,<size>,<timeout ...
- mysql学习5:数据库设计
mysql学习5:数据库设计 本文转载:https://blog.51cto.com/9291927/2087925:原创为天山老妖S 一.数据库设计简介 按照规范设计,将数据库的设计过程分为六个阶段 ...
- Codeforces Round #552 (Div. 3) C题
题目网址:http://codeforces.com/contest/1154/problem/C 题目意思:小猫吃三种食物,A,B,C,一周吃食物的次序是,A,B,C,A,C,B,A,当小猫该天无食 ...
- (一)java基础
注:本栏均为学习笔记 一.java标识符 标识符是用来命名的. 规则:字母数字下划线$组成,且不能以数字开头.不能使用java中的关键字. 一般:项目名.包名全部小写 变量名.方法名首字母小写,驼峰命 ...
- freemarker使用
获得FreeMarker 官网:http://freemarker.org/ 中文帮助文档:https://sourceforge.net/projects/freemarker/files/chin ...
- Solidity-让合约地址 接受ETH的转账充值的 三种方式
以太坊智能合约开发:让合约接受转账 在以太坊智能合约开发中,通常会有向合约地址进行转账的需求,那么有几种向合约地址进行转账的方式呢? 有三种方式: 部署合约时转账 调用合约提供的方法 直接向合约地址进 ...
- CentOS7升级默认内核
安装内核升级镜像源 rpm -Uvh https://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm Yum安装内核 yum --e ...
- mybatis学习笔记1.零碎记录
1.conf.xml文件中的一些标签先后顺序会有影响. conf.xml文件<configuration>标签对里面配置的<typeAliases>标签的位置还有讲究?我将其放 ...