修改虚拟机镜像大小(qcow2/raw resize)

不多说,直接看
创建一个镜像文件,大小1G,格式是qcow2

muxueqz@muxueqz /tmp $ qemu-img create -f qcow2 t.qcow2 1G
Formatting 't.qcow2', fmt=qcow2 size=1073741824 encryption=off cluster_size=0

查看镜像文件实际占用空间
muxueqz@muxueqz /tmp $ ls -alh t.qcow2
-rw-r--r-- 1 muxueqz muxueqz 193K 8月 31 13:18 t.qcow2

查看qcow2信息
muxueqz@muxueqz /tmp $ qemu-img info t.qcow2
image: t.qcow2
file format: qcow2
virtual size: 1.0G (1073741824 bytes)
disk size: 136K
cluster_size: 65536

加1G(resize +)
muxueqz@muxueqz /tmp $ qemu-img resize t.qcow2 +1G
Image resized.

再查看qcow2信息
muxueqz@muxueqz /tmp $ qemu-img info t.qcow2
image: t.qcow2
file format: qcow2
virtual size: 2.0G (2147483648 bytes)
disk size: 140K
cluster_size: 65536

减1G(resize -)
muxueqz@muxueqz /tmp $ qemu-img resize t.qcow2 -- 2G
qemu-img: This image format does not support resize

!!!qcow2只能加不能减!
再查看qcow2信息
muxueqz@muxueqz /tmp $ qemu-img info t.qcow2
image: t.qcow2
file format: qcow2
virtual size: 2.0G (2147483648 bytes)
disk size: 140K
cluster_size: 65536

果然没变
再试试改变raw格式的大小(resize raw)
同样先创建1G大小的raw
muxueqz@muxueqz /tmp $ qemu-img create -f raw t.raw 1G
Formatting 't.raw', fmt=raw size=1073741824
muxueqz@muxueqz /tmp $ qemu-img info t.raw
image: t.raw
file format: raw
virtual size: 1.0G (1073741824 bytes)
disk size: 1.0M

可以看出raw要比qcow2多占一些空间。
加1G
muxueqz@muxueqz /tmp $ qemu-img resize t.raw -- +1G
Image resized.
muxueqz@muxueqz /tmp $ qemu-img info t.raw
image: t.raw
file format: raw
virtual size: 2.0G (2147483648 bytes)
disk size: 2.0M

减1G(resize -)
muxueqz@muxueqz /tmp $ qemu-img resize t.raw -- -1G
Image resized.
muxueqz@muxueqz /tmp $ qemu-img info t.raw
image: t.raw
file format: raw
virtual size: 1.0G (1073741824 bytes)
disk size: 1.0M

已有 14 条评论 »

  1. ttt ttt

    现在虚拟化发展真快……

    1. 是啊!

      1. ttt ttt

        ganeti也是好东西

        1. 嗯,我也觉得ganeti比opennebula之类依赖libvirt的舒服。

          1. ttt ttt

            轻与重的选择。

          2. 不能认证?!

          3. ttt ttt

            leveldb也是好东西。

          4. 想尝试tiny-cdb,但好诡异

          5. 求靠谱nosql……

          6. mandriva mandriva

            mandriva 用户到此一游

  2. 哈哈,添加了搜狗云输入法的支持

    1. 家里的电脑云输入法

  3. 到处都是云和虚拟。。

  4. ubuntu tour不错

评论已关闭