Skip to content(if available)orjump to list(if available)

How to free up and automatically manage disk space for WSL

Dylan16807

I think Optimize-VHD will do the same thing as messing with diskpart.

It's a shame you can't just turn on live TRIM support.

This kind of disk image is a bunch of multi-megabyte blocks of data, plus a list of where each block goes on the virtual disk. Implementations can support TRIM by deleting the block that's zeroed and moving the block at the end of the file into that spot. VirtualBox can do this, shrinking the file when the guest OS TRIMs, but Hyper-V can't.

wtallis

It seems like just using a sparse file would make things simpler. I guess there would be potential inefficiency when you try to move the VM to another drive, but for just storing and using the VM in place it doesn't seem like this has to be hard: a TRIM inside the VM gets translated into a hole punch in the disk image file, which gets translated into a TRIM sent to the underlying storage.

Dylan16807

Sparse files would be useful but I'm pretty sure sparse files on NTFS always reserve their full size. Eating 1TB of free space for my ext4.vhdx is a non-starter.

banana_giraffe

https://gist.github.com/Q726kbXuN/c80028aa1714032546d3b442c1...

Nope, they don't eat up space. One of the fun side effects of sparse files on NTFS is calling WriteFile on the sparse file can lead to an ERROR_DISK_QUOTA_EXCEEDED error, which applications tend to not expect.

wtallis

Based on https://learn.microsoft.com/en-us/windows/win32/fileio/spars... and subsequent links, it sounds like sparse files count against disk quotas as if they weren't sparse, but otherwise sparse files actually work on NTFS.

If sparse files didn't save on actual space allocations, it would simply be a lie to call them sparse files. Granted, that's totally something Microsoft would do, and has done for other features they lack, but that doesn't seem to be the case here.

vrighter

and the vhdx format already allows for this too. You can mark a block as "present, but zeroed out" (contents of never accessed blocks is undefined). These types of blocks don't have an actual block of data in the file, but still have well defined semantics.

Eridrus

Someone should really make a utility to make this easy if Microsoft won't do it.

rr808

I'm done with WSL. It just makes life too hard, dual disk is a problem, two network endpoints two firewalls, two different hypervisors you can choose from where some things expect one some the other.

I used to think a windows laptop would be better for hardware management, maybe it is but I just gave up and installed Linux. My life is so much easier.

ycombinatrix

WSL is really convenient for a lot of use cases though. Much better than dual booting on a machine used primarily for gaming.

mikepurvis

I’m also doing WSL-centric development and I’m not even really gaming on that machine, I just appreciate the comforts that come with competent multi monitor support and reliable wake from sleep.

My biggest frustration with WSL at present is that 1Password won’t properly support proxying their ssh agent into it. (Though in googling it again just now, I see a suggestion to try something called npiperelay, so I’ll spend some time seeing again if I can get that working)

ycombinatrix

You can actually run the windows ssh.exe binary directly from WSL, no extra setup needed. Give it a try.

olivermuty

No such thing needez, just alias ssh to ssh.exe and ssh-add to ssh-add.exe and it works out of the box.

mrheosuper

i'm the opposite of you, i'm so done with Linux on my laptop. I can't count how many time my machine cooks itself inside my bag when using Linux. Windows also has the same problem, but much less frequently.

Now if i want linux, WSL2, and if i want linux graphic, Vmware or something similar

rogerrogerr

Wish there was a good option in corporate environments where I can’t just install Linux.

rafaelmn

Ask for a Mac ? At this point enough manager were sold on it that most places have to support MacOS, and its popular enough with devs to also have to support dev environments on it.

Like even if you prefer Linux, Mac is a huge step up over windows and WSL if those were your only options.

Also latest Mac machines aren't even that overpriced as they were before their in-house CPUs, for the performance you get really there is only one PC chip out there right now that can be compared and that chip is available in like 2 laptops.

rr808

At work I asked for a remote server and my pc is just a terminal to use ssh & xwindows.

mystifyingpoi

I also considered this, but I was not able to solve the security problems. That remote server must (or not?) hold all my SSH keys, AWS creds, and other stuff, to even be useful. Secops guys would kill me for this. Until then, WSL is good enough.

pxc

I have something like that at work for testing Windows things, since my work machine is a Mac.

It's pretty miserable in terms of latency and window management. If you can get this to work well with NX or X forwarding, that's cool, but it's a second class offering when that's your only option.

bpbp-mango

what distro did you go with

rtcode_io

"Skills issue"