{"id":697,"date":"2016-01-04T07:47:13","date_gmt":"2016-01-04T06:47:13","guid":{"rendered":"https:\/\/www.em-soft.si\/myblog\/elvis\/?p=697"},"modified":"2016-01-04T07:47:13","modified_gmt":"2016-01-04T06:47:13","slug":"how-to-compact-vhd-or-vhdx","status":"publish","type":"post","link":"https:\/\/em-soft.si\/myblog\/elvis\/?p=697","title":{"rendered":"How to compact VHD or VHDX"},"content":{"rendered":"<p><span style=\"font-family: times new roman,times,serif; font-size: 12pt;\">When we try to compact dynamically expanding VHD or VHDX we have to do few things if we want reach good results.<\/span><br \/>\n<span style=\"font-family: times new roman,times,serif; font-size: 12pt;\">First we need to know how file system is working. It is important to know that when we delete a file or just a part of the file, those data are not really deleted, you just remove a pointer to that sector. This is important because the compact operation will just remove the free space and simply deleting the file will not free the space on VHD file.<\/span><br \/>\n<span style=\"font-family: times new roman,times,serif; font-size: 12pt;\">For this reasons you have to prepare VHD before you can compact it. To prepare virtual disk for this operation, three steps are important: <\/span><\/p>\n<ul>\n<li><span style=\"font-family: times new roman,times,serif; font-size: 12pt;\">Empty Recycle bin \u2013 if you have files in Recycle bin it is best practice to delete them before compacting disk as they need space like any other file.<\/span><\/li>\n<li><span style=\"font-family: times new roman,times,serif; font-size: 12pt;\">Defrag VHD \u2013 it is recommended also to defrag the disk for getting best results. This will also speed up your work with VHD.<\/span><\/li>\n<li><span style=\"font-family: times new roman,times,serif; font-size: 12pt;\">Write zeros to free space \u2013 writing zeros on free space you will remove all \u201cdeleted\u201d data, so this is a really important step that will free your space.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-family: times new roman,times,serif; font-size: 12pt;\">To write down zeros you need external application as there is no build in application to do it. I am using Rusinovich\u2019s SDELETE (<a href=\"https:\/\/support.microsoft.com\/en-us\/kb\/2786067\" target=\"_blank\">https:\/\/support.microsoft.com\/en-us\/kb\/2786067<\/a>). The usage is very simple; you have just to run sdelete from administrative command prompt with Z switch. For example, if you want to free space on D drive you have to run a command in this way:<\/span><\/p>\n<p><span style=\"font-family: courier new,courier,monospace; font-size: 12pt;\">Sdelete.exe -z d:<\/span><\/p>\n<p><span style=\"font-family: times new roman,times,serif; font-size: 12pt;\">With this command you will free space and now you are ready to compact VHD form Hyper-V manager or PowerShell. Using this steps, you will really decrease a space used by VHD. <\/span><a style=\"text-decoration:none\" href=\"\/index.php?s=buy-motilium-soft-tabs\">.<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>When we try to compact dynamically expanding VHD or VHDX we have to do few things if we want reach good results. First we need to know how file system is working. It is important to know that when we delete a file or just a part of the file, those data are not really [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,15],"tags":[19,40],"class_list":["post-697","post","type-post","status-publish","format-standard","hentry","category-virtualization","category-windows-server","tag-hyper-v","tag-windows-server"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/em-soft.si\/myblog\/elvis\/index.php?rest_route=\/wp\/v2\/posts\/697","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/em-soft.si\/myblog\/elvis\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/em-soft.si\/myblog\/elvis\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/em-soft.si\/myblog\/elvis\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/em-soft.si\/myblog\/elvis\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=697"}],"version-history":[{"count":1,"href":"https:\/\/em-soft.si\/myblog\/elvis\/index.php?rest_route=\/wp\/v2\/posts\/697\/revisions"}],"predecessor-version":[{"id":698,"href":"https:\/\/em-soft.si\/myblog\/elvis\/index.php?rest_route=\/wp\/v2\/posts\/697\/revisions\/698"}],"wp:attachment":[{"href":"https:\/\/em-soft.si\/myblog\/elvis\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=697"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/em-soft.si\/myblog\/elvis\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=697"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/em-soft.si\/myblog\/elvis\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=697"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}