-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow reclaiming unused storage space from guest hard disk #3460
Comments
a possible method that doesn't take up the space to shrink the image is with (ssd) trimming/discards, provided the drives has the options to shrink the image on discards (by default, it doesn't). this method depends on the OS to trim the free space, triggered manually or automatically. example.mp4(editing existing auto-generated qemu arguments isn't a feature and i'd really like that (still advanced but useful in some cases)) for making it smaller by converting with qemu-img, expand my previous comment below for my concerns of such. comment i previously wrote with other concernsthis is a nice feature to have. i just have a concern: systems don't actually zero out the deleted files, and qemu-img removes at most, the consecutive null bytes that's actually being occupying disk space and within the disk image. let's say, a disk image of 64 gb: 30 gb used, 20 gb free but has written data (i.e. space was used but now deleted files live there), and the rest of the 14gb was never used. the image size could be around 52gb. the user presses the button to free up space, but gets about 2gb back. the user could compare the free space in the vm and the disk image, and then report an issue that not all free space is removed (which for what i know, can be resolved by zeroing out the free space under the vm and then going through qemu-img again). another concern is disk space. what if the user doesn't have enough disk space? then they can't "delete" the unused free space. |
That sounds like a much better idea. |
Yeah, I agree. As long as we can reclaim the space back, I dont mind which method works best for us. When I had VMware, I used to run Sdelete on Windows 10 before shutting down and hitting the button to reclaim the disk space. It did work for me back then. Using the SDelete utility you can securely delete files and wipe free space in Windows 10 to prevent any sensitive data from falling into the wrong hands. Despite SDelete does not have a graphical user interface, it is still easy for anyone to use. https://docs.microsoft.com/en-us/sysinternals/downloads/sdelete |
@JacksonChen666 the source says "First of all, you’ll want to switch the drives from VirtIO to SCSI and use the VirtIO SCSI adapter (which supports TRIM since quite some time, while the blk driver only recently learned about it)." But it was written a year ago. Can you confirm that it works without VirtIO SCSI for you? |
@osy I am very confident that I did not use any other devices other than the auto-generated arguments (v3.0.1-beta) that I removed and then re-added manually so I can modify the arguments. But if I'm wrong, I might be not aware of that. So I will provide the arguments I modified and used for the drive:
The above was from the QEMU command export (of the vm I just created like 20 minutes ago, still works). QEMU command export (not modified form)
Modified QEMU command export (enables discards)
I've also noticed that actually, the options doesn't make it actually un-allocate the space that's used, but make it into sparse space ( |
@osy I can confirm that using |
As a data point, I've gone another route, and use Using -c during initial disk creation by default is not a good idea though, as you immediately lose any potential for machine snapshots. I'd be interested to find out if it's compatible with discard=unmap though, to avoid having to zero-out freespace in the guest. |
I posted the following on this discussion and @conath suggested me to add it as a feature request:
VMware provides this as a way to reclaim disk space: https://www.askdavetaylor.com/vmware-fusion-is-eating-up-my-hard-drive-help/
UTM could do a similar thing with qemu-img and qcow2 images. Say you have a machine and specified it to have a max 64GB. And you are currently using 34GB of 64GB. Now, what if you install a program (like an Adobe Creative Cloud suite, for example) and it eats up more 6GB, adding up to 40GB of usage, but you regret it and uninstall the whole suite, but you are left with a 40GB qcow2 image instead of 34GB, and unused 6GB? You might want that space back.
VMware deals with it by adding a "Clean Up Virtual Machine" which reclaims the unused 6GB disk space.
I usually deal with it using a command line with qemu-img:
qemu-img convert -O qcow2 win11.qcow2 win11_small.qcow2
then I deletewin11.qcow2
, and finally I rename thewin11_small.qcow2
towin11.qcow2
This process does shrink the image from 40GB to 34GB (or maybe even more, depending of your mileage and disk usage).
Basically you would need to do some kind of script to automatize this process and add a button to the machine configuration to do that, just like how VMware does. The process does take some considerable time to finish (depending of your machine image size), so you might need to add a pop-up screen asking the user to wait until the process is finished (VMware does the same for its Linux machines).
The text was updated successfully, but these errors were encountered: