https://rancher.com/ logo
e

early-shoe-8160

09/08/2022, 2:12 AM
Hello everyone I just have a quick question, I've tried to delete unused images via rancher desktop UI but after that, I noticed that I still haven't reclaimed disk space for it. But when I reset all my rancher configs, I get the free space back. Any thoughts?
f

fast-garage-66093

09/08/2022, 4:03 AM
There is no way to reclaim the disk space on the host side, but if you delete images, then that space will be re-used when you fetch or create additional images.
The data volume of the VM is essentially a sparse file, that is 100GB in size, but only the used blocks are allocated. But once you write to any block, the disk space on the host filesystem is committed, and there is no way free that again, except by deleting the file and creating a new sparse file.
Is there a way to specify disk size for VM on Mac M1? · Issue #1521 · rancher-sandbox/rancher-desktop shows a workaround to modify the max size of the data volume (at the time of creation). You could use this to specify a smaller size, so you get an "out of space" error on the data volume instead of it growing to 100GB.
e

early-shoe-8160

09/08/2022, 4:11 AM
Thanks @fast-garage-66093 btw I am on Windows 10.. And I only noticed that the space got freeup when I reset factory the rancher desktop. I am thinking if there is other way to do that by not reset factory?
f

fast-garage-66093

09/08/2022, 5:35 AM
Unfortunately there is no other way right now. Well, besides making sure to regularly prune old/unused image before the volume grows too much. But there is no other way to reclaim the disk space once the volume has grown; you have to make space available to be reused to prevent additional space from being allocated.
👍 1
e

early-shoe-8160

09/08/2022, 6:03 AM
w

wide-mechanic-33041

09/08/2022, 12:26 PM
One method for pro/ultimate level windows is the optimize-vhd cmdlet in powershell. make sure that Rancher is shutdown and target the ~\Appdata\Local\rancher-desktop\distro-data\ext4.vhdx
in Home you can shrink them using diskpart, but just takes a bit more work
e

early-shoe-8160

09/09/2022, 12:58 AM
Yup sadly I'm on enterprise so not applicable. Thanks still Justin
f

fast-garage-66093

09/09/2022, 1:00 AM
Enterprise edition should include
optimize-vhd
as well (it is a Hyper-V tool), so you should have it
👍 1
e

early-shoe-8160

09/09/2022, 1:03 AM
I already tried it but its not being recognize with my powershell.. Or do I miss something?
f

fast-garage-66093

09/09/2022, 1:04 AM
I just found How to Shrink a WSL2 Virtual Disk – Stephen's Thoughts. I obviously haven't tried it, and don't know if it is save, but you may want to give it a read
e

early-shoe-8160

09/09/2022, 1:06 AM
Yup I also tried that article but didnt work. Maybe for now, I don't have any option but to do factory reset just to free up space
f

fast-garage-66093

09/09/2022, 1:08 AM
So what happened when you tried the approach in the article? Did you get an error, or did it just not shrink the file? Are you sure you have significant empty space on the volume by deleting images first?
e

early-shoe-8160

09/09/2022, 1:09 AM
No error it says 100% completed after compact vdisk but when I checked my drive for my WSL distro (Ubuntu 20.04) it didnt shrinked
f

fast-garage-66093

09/09/2022, 1:10 AM
Did you check the free space on the host disk itself?
e

early-shoe-8160

09/09/2022, 1:10 AM
Yes nothing changed
f

fast-garage-66093

09/09/2022, 1:11 AM
Too bad. It sounded promising as several commenters confirmed that the procedure worked for them too.
e

early-shoe-8160

09/09/2022, 1:11 AM
Yeah anyway thanks for helping me @fast-garage-66093
Hopefully soon Racher Desktop will have that feature that will automatically remove tangled/unused images
f

fast-garage-66093

09/09/2022, 1:13 AM
You mean like running
docker image prune
or
docker image prune -a
on a schedule?
I don't think we would add that; this seems to be something best left to the user. What I would like to figure out would be install the data volume initially with a smaller maximum size, so you get an out-of-disk-space error when creating more images instead of filling up the host disk,
👍 1
Did you run
wsl --shutdown
again after
compact
? Or maybe even reboot?
e

early-shoe-8160

09/09/2022, 1:20 AM
Yup I run shutdown first before doing other steps
f

fast-garage-66093

09/09/2022, 1:21 AM
I would still try to reboot once, if you haven't done so, just to see if it makes a difference. The old space may still be kept allocated by some process/service in memory. It's grasping a straws, but there seems little else left to do...
e

early-shoe-8160

09/09/2022, 1:22 AM
Ahh you mean reboot.. yes I've done that as well but nothing happens
f

fast-garage-66093

09/09/2022, 1:23 AM
Another thing to try: Run
sudo fstrim /
inside the
rancher-desktop
distro after deleting images, but before running
diskpart
or
compact
.
👍 1
Hmm, not sure if we include
fstrim
in the Alpine distro; let me do some checks
It doesn't work for me on macOS; will check on Windows
It does not throw an error on Windows:
wsl -d rancher-desktop fstrim /
You may need to run
wsl -d rancher-desktop fstrim /var/lib
instead
Because that is the mount point on which the data volume is mounted, and where the images are stored
I have to drop now; but please let us know if you got things working!
e

early-shoe-8160

09/09/2022, 1:32 AM
Ok I will try that again. Thanks @fast-garage-66093 🙂
f

fast-garage-66093

09/09/2022, 4:35 AM
I suspect you didn't shutdown wsl before running the
compact
w

wide-mechanic-33041

09/09/2022, 12:57 PM
yup close RD so that distro is not running or just wsl --shutdown to down them all. And you may need to check if you just have the Hyper-V feature enabled or only Windows Hypervisor Platform. I would imagine that cmdlet will need the Hyper-V “management” parts in addition to the core platform feature that WSL2 depends on.
1071 Views