I have been working with DDEV and enjoying myself. One annoying issue is the mounted drive becoming read-only associated with my WSL Ubuntu installation. I believe it's related to my company laptop going into sleep/hibernation and causing havoc with Docker that is running inside of Ubuntu and inside of WSL— I know, there are too many layers of virtualization. Unfortunately, it's a necessary evil at this moment.
I threw together a Powershell script that does most of my work. I created a new script named reset-ubuntu.ps1 and added this code.
wsl.exe --shutdown
wsl.exe --set-default kali-linux
$ext4_volume = (Get-ChildItem -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss | Where-Object { $_.GetValue("DistributionName") -eq 'Ubuntu' }).GetValue("BasePath") + "\ext4.vhdx"
wsl.exe --mount $ext4_volume --vhd --bare
wsl.exe sudo e2fsck -fy /dev/sdc
wsl.exe sudo fsck -fy /dev/sdc
wsl.exe --unmount
wsl --set-default ubuntu
Make sure you are in Powershell by running powershell
, then run the script by running .\reset-ubuntu.ps1
Feel free to edit it to work with your own environment. The script assumes you have the broken Ubuntu instance named "ubuntu" and that you also have an instance of Kali Linux installed and called "kali-linux."
If you want to know more, here are some resources that explain the underlying issue and how to correct it.
- https://learn.microsoft.com/en-us/windows/wsl/disk-space#read-only-fallback-error
- https://learn.microsoft.com/en-us/windows/wsl/disk-space#how-to-locate-the-vhdx-file-and-disk-path-for-your-linux-distribution
Comments