æ¬æ主è¦ä»ç»å建èææºçä¸è¬è¿ç¨ã
ä¸å°èææºçæ ¸å¿å°±æ¯ä¸ä¸ªç£çéåï¼è¿ä¸ªéåå¯ä»¥ç解æèææºçç£çï¼éé¢æèææºçæä½ç³»ç»å驱å¨çéè¦æ件ã
å建èææºéå
è¦å¨ä¸å°hostä¸è·èµ·ä¸ä¸ªèææºä¸è¬éè¦ä¸¤ä¸ªæ¥éª¤ï¼
第ä¸æ¥ï¼å建èææºéå
qemu-img create -f raw /images/vm1.raw 8G
qmeu-imgå建çéåæ¯ä¸ä¸ªç¨çæ件ï¼ä¹å°±æ¯è¯´åå建åºæ¥çæ件并没æ8Gï¼å®ä¼éçæ°æ®çå¢å¤æ
¢æ
¢å¢å ï¼ç´å°8G
第äºæ¥ï¼å¯å¨èææº
kvm /imges/vm1.raw
è¿è¡ç»æ: å 为éåéé¢æ²¡æä»»ä½å
容ï¼æ以æ示æ¾ä¸å°å¯å¼å¯¼è®¾å¤ã
使ç¨qemu-img管çéå
qemu-imgåºæ¬å½ä»¤
ä¸èä»ç»äºä½¿ç¨qemu-imgå建éåï¼è¿ä¸èå°ä¼ä»ç»qemu-imgå¨éå管çä¸ç强大åè½ã
qemu-imgæå¾å¤å½ä»¤ï¼å
æ¬ä¸é¢å¸¸ç¨çï¼å½ç¶qemu-img -hä½ æå¾ã
info
æ¥çéåçä¿¡æ¯
create
å建éå
check
æ£æ¥éå
convert
转åéåçæ ¼å¼ï¼ï¼rawï¼qcow â¦â¦ï¼
snapshot
管çéåçå¿«ç
§
rebase
å¨å·²æçéåçåºç¡ä¸å建æ°çéå
resize
å¢å æåå°éå大å°
å建éå
qemu-img create -f <fmt> -o <options> <fname> <size>
举ä¾ï¼
qemu-img create -f raw -o size=4G /images/vm2.raw
hzgatt@hzgatt:~/images$ ll
total 0-rw-r--r-- 1 hzgatt hzgatt 4.0G 6æ 29 14:11 vm2.raw
hzgatt@hzgatt:~/images$ ll -s
total 00 -rw-r--r-- 1 hzgatt hzgatt 4.0G 6æ 29 14:11 vm2.raw
hzgatt@hzgatt:~/images$ qemu-img info vm2.raw
image: vm2.raw
file format: raw
virtual size: 4.0G (4294967296 bytes)
disk size: 0
è½ç¶lsä¸çå°æ件ç大å°æ¯4Gï¼ä½æ¯å®é
ä¸ç£ç大å°æ¯0ãè¿å°±æ¯ç¨çæ件
转å
å°ä¸ä¸ªéåæ件转å为å¦å¤ä¸ç§æ ¼å¼ï¼qemu-imgæ¯æçæ ¼å¼å¯ä»¥çqemu-img -hæåä¸è¡ã
Supported formats: vvfat vpc vmdk vdi sheepdog rbd raw host_cdrom host_floppy host_device file qed qcow2 qcow parallels nbd dmg tftp ftps ftp https http cow cloop bochs blkverify blkdebug
转åå½ä»¤ï¼
qemu-img convert -c -f fmt -O out_fmt -o options fname out_fname
-cï¼éç¨å缩ï¼åªæqcowåqcow2ææ¯æ
-fï¼æºéåçæ ¼å¼ï¼å®ä¼èªå¨æ£æµï¼æ以çç¥ä¹
-O ç®æ éåçæ ¼å¼
-o å
¶ä»éå
fnameï¼æºæ件
out_fname:转ååçæ件
çä¾åï¼
hzgatt@hzgatt:~/images$ qemu-img convert -c -O qcow2 vm2.raw vm2.qcow2
hzgatt@hzgatt:~/images$ ll -s
total 136K
0 -rw-r--r-- 1 hzgatt hzgatt 5.0G 6æ 29 13:55 vm1.raw
136K -rw-r--r-- 1 hzgatt hzgatt 193K 6æ 29 14:22 vm2.qcow2
0 -rw-r--r-- 1 hzgatt hzgatt 4.0G 6æ 29 14:11 vm2.raw
hzgatt@hzgatt:~/images$ qemu-img info vm2.qcow2
image: vm2.qcow2
file format: qcow2
virtual size: 4.0G (4294967296 bytes)
disk size: 136K
cluster_size: 65536
å¦ææ³çè¦è½¬åçæ ¼å¼æ¯æç-oé项æåªäºï¼å¯ä»¥å¨å½ä»¤æ«å°¾å ä¸ -o ï¼
hzgatt@hzgatt:~/images$ qemu-img convert -c -O qcow2 vm2.raw vm2.qcow2 -o ?
Supported options:
size Virtual disk size
backing_file File name of a base image
backing_fmt Image format of the base image
encryption Encrypt the image
cluster_size qcow2 cluster size
preallocation Preallocation mode (allowed values: off, metadata)
å¢å åå°éå大å°
注æï¼åªærawæ ¼å¼çéåæå¯ä»¥æ¹å大å°
hzgatt@hzgatt:~/images$ qemu-img resize vm2.raw +2GB
hzgatt@hzgatt:~/images$ ll -s
total 136K
0 -rw-r--r-- 1 hzgatt hzgatt 5.0G 6æ 29 13:55 vm1.raw
136K -rw-r--r-- 1 hzgatt hzgatt 193K 6æ 29 14:22 vm2.qcow2
0 -rw-r--r-- 1 hzgatt hzgatt 6.0G 6æ 29 14:28 vm2.raw
hzgatt@hzgatt:~/images$ qemu-img info vm2.raw
image: vm2.raw
file format: raw
virtual size: 6.0G (6442450944 bytes)
disk size: 0
å¿«ç
§
æ¥çå¿«ç
§
qemu-img snapshot -l /images/vm2.qcow2
注æï¼åªæqcow2ææ¯æå¿«ç
§
æå¿«ç
§
qemu-img snapshot -c booting vm2.qcow2
举ä¾ï¼
hzgatt@hzgatt:~/images$ qemu-img snapshot -c booting vm2.qcow2
hzgatt@hzgatt:~/images$ qemu-img snapshot -l vm2.qcow2
Snapshot list:
ID TAG VM SIZE DATE VM CLOCK
1 booting 0 2012-06-29 14:35:04 00:00:00.000
ä»å¿«ç
§æ¢å¤ï¼
qemu-img snapshot -a 1 /images/vm2.qcow2
ç¶åä»kvmå¯å¨è¿ä¸ªèææºï¼ä¼åç°èææºåå¨æå¿«ç
§æ¶çç¶æäº
å é¤å¿«ç
§ï¼
qemu-img snapshot -d 2 /images/vm2.qcow
使ç¨æ´¾çéå(qcow2)
å½å建çèææºè¶æ¥è¶å¤ï¼å¹¶ä¸ä½ åç°å¥½å¤èææºé½æ¯åä¸ä¸ªæä½ç³»ç»ï¼å®ä»¬çåºå«å°±æ¯å®è£
ç软件ä¸å¤§ä¸æ ·ï¼é£ä¹ä½ è¯å®ä¼å¸ææä»ä»¬å
Œ
±çé¨åæååºæ¥ï¼åªä¿åé£äºä¸å
Œ
±é¨åä¸åçä¸è¥¿ï¼è¿æ ·éå大å°ä¸å»äºï¼ç©ºé´åå¤äºï¼ç®¡çä¹æ¹ä¾¿äºãæ´¾çéåå°±æ¯ç¨æ¥å¹²è¿äºçï¼
é¦å
çä¸ä¸ªåå§éå
hzgatt@hzgatt:~/images$ qemu-img info vm3_base.raw
image: vm3_base.raw
file format: raw
virtual size: 2.0G (2147483648 bytes)
disk size: 2.0G
ç°å¨æ们æ°å»ºä¸ä¸ªéåï¼ä½æ¯æ´¾çèªå®
hzgatt@hzgatt:~/images$ qemu-img create -f qcow2 vm3_5.qcow2 -o backing_file=vm3_base.raw 5G
Formatting 'vm3_5.qcow2', fmt=qcow2 size=5368709120 backing_file='vm3_base.raw' encryption=off cluster_size=65536
hzgatt@hzgatt:~/images$ ll-rw-r--r-- 1 hzgatt hzgatt 193K 6æ 29 15:00 vm3_5.qcow2
-rw-r--r-- 1 hzgatt hzgatt 2.0G 6æ 29 14:51 vm3_base.raw
hzgatt@hzgatt:~/images$ qemu-img info vm3_5.qcow2
image: vm3_5.qcow2
file format: qcow2
virtual size: 5.0G (5368709120 bytes)
disk size: 136K
cluster_size: 65536
backing file: vm3_base.raw (actual path: vm3_base.raw)
^_^ï¼è¿ä¸ªéåæ136Kï¼å¤çäºå§ãDRYæ°¸è¿çççåï¼
ç°å¨æ们å¨vm3_5.qcow2ä¸æäºå¾å¤å®å
¨è¡¥ä¸ï¼ç¶ååç°æåæ³å¨vm3_5.qcow2ä¸æ´¾çæ°çèææºï¼o(â©â©)o...ååï¼è¿ä¸æä¹åå¢ï¼
hzgatt@hzgatt:~/images$ qemu-img convert -O raw vm3_5.qcow2 vm3_base2.raw
hzgatt@hzgatt:~/images$ qemu-img info vm3_base2.raw
image: vm3_base2.raw
file format: raw
virtual size: 5.0G (5368709120 bytes)
disk size: 592M
è¿ä¸ªè½¬åå°ä¼å°vm3_5åbaseå并ï¼çææ°çvm3_base2.rawï¼ç¶åä½ å°±å¯ä»¥ç»§ç»æ ç©·æ å°½çæ´¾çä¹æ
äºï¼
温馨提示:答案为网友推荐,仅供参考