{"id":538,"date":"2014-09-11T21:29:54","date_gmt":"2014-09-11T09:29:54","guid":{"rendered":"http:\/\/mdickinson.dyndns.org\/php\/wordpress\/?p=538"},"modified":"2014-09-11T21:29:54","modified_gmt":"2014-09-11T09:29:54","slug":"compressing-qcow2-images-important-tip","status":"publish","type":"post","link":"https:\/\/mdickinson.dyndns.org\/php\/wordpress\/?p=538","title":{"rendered":"Compressing qcow2 images &#8211; important tip"},"content":{"rendered":"<p>This probably applies to normal ext4 filesystems as well as LVM ones. <\/p>\n<p>This post is because I deleted 60Gb of data from a qcow2 disk, and when I did a compress only got the disk image to shrink about 5Gb. Obviously something was not working as I expected.<\/p>\n<p>In the past my qcow images used only ext4 filesystems so my initial thought was &#8220;bugger, why did I use LVM&#8221;&#8230; but then I started thinking. What is available to compress ?.<\/p>\n<p>Silly me&#8230; if you delete 60Gb of data of course you will not get space back, deleting a file only removes indexes (vtoc entries, pointer to the file etc) and the actual data is still clogging the disk until it is overwritten; a qemu-img compress won&#8217;t be able to get data back while that junk is still left there.<\/p>\n<p>I wrote zeros to the free space on the disk&#8230; as it was a live running system I tried to guestimate a safe filesize, I guessed wrong and filled the filesystem, thats life.<\/p>\n<pre>\r\n[mark@vosprey2 ~]$ dd if=\/dev\/zero of=junk count=1000000 bs=1024000\r\ndd: error writing \u2018junk\u2019: No space left on device\r\n80188+0 records in\r\n80187+0 records out\r\n82112401408 bytes (82 GB) copied, 28142.7 s, 2.9 MB\/s\r\n[mark@vosprey2 ~]$ df -k .\/\r\nFilesystem              1K-blocks     Used Available Use% Mounted on\r\n\/dev\/mapper\/fedora-root  99653104 94338024    229896 100% \/\r\n[mark@vosprey2 ~]$ rm junk\r\n[mark@vosprey2 ~]$ df -k .\/\r\nFilesystem              1K-blocks     Used Available Use% Mounted on\r\n\/dev\/mapper\/fedora-root  99653104 14149764  80418156  15% \/\r\n[mark@vosprey2 ~]$ \r\n<\/pre>\n<p>Then shutdown the VM and use qemu-img to compress the qcow2 disk image. Well that certainly resolved my problem.<\/p>\n<pre>\r\n[root@vmhost1 VM_disks]# ls -ltr osp*\r\n-rw-r--r--. 1 root root 68162533376 Sep  9 22:17 osprey_bkp_aftercompress.qcow2  < == compress of a 75Gb disk before I wrote zeros\r\n-rw-r--r--. 1 root root 93995008000 Sep 11 18:12 osprey_precomp.qcow2            <== filesize after writing zeros filled the disk\r\n-rw-r--r--. 1 root root 11430384640 Sep 11 18:54 osprey.qcow2                    <== size after compress of zero filled filesystem\r\n<\/pre>\n<p>Well. I got well over the 60Gb I expected back.<\/p>\n<p>So qemu-img compress works great, if you do a little manual work before hand to make sure it is able to compress :-).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This probably applies to normal ext4 filesystems as well as LVM ones. This post is because I deleted 60Gb of data from a qcow2 disk, and when I did a compress only got the disk image to shrink about 5Gb. &hellip; <a href=\"https:\/\/mdickinson.dyndns.org\/php\/wordpress\/?p=538\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,3],"tags":[],"class_list":["post-538","post","type-post","status-publish","format-standard","hentry","category-my-nux-thoughts-and-notes","category-virtual-machines"],"_links":{"self":[{"href":"https:\/\/mdickinson.dyndns.org\/php\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/538","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mdickinson.dyndns.org\/php\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mdickinson.dyndns.org\/php\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mdickinson.dyndns.org\/php\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/mdickinson.dyndns.org\/php\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=538"}],"version-history":[{"count":1,"href":"https:\/\/mdickinson.dyndns.org\/php\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/538\/revisions"}],"predecessor-version":[{"id":539,"href":"https:\/\/mdickinson.dyndns.org\/php\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/538\/revisions\/539"}],"wp:attachment":[{"href":"https:\/\/mdickinson.dyndns.org\/php\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=538"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mdickinson.dyndns.org\/php\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=538"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mdickinson.dyndns.org\/php\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=538"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}