Skip to content

Instantly share code, notes, and snippets.

View mcdaqc's full-sized avatar
:octocat:
Focusing

David Quispe mcdaqc

:octocat:
Focusing
View GitHub Profile
@mcdaqc
mcdaqc / gist:563c7a92af8da9d911b4f358858d8504
Last active July 7, 2025 10:46
Shrink WSL2 and Docker Virtual Disks to Reclaim Disk Space

Shrink WSL2 and Docker Virtual Disks to Reclaim Disk Space

Over time, WSL2 distributions and Docker images can consume significant disk space. Even after deleting files, the allocated virtual disk (VHDX) does not automatically shrink. This guide explains how to manually reclaim disk space by optimizing the virtual disk.

Shrinking WSL2 Virtual Disks

Locate the VHDX File

On Windows 11, WSL2 distributions store their virtual disks in the following location:

var cover = document.createElement("div");
let css = `
position: fixed;
pointer-events: none;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
background-color: white;
mix-blend-mode: difference;
@jjmartres
jjmartres / how-to-shrink-a-wsl2-virtual-disk.md
Last active April 14, 2025 18:15
How to Shrink a WSL2 Virtual Disk

How to Shrink a WSL2 Virtual Disk

Before you begin

Before shrinking a WSL2 virtual disk, you need to ensure that WSL2 is not running.

You can check if it’s running with the command wsl.exe --list --verbose in PowerShell:

PS C:\Users\valorin> wsl.exe --list --verbose
 NAME STATE VERSION