Skip to content
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

WSL2: VHD Size Limited to 256GB #4373

Open
iankoulski opened this issue Aug 2, 2019 · 21 comments
Open

WSL2: VHD Size Limited to 256GB #4373

iankoulski opened this issue Aug 2, 2019 · 21 comments
Labels
feature wsl2 Issue/feature applies to WSL 2

Comments

@iankoulski
Copy link

The VHD used by WSL2 is created with max size of 256 GB (as described here: https://docs.microsoft.com/en-us/windows/wsl/wsl2-ux-changes#understanding-wsl-2-uses-a-vhd-and-what-to-do-if-you-reach-its-max-size)
When the max size is reached, increasing the VHD size further requires a series of steps as described in the same document.
There are cases when users know that they would need more than 256GB when they are enabling WSL2 and it would be good if they are given an opportunity to make a choice about the max size of their VHD if their preference is different than the default. This should be achievable via an optional command line argument. It would also be great if the max size of the VHD could be controllable via API. Then an engine like Docker for Windows could manage the amount of storage available to run containers without need for a user to go through several manual steps to resize their VHD.

@therealkenc
Copy link
Collaborator

There are cases when users know that they would need more than 256GB

Any real example of that use case?

Tempting to post a Slashdot meme from late 1990s (canonical use case for needing that much disk space) which most the crowd here probably doesn't remember.

But a (more contemporaneously appropriate) dev scenario? Hmm. 400GB is recommended for an Android build, or so I gather.

@craigloewen-msft craigloewen-msft added feature wsl2 Issue/feature applies to WSL 2 labels Aug 7, 2019
@jpflueger
Copy link

Stumbled on this and wanted to post my particular use case. My company makes robots, everyone here is on Windows 10 and our primary target is UWP so Windows 10 is a hard requirement for us. A few of us at our company also work on OS builds for the robot, I'm currently trying to see if I can run an OpenEmbedded build (to see if we can ditch UWP for dotnet core) but ran into the size limitation when I wanted to adjust the kernel. I used LxRunOffline to move WSL 2.0 onto a second SSD in my laptop that has 500 GB of storage. While I may have a use case for this, it does seem like as long as there are instructions on how to resize the VHD, having a single command to resize would help me but I would use it so infrequently that having it as a feature would be extremely low priority for my particular use case.

@toulouse
Copy link

Compiling two versions of Android with ccache can easily exceed 256GB

@mldxtj-cyc
Copy link

Here is the real user instance. I'm Xiaomi software engineer. A whole smartphone software code can be more than 150GB easily, sometime I need download several projects and compile them.
I suggest that, when install WSL, provide users a option to decide how much size to use.

@therealkenc
Copy link
Collaborator

provide users a option to decide how much size to use.

wsl.exe could use a --resize-vhd. That's really the ask here. You can do it yourself now manually, it is just a little more typing.

@fungiboletus
Copy link

How can you reduce the size ? I don't want to have so much space wasted with old data.

@onomatopellan
Copy link

@fungiboletus Same as any other vhdx.
https://stephenreescarter.net/how-to-shrink-a-wsl2-virtual-disk/

@HyperN00B
Copy link

I agree, users need an option to increase their WSL2 disk size. I myself compile 2 different Android custom ROMS and even 1 can exceed 300gb, not to mention the presence of ccache. So i want to expand it to 700gb, but i just can't, please Microsoft do something with this, I'm using Windows Insider Beta version, is there a wsl option in beta version to do such thing?

@HyperN00B
Copy link

Maybe include LVM so partitions can be resized on-the-go

@onomatopellan
Copy link

onomatopellan commented Apr 25, 2021

@bencetari It's not easy but it's possible to expand the vhdx to 700Gb. Follow these steps:
https://docs.microsoft.com/en-us/windows/wsl/vhd-size

@pmualaba
Copy link

the docs did not work for me: Got the following error:
$ sudo resize2fs /dev/sdc 900000M
resize2fs 1.45.5 (07-Jan-2020)
The containing partition (or device) is only 67108864 (4k) blocks.
You requested a new size of 230400000 blocks.

Anyone experienced the same? Or found a solution?

@a5af
Copy link

a5af commented Nov 17, 2021

@pmualaba I saw the same error when I tried resizing the wrong device. Try

mount | grep ext4

Make sure /dev/sdc is the device you want to resize.

@agilous
Copy link

agilous commented Jan 19, 2022

@bencetari It's not easy but it's possible to expand the vhdx to 700Gb. Follow these steps: https://docs.microsoft.com/en-us/windows/wsl/compare-versions#expanding-the-size-of-your-wsl-2-virtual-hard-disk

Facing the same issue but sadly this URL returns a 404. Trying this: https://docs.microsoft.com/en-us/windows/wsl/vhd-size

@zheng95z
Copy link

the docs did not work for me: Got the following error: $ sudo resize2fs /dev/sdc 900000M resize2fs 1.45.5 (07-Jan-2020) The containing partition (or device) is only 67108864 (4k) blocks. You requested a new size of 230400000 blocks.

Anyone experienced the same? Or found a solution?

Be sure to completely restart your wsl.

@sjwsl
Copy link

sjwsl commented Jul 7, 2022

the docs did not work for me: Got the following error: $ sudo resize2fs /dev/sdc 900000M resize2fs 1.45.5 (07-Jan-2020) The containing partition (or device) is only 67108864 (4k) blocks. You requested a new size of 230400000 blocks.

Anyone experienced the same? Or found a solution?

I got the same error. Solved by runnning wsl --shutdown again after exiting diskpart.

@madscientist42
Copy link

Sigh...

None of the suggested work-arounds work on a WSL2 setup with latest from the store on a WinX machine with 21h2 updates on it (Locked by client administrative control to this...can't upgrade...and if that's your answer, it'll be another LEGIT, "Windows is Crap" observation...) At least I can mount ext4 volumes via WSL2 now...that was missing prior to the upgrade. (Niiice...)

It won't let me resize past the default max size here. So, what gives? We're now in Jan of 2023 with this problem being a problem with NO help from Microsoft.

So, when the documentation doesn't describe the needed...what do you do? Switch to a VM framework that while it uses the Hyper-X backend, works like it's supposed to and then run docker atop that?

@beevik
Copy link

beevik commented Jan 16, 2023

To resize an ext4 partition within an existing wsl distribution, you need to do 2 things:

  1. Resize the virtual hard disk (vhdx) used by the distribution. This is described on this page. This will grow the maximum size for the distribution's root linux partition, but it will not actually increase the allocated size of the root partition within the container.
  2. Resize the root partition within the wsl container using resize2fs.

Unfortunately, you cannot perform step 2 while the root partition is mounted. So you'll have to do it by attaching the virtual hard disk to another distribution and resizing it there.

To resize my Ubuntu distribution's root partition size, I grew the virtual hard disk to 1TB using step 1 above. Then I performed the following steps:

  1. If you are running any services that depend on WSL2 (e.g., Docker Desktop), shut them down. Otherwise the device names shown in later steps may be different on your system.
  2. Find the Ubuntu distribution's vhdx file location using this Powershell command: (Get-ChildItem -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss | Where-Object { $_.GetValue("DistributionName") -eq 'Ubuntu' }).GetValue("BasePath") + "\ext4.vhdx"
  3. PLEASE BACK UP THIS VHDX FILE BEFORE RUNNING THE REST OF THESE STEPS. You could destroy your Ubuntu root partition if you make an error.
  4. Shut down wsl: wsl --shutdown
  5. Install the wsl Debian distribution using wsl --install Debian.
  6. After completing the Debian install, exit and terminate it: wsl --terminate Debian
  7. Attach (but don't mount) the Ubuntu virtual disk to all distributions using this command: wsl --mount --bare --vhd "<path from step 2>"
  8. Run the Debian wsl distribution: wsl -d Debian
  9. The Ubuntu root partition should be attached as /dev/sdd.
  10. Run e2fsck on the Ubuntu partition: sudo e2fsck -f /dev/sdd
  11. Resize the Ubuntu root partition to 1TB: sudo resize2fs /dev/sdd 1024000M
  12. Exit Debian.
  13. At the Windows powershell prompt, detach the Ubuntu virtual disk from all other distributions: wsl --unmount
  14. Shut down wsl again, just to clean everythiing up: wsl --shutdown

At this point you can start the Ubuntu distribution, and its root partition should be 1TB.

@madscientist42
Copy link

madscientist42 commented Jan 16, 2023 via email

@qtfkwk
Copy link

qtfkwk commented Jul 13, 2023

This is still an issue... I have a crashing Debian WSL2 due to the VHD "virtual size" being 1024 GB by default on a system with just 256 GB disk (!). Great job setting the default virtual size guys. 🙄

I have precisely the opposite problem: I want to reduce the virtual size in order to keep it from growing so large that it fills my C: drive.

Some ideas:

  • Clean/remove /tmp/* on wsl -t Distro / wsl --shutdown?
  • Seems diskpart can easily increase the maximum / virtual size, but where's the ability to decrease it?
  • Or better yet how about calculating it automatically to an actually sane number?

Seems currently the only solution is to back up my files, delete the WSL (wsl --unregister Debian), reinstall it fresh (wsl --install Debian), use it until it fills up again, repeat. Pretty sad state.

@fmillion-mnsu
Copy link

fmillion-mnsu commented Aug 22, 2023

Yes, WSL2 really does need the ability to specify the size of the vhdx file when a new distro is created. There's no good reason to enforce a hard-coded size. The fact that it went from 256GB to 1TB shows it can be changed. It just needs to be exposed to the UI via the wsl.exe command. For example: wsl.exe --install Debian --root-size 128G

I have been able to successfully shrink the vhdx file by using resize2fs first and then making a new vhdx and copying the data at the block level. But not only is this horribly inefficient (it could be scripted to some degree but it's far from ideal) but it also won't persist, and it's useless for situations like Docker Desktop which entirely self-manages the WSL instances. You can do the same with Docker Desktop but even a new Docker version might cause the distro to be rebuilt and your resized vhdx to be trashed.

I suppose a sort-of kind-of workaround might be just that - using resize2fs but then not resizing the vhdx. It'll be a larger block device on Linux but no data would ever be written outside the ext4 filesystem's bounds anyway.

If Microsoft would at least open source the userspace components and scripts of WSL, perhaps the community could implement this...

@J4CKVVH173
Copy link

@beevik your guide is best

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature wsl2 Issue/feature applies to WSL 2
Projects
None yet
Development

No branches or pull requests