Setup Windows Subsystem Linux(WSL) in your windows laptop
Windows Subsystem for Linux (WSL) allows you to run a full Linux environment directly on Windows, without needing a separate virtual…
Setup Windows Subsystem Linux(WSL) in your windows laptop
Windows Subsystem for Linux (WSL) allows you to run a full Linux environment directly on Windows, without needing a separate virtual machine or dual-booting. It is primarily used by developers to run Linux command-line tools, Bash scripts, and Linux-specific applications seamlessly within a Windows workflow.
To begin with, download Ubuntu Pro for WSL from Microsoft Store.

Next, open your windows powershell. Type wsl below.

Professional WSL Troubleshooting Walkthrough
This section demonstrates what to do when typing wsl from PowerShell fails, which files and directories to inspect, the common WSL commands every developer should know, and how to exit WSL safely back to Windows PowerShell.
1. When Typing wsl Fails: PowerShell Commands and Expected Outputs
Suppose you open PowerShell and run:
wsl
Instead of entering Ubuntu, you may see errors such as:
wsl: Processing /etc/fstab with mount -a failed.
wsl: Failed to mount C:\, see dmesg for more details.
wsl: Failed to mount D:\, see dmesg for more details.
wsl: Failed to translate 'C:\Users\anirban'
wsl: Failed to translate 'C:\Windows\system32'
<3>WSL ERROR: getpwuid(0) failed 2
<3>WSL ERROR: execvpe(/bin/sh) failed: No such file or directory
This output suggests WSL is having startup issues. The failure could be caused by the wrong default distro, broken Windows drive mounts, bad /etc/fstab entries, or a missing Linux shell such as /bin/sh.
The first step is not to reinstall WSL. The first step is to inspect the installed distributions.
Step 1: List Installed WSL Distributions
Run this in PowerShell:
wsl -l -v
Expected output:
NAME STATE VERSION
* Ubuntu Stopped 2
Ubuntu-24.04 Stopped 2
Meaning:
ColumnMeaningNAMEWSL distribution nameSTATEWhether the distro is running or stoppedVERSIONWSL version, usually 1 or 2*The default distro launched when you type only wsl
If the broken distro has the * beside it, plain wsl will keep launching the broken distro.
Step 2: Launch the Correct Distro Explicitly
If your working distro is Ubuntu-24.04, run:
wsl -d Ubuntu-24.04
Expected successful output:
(base) anirban@LAPTOP-F3H8724S:/mnt/c/Users/anirban$
This means you are now inside WSL.
Explanation of the prompt:
Prompt PartMeaning(base)Conda base environment is activeanirbanLinux usernameLAPTOP-F3H8724SHost machine name/mnt/c/Users/anirbanCurrent directory inside mounted Windows C drive$Normal non-root Linux shell
If this works, then the problem may simply be that the wrong WSL distro is set as default.
Step 3: Set the Correct Default Distro
Back in PowerShell, run:
wsl --set-default Ubuntu-24.04
Expected output:
The operation completed successfully.
Then shut down all WSL instances:
wsl --shutdown
This command usually returns no output if successful.
Now test again:
wsl
Expected output:
(base) anirban@LAPTOP-F3H8724S:/mnt/c/Users/anirban$
At this point, typing only wsl should open Ubuntu-24.04.
Step 4: If Normal Startup Still Fails, Enter as Root
If this command fails:
wsl -d Ubuntu-24.04
try entering as root with Bash:
wsl -d Ubuntu-24.04 -u root --exec /bin/bash
Expected output:
root@LAPTOP-F3H8724S:/#
This means you entered the Linux environment as the root user.
If /bin/bash works, but normal startup fails, the issue may be with the default user, /bin/sh, /etc/passwd, /etc/fstab, or /etc/wsl.conf.
Step 5: Test Whether Basic Linux Binaries Exist
From PowerShell, you can directly execute Linux commands without opening an interactive shell.
Check the root filesystem:
wsl -d Ubuntu-24.04 -u root --exec /bin/ls /
Expected output:
bin boot dev etc home lib lib64 media mnt opt proc root run sbin tmp usr var
Check whether Bash exists:
wsl -d Ubuntu-24.04 -u root --exec /bin/ls -l /bin/bash
Expected output:
-rwxr-xr-x 1 root root 1396520 Mar 31 2024 /bin/bash
Check whether /bin/sh exists:
wsl -d Ubuntu-24.04 -u root --exec /bin/ls -l /bin/sh
Expected healthy output:
lrwxrwxrwx 1 root root 4 Mar 31 2024 /bin/sh -> dash
or:
lrwxrwxrwx 1 root root 4 Mar 31 2024 /bin/sh -> bash
Problem output:
/bin/ls: cannot access '/bin/sh': No such file or directory
If /bin/sh is missing but /bin/bash exists, you can repair it from inside WSL root mode:
ln -sf /bin/bash /bin/sh
Then restart WSL:
wsl --shutdown
wsl -d Ubuntu-24.04
2. Significant WSL Directories and Files to Check
When WSL fails to start, the following directories and files are important.
/etc/fstab
Command:
cat /etc/fstab
Purpose:
/etc/fstab controls filesystems mounted automatically at startup.
What to look out for:
C:\ /mnt/c drvfs defaults 0 0
D:\ /mnt/d drvfs defaults 0 0
In WSL, Windows drives are usually mounted automatically. Bad or unnecessary manual mount entries can cause startup errors.
If you see suspicious mount lines, edit the file:
sudo nano /etc/fstab
Comment out suspicious entries:
# C:\ /mnt/c drvfs defaults 0 0
# D:\ /mnt/d drvfs defaults 0 0
Then restart WSL:
wsl --shutdown
wsl -d Ubuntu-24.04
/etc/wsl.conf
Command:
cat /etc/wsl.conf
Purpose:
/etc/wsl.conf controls WSL-specific behavior such as default user, automounting, interop, and whether Windows PATH is appended.
Example healthy file:
[automount]
enabled = true
root = /mnt/
[interop]
enabled = true
appendWindowsPath = false
[user]
default = anirban
What to look out for:

If the default user is wrong, fix it:
sudo nano /etc/wsl.conf
Example:
[user]
default = anirban
Then restart WSL:
wsl --shutdown
wsl
/bin/sh
Command:
ls -l /bin/sh
Expected output:
lrwxrwxrwx 1 root root 4 Mar 31 2024 /bin/sh -> dash
Purpose:
/bin/sh is the default POSIX shell used by many Linux scripts and startup processes.
Problem:
ls: cannot access '/bin/sh': No such file or directory
Fix if Bash exists:
sudo ln -sf /bin/bash /bin/sh
Better Ubuntu-style fix if dash exists:
sudo ln -sf /bin/dash /bin/sh
Check dash:
ls -l /bin/dash
Expected output:
-rwxr-xr-x 1 root root 125688 Mar 31 2024 /bin/dash
/bin/bash
Command:
ls -l /bin/bash
Purpose:
Bash is the common interactive shell used in Ubuntu.
Expected output:
-rwxr-xr-x 1 root root 1396520 Mar 31 2024 /bin/bash
If /bin/bash is missing, the distro is seriously damaged. You should back up before attempting major repair.
/etc/passwd
Command:
cat /etc/passwd | head
Purpose:
/etc/passwd contains Linux user account records.
Expected output should include:
root:x:0:0:root:/root:/bin/bash
And for your user:
anirban:x:1000:1000:,,,:/home/anirban:/bin/bash
What to look out for:

/home/anirban
Command:
ls -ld /home/anirban
Expected output:
drwxr-x--- 20 anirban anirban 4096 Jun 1 20:00 /home/anirban
Purpose:
This is the Linux home directory. It is the recommended place to keep projects.
Good project structure:
cd ~
mkdir -p projects
cd projects
Recommended path:
/home/anirban/projects
Avoid doing heavy development inside:
/mnt/c/Users/anirban
because Windows-mounted paths are often slower and can create permission issues for Linux tools.
/mnt/c
Command:
ls /mnt/c
Expected output:
$Recycle.Bin Program Files Program Files (x86) Users Windows
Purpose:
/mnt/c is the mounted Windows C drive.
If this fails:
ls: cannot access '/mnt/c': No such file or directory
or:
Input/output error
then Windows drive mounting is broken.
Check WSL automount configuration:
cat /etc/wsl.conf
Look for:
[automount]
enabled = true
root = /mnt/
Then restart:
wsl --shutdown
wsl
/var/log
Command:
ls /var/log
Purpose:
Contains Linux logs. In WSL, not all traditional Linux logs behave exactly like a full server, but this directory can still contain useful diagnostic information.
Useful commands:
dmesg | tail -50
journalctl -xe
journalctl works only if systemd is enabled.
3. Common WSL Commands
These commands are useful from PowerShell.
List Installed Distros
wsl -l -v
Example output:
NAME STATE VERSION
* Ubuntu-24.04 Running 2
Start Default WSL Distro
wsl
Start a Specific Distro
wsl -d Ubuntu-24.04
Start a Specific Distro as Root
wsl -d Ubuntu-24.04 -u root
Run a Linux Command Directly from PowerShell
wsl -d Ubuntu-24.04 --exec uname -a
Example output:
Linux LAPTOP-F3H8724S 5.15.167.4-microsoft-standard-WSL2 x86_64 GNU/Linux
Check Current WSL Status
wsl --status
Example output:
Default Distribution: Ubuntu-24.04
Default Version: 2
Set Default WSL Distro
wsl --set-default Ubuntu-24.04
Set Default WSL Version
wsl --set-default-version 2
Expected output:
The operation completed successfully.
Shut Down All WSL Distros
wsl --shutdown
This stops all running WSL distributions.
Useful after changing:
/etc/wsl.conf- Windows PATH behavior
- Automount settings
- Default user
- Docker/WSL integration
- WSL memory settings
Terminate One Specific Distro
wsl --terminate Ubuntu-24.04
This stops only the selected distro.
Export a WSL Backup
mkdir C:\wsl-backup
wsl --export Ubuntu-24.04 C:\wsl-backup\Ubuntu-24.04-backup.tar
Use this before risky repairs.
Import a WSL Backup
wsl --import Ubuntu-24.04-Restored C:\WSL\Ubuntu-24.04-Restored C:\wsl-backup\Ubuntu-24.04-backup.tar --version 2
This creates a restored copy under a new distro name.
Unregister a Distro
wsl --unregister Ubuntu-24.04
Warning: this deletes the distro.
Only use this after backing up important files.
Update WSL
wsl --update
Check WSL Help
wsl --help
4. Useful Commands Inside WSL
Once inside Ubuntu, these commands are useful.
Check Current Directory
pwd
Example output:
/home/anirban
List Files
ls
Detailed listing:
ls -lah
Go to Linux Home Directory
cd ~
Go to Windows C Drive
cd /mnt/c
Go to Windows User Folder
cd /mnt/c/Users/anirban
Create a Project Folder
cd ~
mkdir -p projects
cd projects
Check Ubuntu Version
lsb_release -a
Example output:
Distributor ID: Ubuntu
Description: Ubuntu 24.04 LTS
Release: 24.04
Codename: noble
Check Linux Kernel
uname -a
Check Current User
whoami
Expected output:
anirban
Check Shell
echo $SHELL
Expected output:
/bin/bash
Check Conda Environment
conda info --envs
Example output:
# conda environments:
#
base * /home/anirban/anaconda3
pyakc /home/anirban/anaconda3/envs/pyakc
Check Python
which python
python --version
Example output:
/home/anirban/anaconda3/bin/python
Python 3.13.x
Check Windows Mount
ls /mnt/c
Expected output:
Program Files Program Files (x86) Users Windows
5. Logging Out from WSL and Returning to Windows Mode
When you are inside WSL, the prompt may look like this:
(base) anirban@LAPTOP-F3H8724S:/mnt/c/Users/anirban$
To exit WSL and return to Windows PowerShell, type:
exit
Expected result:
PS C:\Users\anirban>
You are now back in Windows PowerShell.
Alternative: Press Ctrl + D
Inside WSL, you can also press:
Ctrl + D
This sends an end-of-file signal and closes the shell session.
Expected result:
PS C:\Users\anirban>
Difference Between exit, wsl --terminate, and wsl --shutdown

Use exit for normal logout.
Use wsl --shutdown after changing WSL configuration files such as:
/etc/wsl.conf
/etc/fstab
6. Practical End-to-End Recovery Flow
Here is a clean professional workflow.
First, in PowerShell:
wsl
If it fails, inspect distros:
wsl -l -v
If Ubuntu-24.04 is the correct distro, launch it directly:
wsl -d Ubuntu-24.04
If successful, set it as default:
wsl --set-default Ubuntu-24.04
wsl --shutdown
wsl
If it still fails, enter as root:
wsl -d Ubuntu-24.04 -u root --exec /bin/bash
Then inspect important files:
ls -l /bin/sh
ls -l /bin/bash
cat /etc/fstab
cat /etc/wsl.conf
cat /etc/passwd | head
ls /mnt/c
If /bin/sh is missing but Bash exists:
ln -sf /bin/bash /bin/sh
If /etc/fstab has suspicious mount entries:
nano /etc/fstab
Comment them out:
# C:\ /mnt/c drvfs defaults 0 0
# D:\ /mnt/d drvfs defaults 0 0
Then restart from PowerShell:
wsl --shutdown
wsl -d Ubuntu-24.04
Before any destructive action, export a backup:
mkdir C:\wsl-backup
wsl --export Ubuntu-24.04 C:\wsl-backup\Ubuntu-24.04-backup.tar
Only after backup should you consider unregistering or reinstalling a distro.
7. Key Takeaways
When wsl fails, do not immediately reinstall Ubuntu.
First check:
wsl -l -v
Then try:
wsl -d Ubuntu-24.04
The failure may simply be caused by the wrong default distro.
The most important Linux files to inspect are:
/etc/fstab
/etc/wsl.conf
/etc/passwd
/bin/sh
/bin/bash
The most important Windows-side commands are:
wsl -l -v
wsl -d Ubuntu-24.04
wsl --set-default Ubuntu-24.04
wsl --shutdown
wsl --export
To leave WSL and return to Windows PowerShell:
exit
A calm, structured debugging approach is better than panic reinstalling. WSL errors often look intimidating, but the root cause is usually discoverable from the first few lines of the error message.
메타데이터
- post_id
- ae2ff80a4977
- slug
- setup-windows-subsystem-linux-wsl-in-your-windows-laptop-ae2ff80a4977
- url
- https://medium.com/anirbans-lenses/setup-windows-subsystem-linux-wsl-in-your-windows-laptop-ae2ff80a4977
- canonical_url
- https://medium.com/anirbans-lenses/setup-windows-subsystem-linux-wsl-in-your-windows-laptop-ae2ff80a4977
- author_url
- https://medium.com/@anirban-karchaudhuri
- status
- ok
- fetched_at
- 2026-06-09 15:37:30