Dev Note: Tips of developing with WSL
Dev Note: Tips of developing with WSL
Questions
- Ubuntu running under Windows Subsystem for Linux (WSL) popped up error about inefficient memory in virtual disk
- I have to expand the memory of virtual disk
Source: How to manage WSL disk space | Microsoft Learn
Procedure
-
Open Windows Command Prompt with admin privileges and then open the diskpart command
1
diskpart
-
Wait for diskpart awake, using
Select vdiskto specify the path to disk, but most of the time, the path to VHD (Virtual Hard Disk) is unknown, so I have to use other prompt to find it.- I found the resolution as following source: How to manage WSL disk space | Microsoft Learn
Command Prompt 1
(Get-ChildItem -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss | Where-Object { $_.GetValue("DistributionName") -eq 'distribution-name'
- However, what is
distribution name? -> preciously, it means the name of distro of Linux OS under your subsystem, such as Ubuntu, Arch Linux, et al. So I use following code to find out the name of my distro:
Command Prompt 1
wsl -l -v
Outputs are following:
1
2NAME STATE VERSION
* Ubuntu-22.04 Stopped 2- It is
Ubuntu-22.04. After I replaced it into'distribution-name', got the path.
1
(Get-ChildItem -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss | Where-Object { $_.GetValue("DistributionName") -eq 'Ubuntu-22.04'
Outputs are following:
1
C:\Users\LI\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu22.04LTS_79rhkp1fndgsc\LocalState\ext4.vhdx
- Finally, I could use the prompt to select the virtual disk as:
1
Select vdisk file = "C:\Users\LI\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu22.04LTS_79rhkp1fndgsc\LocalState\ext4.vhdx"
-
Check the detail of virtual disk with prompt:
1
detail vdisk
Got infos as outputs:
1
2
3
4
5
6
7
8Vendor ID: {00000000-0000-0000-0000-000000000000} (Unknown)
State: Added
Virtual size: 256 GB
Physical size: 240 GB
Filename: C:\Users\LI\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu22.04LTS_79rhkp1fndgsc\LocalState\ext4.vhdx
Is Child: No
Parent Filename:
Associated disk#: Not found.→ Well, 256 GB is not enough, I have already used 95% of them.
-
Expand the size of the virtual disk and exit with the following prompts:
Notes: the units of the disk size is MB, so I enlarged the size of virtual disk 100% of the original1
expand vdisk maximum=512000
1
exit
-
Not the end. I have to let the subsystem recognize the renewed disk size, after opened the wsl and activate Ubuntu, prompt:
1
sudo mount -t devtmpfs none /dev mount | grep ext4
and, with
resize2fs(specify the correct path:/dev/sdcas my case, and don’t forget the unit symbol M)1
sudo resize2fs /dev/sdc 512000M
-
Check if it works, with
df:
![[Pasted image 20230713142250.png]]
⇾ Congratulation.
#### SOLVED ####
Keywords:
#dev_note #wsl #linux #virtual_disk
