Free up space (effortlessly) on WSL2

https://news.ycombinator.com/rss Hits: 4
Summary

Windows Subsystem for Linux (WSL) lets you run a Linux environment directly on Windows. This is particularly useful for web development where you can develop and test applications in a Linux environment without leaving Windows. You can even run freeCodeCamp locally with it! But managing disk space can be a quite a challenge, as WSL uses virtual hard disks that do not automatically free up unused space. This tutorial will guide you through the process of manually compacting your WSL virtual hard disks. We’ll automate this task using a PowerShell script, ensuring that your WSL environment remains efficient and clutter-free. Reclaim Your Space WSL uses a virtualization platform to install Linux distributions on your Windows system. Each distribution you add gets its own Virtual Hard Disk (VHD), which uses the ext4 file system (common in Linux). It’s saved on your Windows drive as an ext4.vhdx file. Key issues here: Inefficient storage: by default, VHD files do not reclaim unused space. This means that when you delete a file in WSL, the associated disk space isn’t immediately freed up. Disk space consumption: due to that inefficient storage, the VHD files can grow large thanks to that accumulated data, especially if you’re a WSL heavy user. Need for maintenance: you may not know that you need to compact your VHD files in order to reclaim disk space. If you notice that your free disk space is shrinking even after deleting files and apps, WSL might be the reason. This tutorial will help you keep your WSL and Windows environment running smoothly. Table of Contents Part 1: How to Manually Compact Your Virtual Hard Disk Let's start by going through the process manually. This section will guide you through checking your WSL version and associated Linux distributions, finding VHD files, shutting down WSL, and compacting the virtual disk. Prerequisites Windows 10 (20H1/2004+) or Windows 11 with WSL2 installed The PowerShell or Command Prompt running as Administrator (from the W...

First seen: 2025-08-19 03:48

Last seen: 2025-08-19 06:49