[root@node1 ~]# qemu-img -h
qemu-img version 1.5.3, Copyright (c) 2004-2008 Fabrice Bellard
usage: qemu-img command [command options]
QEMU disk image utility
Command syntax:
check [-q] [-f fmt] [--output=ofmt] [-r [leaks | all]] [-T src_cache] filename
create [-q] [-f fmt] [-o options] filename [size]
commit [-q] [-f fmt] [-t cache] filename
compare [-f fmt] [-F fmt] [-T src_cache] [-p] [-q] [-s] filename1 filename2
convert [-c] [-p] [-q] [-n] [-f fmt] [-t cache] [-T src_cache] [-O output_fmt] [-o options] [-s snapshot_name] [-S sparse_size] filename [filename2 [...]] output_filename
info [-f fmt] [--output=ofmt] [--backing-chain] filename
map [-f fmt] [--output=ofmt] filename
snapshot [-q] [-l | -a snapshot | -c snapshot | -d snapshot] filename
rebase [-q] [-f fmt] [-t cache] [-T src_cache] [-p] [-u] -b backing_file [-F backing_fmt] filename
resize [-q] filename [+ | -]size
amend [-q] [-f fmt] [-t cache] -o options filename
Command parameters:
'filename' is a disk image filename
'fmt' is the disk image format. It is guessed automatically in most cases
'cache' is the cache mode used to write the output disk image, the valid
options are: 'none', 'writeback' (default, except for convert), 'writethrough',
'directsync' and 'unsafe' (default for convert)
'src_cache' is the cache mode used to read input disk images, the valid
options are the same as for the 'cache' option
'size' is the disk image size in bytes. Optional suffixes
'k' or 'K' (kilobyte, 1024), 'M' (megabyte, 1024k), 'G' (gigabyte, 1024M),
'T' (terabyte, 1024G), 'P' (petabyte, 1024T) and 'E' (exabyte, 1024P) are
supported. 'b' is ignored.
'output_filename' is the destination disk image filename
'output_fmt' is the destination format
'options' is a comma separated list of format specific options in a
name=value format. Use -o ? for an overview of the options supported by the
used format
'-c' indicates that target image must be compressed (qcow format only)
'-u' enables unsafe rebasing. It is assumed that old and new backing file
match exactly. The image doesn't need a working backing file before
rebasing in this case (useful for renaming the backing file)
'-h' with or without a command shows this help and lists the supported formats
'-p' show progress of command (only certain commands)
'-q' use Quiet mode - do not print any output (except errors)
'-S' indicates the consecutive number of bytes (defaults to 4k) that must
contain only zeros for qemu-img to create a sparse image during
conversion. If the number of bytes is 0, the source will not be scanned for
unallocated or zero sectors, and the destination image will always be
fully allocated
'--output' takes the format in which the output must be done (human or json)
'-n' skips the target volume creation (useful if the volume is created
prior to running qemu-img)
Parameters to check subcommand:
'-r' tries to repair any inconsistencies that are found during the check.
'-r leaks' repairs only cluster leaks, whereas '-r all' fixes all
kinds of errors, with a higher risk of choosing the wrong fix or
hiding corruption that has already occurred.
Parameters to snapshot subcommand:
'snapshot' is the name of the snapshot to create, apply or delete
'-a' applies a snapshot (revert disk to saved state)
'-c' creates a snapshot
'-d' deletes a snapshot
'-l' lists all snapshots in the given image
Parameters to compare subcommand:
'-f' first image format
'-F' second image format
'-s' run in Strict mode - fail on different image size or sector allocation
Supported formats: vvfat vpc vmdk vhdx vdi ssh sheepdog rbd raw host_cdrom host_floppy host_device file qed qcow2 qcow parallels nbd iscsi gluster dmg tftp ftps ftp https http cloop bochs blkverify blkdebug
[root@node1 ~]#
提示:从上面的示例可以看到除了off指定创建的磁盘,我们看到的大小是一个很小的大小,其他模式在文件系统上表现形式都是我们指定大小的空间;从qemu-img info 命令来看,off和metadata disk size是很小的空间,虚拟空间是我们指定的大小;后者falloc和full disk大小和virtual size大小都是我们指定的大小;在文件系统上看到的磁盘文件之所以要大于我们指定的空间,是因为在文件系统上它作为一个文件形式存在,它也有元素数据信息的;
qemu-img info :用于查看指定磁盘文件的详细信息;用法格式:qemu-img info [-f fmt] [--output=ofmt] [--backing-chain] filename
[root@node1 ~]# qemu-img info /kvm/images/centos7.qcow2
image: /kvm/images/centos7.qcow2
file format: qcow2
virtual size: 10G (10737418240 bytes)
disk size: 196K
cluster_size: 65536
Format specific information:
compat: 1.1
lazy refcounts: false
[root@node1 ~]# qemu-img info /kvm/images/win7.qcow2
image: /kvm/images/win7.qcow2
file format: qcow2
virtual size: 50G (53687091200 bytes)
disk size: 8.5G
cluster_size: 65536
Format specific information:
compat: 1.1
lazy refcounts: false
[root@node1 ~]#
[root@node1 ~]# qemu-img check /kvm/images/win7.qcow2
No errors were found on the image.
138808/819200 = 16.94% allocated, 27.22% fragmented, 0.00% compressed clusters
Image end offset: 9098887168
[root@node1 ~]# qemu-img check /kvm/images/centos7.qcow2
No errors were found on the image.
Image end offset: 262144
[root@node1 ~]#
[root@node1 ~]# qemu-img snapshot -l /kvm/images/centos7.qcow2
Snapshot list:
ID TAG VM SIZE DATE VM CLOCK
1 snapshot_centos7_1 0 2017-03-29 01:16:08 00:00:00.000
[root@node1 ~]#
-a:应用快照,将磁盘恢复到做快照那一刻;
[root@node1 ~]# qemu-img snapshot -a snapshot_centos7_1 /kvm/images/centos7.qcow2
[root@node1 ~]#
-d:删除快照
[root@node1 ~]# qemu-img snapshot -l /kvm/images/centos7.qcow2
Snapshot list:
ID TAG VM SIZE DATE VM CLOCK
1 snapshot_centos7_1 0 2017-03-29 01:16:08 00:00:00.000
[root@node1 ~]# qemu-img snapshot -d snapshot_centos7_1 /kvm/images/centos7.qcow2
[root@node1 ~]# qemu-img snapshot -l /kvm/images/centos7.qcow2
[root@node1 ~]#
[root@node1 ~]# virsh console centos7
连接到域 centos7
换码符为 ^]
CentOS Linux 7 (Core)
Kernel 3.10.0-693.el7.x86_64 on an x86_64
localhost login: root
Password:
Last login: Wed Aug 19 09:30:56 on tty1
[root@localhost ~]# fdisk -l
Disk /dev/vda: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000a5c54
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 1050623 524288 83 Linux
/dev/vda2 1050624 20971519 9960448 8e Linux LVM
Disk /dev/mapper/centos-root: 10.2 GB, 10192158720 bytes, 19906560 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/mapper/centos-swap: 4 MB, 4194304 bytes, 8192 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/vdb: 2148 MB, 2148073472 bytes, 4195456 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
[root@localhost ~]#
提示:可以看到有一个vdb的磁盘已经被虚拟机识别;
在虚拟机内部对/dev/vdb进行分区,并格式化
[root@localhost ~]# fdisk /dev/vdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xe6bebed1.
Command (m for help): p
Disk /dev/vdb: 2148 MB, 2148073472 bytes, 4195456 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xe6bebed1
Device Boot Start End Blocks Id System
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-4195455, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-4195455, default 4195455):
Using default value 4195455
Partition 1 of type Linux and of size 2 GiB is set
Command (m for help): p
Disk /dev/vdb: 2148 MB, 2148073472 bytes, 4195456 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xe6bebed1
Device Boot Start End Blocks Id System
/dev/vdb1 2048 4195455 2096704 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# mkfs.xfs /dev/vdb1
meta-data=/dev/vdb1 isize=512 agcount=4, agsize=131044 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=524176, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@localhost ~]#
#include<iostream>
#include<cassert>
using namespace std;
template<class T, int SIZE = 50>
class Stack{
private:
T list[SIZE];//数组存放栈的元素
int top;//栈顶位置
public:
Stack(
Gson提供了丰富的预定义类型适配器,在对象和JSON串之间进行序列化和反序列化时,指定对象和字符串之间的转换方式,
DateTypeAdapter
public final class DateTypeAdapter extends TypeAdapter<Date> {
public static final TypeAdapterFacto