Understanding the Permission Error
The specific error code 5 in Linux terminology typically signifies a "Permission Denied" issue. When you attempt to start Kali Linux via the Windows Terminal or the Start Menu, the WSL backend tries to change its working directory to /mnt/c/Windows/System32. If the underlying virtual machine instance has become corrupted, or if file locks from previous crashes remain active, the process fails to gain the necessary read/write permissions.
This often happens after an abrupt shutdown of Windows 11, a failed update, or when multiple WSL distributions are running simultaneously. The WSL driver may leave zombie processes that hold exclusive locks on the disk images associated with your Kali installation. Consequently, any new attempt to launch the distribution hits a wall of restricted access, resulting in the failure message you are seeing.
Step-by-Step Solution: Unregister and Reinstall
While updating WSL via wsl --update is a good maintenance habit, it rarely fixes corruption within a specific distribution's root filesystem. The primary fix involves resetting the Kali Linux instance entirely. Follow these steps carefully to ensure a clean slate.
1. Stop All WSL Instances
Before making changes, you must ensure no background processes are holding locks on the Kali files. Open PowerShell or Command Prompt as Administrator and run:
wsl --shutdown
This command gracefully stops all running distributions and unloads the WSL virtual machine. Wait ten seconds to ensure all handles are released. You can verify this by checking Task Manager for any lingering vmmem or WslService.exe processes related to Kali.
2. List Your Installed Distributions
Identify the exact name of your Kali instance. Run the following command:
wsl -l -v
Note the name listed under the "NAME" column. It is usually Kali or kali-linux. Ensure you have the correct identifier before proceeding, as unregistering will delete the local state of that distribution.
3. Unregister the Broken Instance
Remove the corrupted configuration and file system metadata. Replace <Kali_Name> with the actual name found in the previous step:
wsl --unregister <Kali_Name>
This action does not delete your personal data stored in cloud backups or external drives, but it removes the local virtual hard disk associated with the Kali installation. This is safe because we will immediately reinstall the fresh image.
4. Reinstall Kali Linux
Now, install a fresh copy of Kali Linux. You can do this through the Microsoft Store or via the command line. For a quick command-line reinstallation, use:
wsl --install -d Kali-linux
If you prefer the Microsoft Store, search for "Kali Linux" and click Install. After the installation completes, launch Kali from the Start Menu. It should now initialize without the chdir error, prompting you to create a new UNIX user account.
Preventing Future Lock Conflicts
To avoid encountering this error again, consider adjusting how you interact with WSL on Windows 11. Always shut down WSL properly when you are done using it, rather than just closing the terminal window. You can automate this by adding wsl --shutdown to your Windows login script or using a scheduled task.
Additionally, ensure that your antivirus software is not scanning the %LOCALAPPDATA%\WSL directory in real-time. Antivirus scans can sometimes lock files during write operations, leading to similar permission errors. Excluding the WSL data directory from real-time protection significantly improves stability.
If you are experiencing issues with other subsystems, such as Docker Desktop failing with invalid command line options, you might find relevant troubleshooting tips in our guide on Unable to run Docker Desktop: Invalid command line option --mount.
Frequently Asked Questions
Will unregistering Kali Linux delete my existing data?
Yes, unregistering removes the local virtual disk image containing your files, scripts, and installed packages. However, if you had previously exported your data or synced it with a remote repository, that data remains safe. Always back up important files before unregistering.
Why does this error happen specifically on Windows 11?
Windows 11 uses a newer version of the WSL2 architecture with stricter security boundaries. If the system updates while WSL is running, or if fast startup leaves kernel drivers in a suspended state, permission locks can persist across reboots, triggering this specific chdir failure.
Can I fix this without reinstalling Kali?
In rare cases, simply restarting the WslSvc service in Windows Services might release the lock. However, this is temporary and unreliable. If the root filesystem is corrupted, uninstalling and reinstalling is the only guaranteed fix.
How do I check if WSL is fully updated?
You can check the current version by running wsl --version in PowerShell. To ensure you have the latest kernel and components, run wsl --update. Keeping WSL updated helps prevent compatibility issues with newer Windows builds.
What if the reinstall also fails with the same error?
If the fresh install fails, the issue likely lies with the WSL host environment rather than the Kali distribution itself. Check for pending Windows Updates, ensure Hyper-V is enabled, and verify that your BIOS settings allow for virtualization extensions (VT-x/AMD-V).