收缩QEMU虚拟机磁盘空间

相机照了很多照片,删了可惜,只能精选一些放网上.还有很多景色照片全部丢到百度网盘了.再加上很多虚拟机磁盘镜像,硬盘空间经常不够用.除了删除大量不经典的照片,就是在虚拟机镜像上想办法了.

qcow2磁盘镜像在创建后只占很小的空间,随着虚拟机里磁盘空间的真正的使用,镜像会越来越大.即便文件删除后,空间也不会自动收缩.下面是的方法可以用于回收为使用的磁盘空间.

+ Reclaimed space of my old guests images

  1) Fill unused space to zero:
    In Linux guests:
     # dd if=/dev/zero of=./a.out bs=1M
     # rm a.out

    In Windows guests:
     # download sdelete from http://technet.microsoft.com/en-us/sysinternals/bb897443.aspx
     # sdelete -c c:

  2) # qemu-img convert -p -O qcow2 orig.qcow2 new.qcow2
     # rm orig.qcow2

收缩了几个用了很长时间的镜像,笔记本有剩余40+G空间感觉很富有 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.