CodeRef
CodeRef
  • Software
    • VSCode
  • Midjourney_AI
    • Midjourney Cheat Sheet
  • aws
    • S3 Reference
    • Services
  • bash
    • .bashrc File Contents
    • CAN
    • _System Config File Locations
    • argument-length-limits
    • Conditionals
    • Data Structures
    • File Permissions
    • File Syncing
    • File System
    • Functions
    • General
    • Loops
    • My Functions
    • Networking
    • Number Operations
    • OpenVPN
    • Operators
    • Resource Management
    • Serial RS232
    • Spinning Wheel Animation
    • SSH
    • Text Operations
    • Environment Variables
  • cpp
    • ChatGPT | Pointers vs. References
    • arrays
    • Classes
    • Data Types / Structures
    • Enumerated Classes
    • Exception Handling
    • Function Objects
    • Functions
    • I/O
    • Loops
    • Macros
    • Namespaces
    • New Features
    • Pointers
    • Scope
    • Smart Pointers
    • Raw String Literals
    • Style Guide
    • Switch Case
    • Templating
    • How to Use tinyxml2
    • Useful Libraries
    • google-test
    • Conditionals
    • Rule of Three/Five
    • Optional Parameters
    • Keywords
    • Filesystem
    • Random
    • Casting
    • tools
  • git
    • Code Review Dependency Strategy
    • Git Bisect Guide
    • Git Reference
    • removing-cherry-picks
    • Useful Tools
    • Graphite Reference
  • js
    • functions
    • Javascript Reference
  • linux
    • Display
    • Dual Boot with Windows
    • File System
    • NVIDIA
    • Sending/Receiving TCP/UDP Messages in Ubuntu
    • dynamically_linked_binaries
  • markdown
    • Images
    • obsidian-reference
  • python
    • Classes
    • Exceptions
    • Functions
    • Operations
    • Python Reference
    • unittest_command-line-args
    • unittest_magicmock_GPT
    • unittest_mock
    • unittest_printing
    • unittest_subtest
    • useful-stuff
    • jupyter
    • poetry
  • ros
    • _ROS Cheat Sheet
    • Create New Workspace
    • Install ROS
    • Node Sample - Listener
    • Node Sample - Talker
    • Node Template
    • Setup
    • urdf
  • excel
    • excel-reference
  • windows
    • File System
    • WSL - Windows Subsystem for Linux
    • WSL
  • software_engineering
    • uncle_bob_lectures
      • Overview
      • Lesson 01 - Notes
  • web
    • Front End
    • Hugo
    • new_frontend_tools
  • sql
    • cheatsheet
Powered by GitBook
On this page
  • Shrink Virtual Disk
  • Option 1
  • Option 2
  • Set Maximum Size of Virtual Disk
  1. windows

WSL

Last updated 4 months ago

Shrink Virtual Disk

Option 1

Reclaims unused space. Does not change maximum virtual disk size. Disk can automatically expand again in the future, so you have to do this periodically when you delete large files.

wsl --shutdown
wsl -l -v    # Make sure all VMs are stopped
diskpart
Select vdisk file="<pathToVHD>"
detail vdisk
compact vdisk    # Reclaims unused space

The path for a WSL vdisk is usually:

"C:\Users\user.name\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu22.04LTS_79rhkp1fndgsc\LocalState\ext4.vhdx"

(replace with appropriate linux distro name and ID)

TIP: If the compact vdisk command seems to be hung up for a long time with no progress (ex. at 12%), hit Enter.

Option 2

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-All

Let it reboot.

Resize-VHD -Path "<path-to-vhd>" -ToMinimumSize
# or
Optimize-VHD -Path "<path-to-vhd>" -Mode Full

Set Maximum Size of Virtual Disk

Default is 1TB (1024 GB), so this is only relevant if you want to set the MAX size larger than 1TB.

The MAX size is the "Virtual Size" when you run the following in diskpart:

detail vdisk

https://stephenreescarter.net/how-to-shrink-a-wsl2-virtual-disk/
https://learn.microsoft.com/en-us/windows/wsl/disk-space