49

How much disk space is WSL using on Windows?

I found that you can go into Windows' Apps & Features and it will display disk usage for the WSL2 "Ubuntu", but this does not seem to include WSL Legacy or maybe it does since it seems to report more than I expect?

CTS_AE
  • 1,361

4 Answers4

56

Determine Disk Usage From Linux

Using a tool like ncdu can make determining disk usage easy with a nice cli interface to it as well.

Install ncdu

sudo apt install ncdu  

Running ncdu

So we do not get all of Windows' directories along for the ride we'll need to exclude the /mnt directory.

sudo ncdu / --exclude /mnt

Determining From Windows

Under Windows' Apps & Features it lists Ubuntu as taking up 1.92 GB

ncdu reports 1.7 GiB (~1.82GB) which is pretty close to what Windows reports.

WSL Legacy "Bash on Ubuntu on Linux"

I was not able to find how much room Bash on Ubuntu on Linux was occupying through Windows, but I was able to see how much it was using by running sudo ncdu / --exclude /mnt.

Related Research

CTS_AE
  • 1,361
10

The answer(s) to this question will, of course, always be changing as WSL and its distributions are updated.

It's also very difficult to measure the exact disk space utilized by any given Windows feature since Windows is constantly consuming and releasing disk space for other purposes as well. That said, here are some measurements done on Windows 11 today:

Short form:

  • The WSL feature and kernel take between 100-200MB of space.
  • An Ubuntu distribution takes, at a minimum 1.1GB, but will quickly expand on first update/upgrade to around 2.7GB.
  • An additional ~400MB are consumed by the installed rootfs tarball, which can be recovered.

Note:

These measurements were done with the released version of WSL on Windows 11.

WSL is now available in Preview form from the Microsoft Store, and this version, when installed will consume more disk space since the features are not built into Windows. I have not yet measured the Store/Preview version of WSL.

Also, these measurements were taken with a WSL2 distribution. The initial size consumed by a WSL1 distribution will be greater than that of WSL2, however, WSL1 will release space back as files are deleted (unlike WSL2).

Details:

  • A fresh install of Windows 11 + Updates, before WSL installation, consumed 35,584,876,544 bytes of disk space.

  • After enabling the WSL feature and rebooting, 35,587,739,648 bytes were consumed. A decrease of around 2,863,104 (2.8MB). This is expected, since the feature is built in to Windows and is just "enabled" (not necessarily installed).

    Note that, at this stage, WSL1 is installed and could be used with a distribution.

  • Enabling the Virtual Machine Platform to enable WSL2 consumed an additional 23,044,096 bytes. However, rebooting actually reclaimed 14,274,560 of this, for a net change of 8,769,536. Again, this smaller number is likely due to the fact that the feature ships with Windows, and is just being enabled.

  • After downloading the 16.1MB WSL2 kernel package and rebooting, a whopping additional 568,856,576 was consumed. This number should be taken with a big caveat, in that Edge was launched for the first time in order to download the package. It's almost certain that most of the additional consumed disk space was from Edge features being activated for the first time and other side-effects.

    The kernel itself, installed, takes up 73,476,524 bytes.

  • Installing Ubuntu 20.04 with wsl --install -d Ubuntu is certainly the biggest consumer of disk space. After installing and rebooting, an additional 1,648,529,408 (1.6GB) was used.

    There are two main parts to this. The first is the "App" itself. This includes the rootfs tarball that gets installed. It is stored in the C:\Program Files\ directory that is normally off-limited to your normal user. You can inspect the WSL tarball sizes, however, with a simple PowerShell one-liner run in an Administrative session:

    Get-ChildItem -Recurse 'C:\Program Files\WindowsApps\' | Where-Object {$_.Name -eq 'install.tar.gz' } 
    

    This shows that the tarball is 452,534,052 bytes. Technically, this could be recovered by removing the App, but be warned -- Removing the app also removes the distribution. It's possible to decouple it (through a wsl --export/--import), though, and then remove the "App"/tarball.

    The other part is the actual distribution itself, which under WSL2 can be seen in the size of the ext4.vhdx virtual HDD. Before running any commands, the size of the vhdx was 1,173,397,504.

    After a sudo apt update && sudo apt upgrade -y, the size of the distribution grew to 2,701,131,776 (around 2.7GB). Note that a df showed it to be 1,513,688k. The large change in the vhdx size is likely due to the fact that the virtual disk can grow as needed, but does not release space as files are removed from it. See this question for details.

  • Update for Ubuntu 22.04: The base vhdx size is 1.49GB. However, since it was just released today, it already includes up-to-date packages. As such, an initial sudo apt update && sudo apt upgrade -y did not consume any additional space.

    Compared to Ubuntu 20.04, that's an overall savings of around 1.2GB. Again, this will likely change as we progress through Ubuntu 22.04's lifecycle.

NotTheDr01ds
  • 28,025
3

@CTS_AE's answer was quite helpful. ncdu is an excellent tool for visualizing disk usages of folders. However, ncdu --exclude /mnt did not work for me. ncdu / --exclude /mnt did.

I tested it on Debian (WSL2), and ncdu --version showed ncdu 1.15.1.

1c982d
  • 149
1

Here is the answer, even if now (windows 11) is not that accurate (I see no "canonical" in path): https://askubuntu.com/questions/1363015/understanding-disk-space-using-wsl2

The answer is in windows go here: %userprofile%\AppData\Local\Packages
then search for your distro, and when you find it right click on it an go proprieties, it will count for you.

And as I commented above, there is a HUGE difference between what df/du/ncdu says and reality, for example my fresh installed kali, du says it use 0.9G but windows file explorer says 1.7G

THESorcerer
  • 163
  • 1
  • 11