Shrink Virtual Hard Disk Size
Free disk space. Decrease the size of a virtual disk. Decrease virtual machine storage capacity.
Contents
Introduction[edit]
Copy or share this direct link!
Click = Copy
Copied to clipboard!
https://www.kicksecure.com/wiki/Shrink_Virtual_Harddisk?oldid=82728#Introduction
Click below ↴ = Copy to Clipboard
Click = Copy
Copied to clipboard!
[[Shrink_Virtual_Harddisk#Introduction|Introduction]]
Copy as Wikitext
Click = Copy
Copied to clipboard!
[Introduction](https://www.kicksecure.com/wiki/Shrink_Virtual_Harddisk?oldid=82728#Introduction)
for Discourse, reddit, GitHub
Click = Copy
Copied to clipboard!
[Introduction](https://www.kicksecure.com/wiki/Shrink_Virtual_Harddisk?oldid=82728#Introduction)
Copy as Markdown
Click = Copy
Copied to clipboard!
[url=https://www.kicksecure.com/wiki/Shrink_Virtual_Harddisk?oldid=82728#Introduction]Introduction[/url]
Copy as phpBB
Click below ↴ = Open social URL with share data
We don't use embedded scripts
This share button is completely self-hosted by this webserver. No scripts from any of the social networks are embedded on this webserver. See also
Social Share Button.
Over the course of many system upgrades, logging, etc. the image files can grow substantially. Deletion of obsolete files does not automatically shrink the disk size back as it has “grown” to accommodate the data needed.
Overview[edit]
Copy or share this direct link!
Click = Copy
Copied to clipboard!
https://www.kicksecure.com/wiki/Shrink_Virtual_Harddisk?oldid=82728#Overview
Click below ↴ = Copy to Clipboard
Click = Copy
Copied to clipboard!
[[Shrink_Virtual_Harddisk#Overview|Overview]]
Copy as Wikitext
Click = Copy
Copied to clipboard!
[Overview](https://www.kicksecure.com/wiki/Shrink_Virtual_Harddisk?oldid=82728#Overview)
for Discourse, reddit, GitHub
Click = Copy
Copied to clipboard!
[Overview](https://www.kicksecure.com/wiki/Shrink_Virtual_Harddisk?oldid=82728#Overview)
Copy as Markdown
Click = Copy
Copied to clipboard!
[url=https://www.kicksecure.com/wiki/Shrink_Virtual_Harddisk?oldid=82728#Overview]Overview[/url]
Copy as phpBB
Click below ↴ = Open social URL with share data
We don't use embedded scripts
This share button is completely self-hosted by this webserver. No scripts from any of the social networks are embedded on this webserver. See also
Social Share Button.
Note, when you created a big file or downloaded a big file, then delete it from the VM, the space will not be automatically freed up. Requires disk shrinking.
In essence, the following steps are required to shrink the disk.
1. Deleted files to free space.
2. Reboot your virtual machine in recovery mode.
3. Apply the zerofree
procedure.
4. Shut down.
5. Virtualizer specific command to release the freed space.
6. Done.
Steps[edit]
Copy or share this direct link!
Click = Copy
Copied to clipboard!
https://www.kicksecure.com/wiki/Shrink_Virtual_Harddisk?oldid=82728#Steps
Click below ↴ = Copy to Clipboard
Click = Copy
Copied to clipboard!
[[Shrink_Virtual_Harddisk#Steps|Steps]]
Copy as Wikitext
Click = Copy
Copied to clipboard!
[Steps](https://www.kicksecure.com/wiki/Shrink_Virtual_Harddisk?oldid=82728#Steps)
for Discourse, reddit, GitHub
Click = Copy
Copied to clipboard!
[Steps](https://www.kicksecure.com/wiki/Shrink_Virtual_Harddisk?oldid=82728#Steps)
Copy as Markdown
Click = Copy
Copied to clipboard!
[url=https://www.kicksecure.com/wiki/Shrink_Virtual_Harddisk?oldid=82728#Steps]Steps[/url]
Copy as phpBB
Click below ↴ = Open social URL with share data
We don't use embedded scripts
This share button is completely self-hosted by this webserver. No scripts from any of the social networks are embedded on this webserver. See also
Social Share Button.
VirtualBox
Copy or share this direct link!
Click = Copy
Copied to clipboard!
https://www.kicksecure.com/wiki/Shrink_Virtual_Harddisk?oldid=82728#VirtualBox
Click below ↴ = Copy to Clipboard
Click = Copy
Copied to clipboard!
[[Shrink_Virtual_Harddisk#VirtualBox|VirtualBox]]
Copy as Wikitext
Click = Copy
Copied to clipboard!
[VirtualBox](https://www.kicksecure.com/wiki/Shrink_Virtual_Harddisk?oldid=82728#VirtualBox)
for Discourse, reddit, GitHub
Click = Copy
Copied to clipboard!
[VirtualBox](https://www.kicksecure.com/wiki/Shrink_Virtual_Harddisk?oldid=82728#VirtualBox)
Copy as Markdown
Click = Copy
Copied to clipboard!
[url=https://www.kicksecure.com/wiki/Shrink_Virtual_Harddisk?oldid=82728#VirtualBox]VirtualBox[/url]
Copy as phpBB
Click below ↴ = Open social URL with share data
We don't use embedded scripts
This share button is completely self-hosted by this webserver. No scripts from any of the social networks are embedded on this webserver. See also
Social Share Button.
KVM
Copy or share this direct link!
Click = Copy
Copied to clipboard!
https://www.kicksecure.com/wiki/Shrink_Virtual_Harddisk?oldid=82728#KVM
Click below ↴ = Copy to Clipboard
Click = Copy
Copied to clipboard!
[[Shrink_Virtual_Harddisk#KVM|KVM]]
Copy as Wikitext
Click = Copy
Copied to clipboard!
[KVM](https://www.kicksecure.com/wiki/Shrink_Virtual_Harddisk?oldid=82728#KVM)
for Discourse, reddit, GitHub
Click = Copy
Copied to clipboard!
[KVM](https://www.kicksecure.com/wiki/Shrink_Virtual_Harddisk?oldid=82728#KVM)
Copy as Markdown
Click = Copy
Copied to clipboard!
[url=https://www.kicksecure.com/wiki/Shrink_Virtual_Harddisk?oldid=82728#KVM]KVM[/url]
Copy as phpBB
Click below ↴ = Open social URL with share data
We don't use embedded scripts
This share button is completely self-hosted by this webserver. No scripts from any of the social networks are embedded on this webserver. See also
Social Share Button.
A tool called zerofree free is needed to shrink the backing virtual disk file. Since the default are ext4 partitions, the process might be bit involved:
Inside the VM:
1. Install the package zerofree
in the virtual machine you want to shrink.
Install package(s) zerofree
following these instructions
1 Platform specific notice.
- Kicksecure: No special notice.
- Kicksecure-Qubes: In Template.
2 Update the package lists and upgrade the system.
Click = Copy Copied to clipboard! sudo apt update && sudo apt full-upgrade
3 Install the zerofree
package(s).
Using apt
command line --no-install-recommends
option is in most cases optional.
Click = Copy Copied to clipboard! sudo apt install --no-install-recommends zerofree
4 Platform specific notice.
- Kicksecure: No special notice.
- Kicksecure-Qubes: Shut down Template and restart App Qubes based on it as per Qubes Template Modification
.
5 Done.
The procedure of installing package(s) zerofree
is complete.
2. Erase what you need in the VM, run apt-get purge, apt-get autoremove, apt-get clean, etc. as needed.
3. Reboot your virtual machine in recovery mode.
4. At the command prompt, type Click = Copy Copied to clipboard! systemctl stop systemd-journald.socket && systemctl stop systemd-journald.service && mount -o remount,ro / && zerofree -v /dev/vda1 && shutdown now
5. Shut down the VM.
On the host:
6. Open a terminal on the host.
7. Switch to root.
Click = Copy Copied to clipboard! sudo -s
8. Change directory to the /var/lib/libvirt/images
folder.
Click = Copy Copied to clipboard! cd /var/lib/libvirt/images
9. View files inside the /var/lib/libvirt/images
folder.
Click = Copy Copied to clipboard! ls
10. Create a back up of the disk you want to shrink by moving YourVirtualMachineDisk.qcow2
to YourVirtualMachineDisk.qcow2.backup
.
Note:
- Replace
YourVirtualMachineDisk.qcow2
with the actual name of your virtual harddisk. - Replace
YourVirtualMachineDisk.qcow2.backup
with the actual name of your virtual harddisk.
Click = Copy Copied to clipboard! mv YourVirtualMachineDisk.qcow2 YourVirtualMachineDisk.qcow2.backup
11. Shrink the disk using qemu-img
.
Click = Copy Copied to clipboard! qemu-img convert -O qcow2 -p YourVirtualMachineDisk.qcow2.backup YourVirtualMachineDisk.qcow2
12. Boot up the VM and see if it is working. If it is, you can delete the backup of the qcow file.
There are ways you can get more creative with this using thin provisioned images that are based on a static qcow2 backing file, a preferred method. However the above is a basic method for getting a shrunken qcow2 disk file. [1]
forum discussion: https://forums.whonix.org/t/is-it-possible-to-re-shrink-the-qcow2-image-files/13228/9
Qubes
Copy or share this direct link!
Click = Copy
Copied to clipboard!
https://www.kicksecure.com/wiki/Shrink_Virtual_Harddisk?oldid=82728#Qubes
Click below ↴ = Copy to Clipboard
Click = Copy
Copied to clipboard!
[[Shrink_Virtual_Harddisk#Qubes|Qubes]]
Copy as Wikitext
Click = Copy
Copied to clipboard!
[Qubes](https://www.kicksecure.com/wiki/Shrink_Virtual_Harddisk?oldid=82728#Qubes)
for Discourse, reddit, GitHub
Click = Copy
Copied to clipboard!
[Qubes](https://www.kicksecure.com/wiki/Shrink_Virtual_Harddisk?oldid=82728#Qubes)
Copy as Markdown
Click = Copy
Copied to clipboard!
[url=https://www.kicksecure.com/wiki/Shrink_Virtual_Harddisk?oldid=82728#Qubes]Qubes[/url]
Copy as phpBB
Click below ↴ = Open social URL with share data
We don't use embedded scripts
This share button is completely self-hosted by this webserver. No scripts from any of the social networks are embedded on this webserver. See also
Social Share Button.
Undocumented. Unspecific to Kicksecure. Self Support First Policy applies.
Refer to the Qubes OS user documentation.
Forum discussion:
https://forums.whonix.org/t/the-workstation-vmdk-gets-bigger-and-bigger/218
Build from Source Code[edit]
Copy or share this direct link!
Click = Copy
Copied to clipboard!
https://www.kicksecure.com/wiki/Shrink_Virtual_Harddisk?oldid=82728#Build_from_Source_Code
Click below ↴ = Copy to Clipboard
Click = Copy
Copied to clipboard!
[[Shrink_Virtual_Harddisk#Build_from_Source_Code|Build from Source Code]]
Copy as Wikitext
Click = Copy
Copied to clipboard!
[Build from Source Code](https://www.kicksecure.com/wiki/Shrink_Virtual_Harddisk?oldid=82728#Build_from_Source_Code)
for Discourse, reddit, GitHub
Click = Copy
Copied to clipboard!
[Build from Source Code](https://www.kicksecure.com/wiki/Shrink_Virtual_Harddisk?oldid=82728#Build_from_Source_Code)
Copy as Markdown
Click = Copy
Copied to clipboard!
[url=https://www.kicksecure.com/wiki/Shrink_Virtual_Harddisk?oldid=82728#Build_from_Source_Code]Build from Source Code[/url]
Copy as phpBB
Click below ↴ = Open social URL with share data
We don't use embedded scripts
This share button is completely self-hosted by this webserver. No scripts from any of the social networks are embedded on this webserver. See also
Social Share Button.
Refer to Build and Update Kicksecure from Source Code and utilize this setting:
Click = Copy Copied to clipboard! --vmsize 50G
Future[edit]
Copy or share this direct link!
Click = Copy
Copied to clipboard!
https://www.kicksecure.com/wiki/Shrink_Virtual_Harddisk?oldid=82728#Future
Click below ↴ = Copy to Clipboard
Click = Copy
Copied to clipboard!
[[Shrink_Virtual_Harddisk#Future|Future]]
Copy as Wikitext
Click = Copy
Copied to clipboard!
[Future](https://www.kicksecure.com/wiki/Shrink_Virtual_Harddisk?oldid=82728#Future)
for Discourse, reddit, GitHub
Click = Copy
Copied to clipboard!
[Future](https://www.kicksecure.com/wiki/Shrink_Virtual_Harddisk?oldid=82728#Future)
Copy as Markdown
Click = Copy
Copied to clipboard!
[url=https://www.kicksecure.com/wiki/Shrink_Virtual_Harddisk?oldid=82728#Future]Future[/url]
Copy as phpBB
Click below ↴ = Open social URL with share data
We don't use embedded scripts
This share button is completely self-hosted by this webserver. No scripts from any of the social networks are embedded on this webserver. See also
Social Share Button.
Either,
- A) dracut module or
- B) mkosi-initrd systemd unit,
that runs zerofree before mounting the root disk would be useful. Such a feature does not exist yet in any Linux distribution.
See Also[edit]
Copy or share this direct link!
Click = Copy
Copied to clipboard!
https://www.kicksecure.com/wiki/Shrink_Virtual_Harddisk?oldid=82728#See_Also
Click below ↴ = Copy to Clipboard
Click = Copy
Copied to clipboard!
[[Shrink_Virtual_Harddisk#See_Also|See Also]]
Copy as Wikitext
Click = Copy
Copied to clipboard!
[See Also](https://www.kicksecure.com/wiki/Shrink_Virtual_Harddisk?oldid=82728#See_Also)
for Discourse, reddit, GitHub
Click = Copy
Copied to clipboard!
[See Also](https://www.kicksecure.com/wiki/Shrink_Virtual_Harddisk?oldid=82728#See_Also)
Copy as Markdown
Click = Copy
Copied to clipboard!
[url=https://www.kicksecure.com/wiki/Shrink_Virtual_Harddisk?oldid=82728#See_Also]See Also[/url]
Copy as phpBB
Click below ↴ = Open social URL with share data
We don't use embedded scripts
This share button is completely self-hosted by this webserver. No scripts from any of the social networks are embedded on this webserver. See also
Social Share Button.
Footnotes[edit]
Copy or share this direct link!
Click = Copy
Copied to clipboard!
https://www.kicksecure.com/wiki/Shrink_Virtual_Harddisk?oldid=82728#Footnotes
Click below ↴ = Copy to Clipboard
Click = Copy
Copied to clipboard!
[[Shrink_Virtual_Harddisk#Footnotes|Footnotes]]
Copy as Wikitext
Click = Copy
Copied to clipboard!
[Footnotes](https://www.kicksecure.com/wiki/Shrink_Virtual_Harddisk?oldid=82728#Footnotes)
for Discourse, reddit, GitHub
Click = Copy
Copied to clipboard!
[Footnotes](https://www.kicksecure.com/wiki/Shrink_Virtual_Harddisk?oldid=82728#Footnotes)
Copy as Markdown
Click = Copy
Copied to clipboard!
[url=https://www.kicksecure.com/wiki/Shrink_Virtual_Harddisk?oldid=82728#Footnotes]Footnotes[/url]
Copy as phpBB
Click below ↴ = Open social URL with share data
We don't use embedded scripts
This share button is completely self-hosted by this webserver. No scripts from any of the social networks are embedded on this webserver. See also
Social Share Button.
- ↑
Credit goes to forum user tempest
: https://forums.whonix.org/t/is-it-possible-to-re-shrink-the-qcow2-image-files/13228/3


Copy as Wikitext

for Discourse, reddit, GitHub

Copy as Markdown

Copy as phpBB Click below ↴ = Open social URL with share data











We believe security software like Kicksecure needs to remain Open Source and independent. Would you help sustain and grow the project? Learn more about our 12 year success story and maybe DONATE!