WSL2 Samba Installation / Windows 10 Environment
1. Installation Background
WSL2 VMs have a problem where I/O performance does not appear for directories under /mnt shared with Windows OS. This document summarizes a method to work around this issue by installing and using a Samba Server inside the WSL2 VM.
2. Installation Environment
The installation and configuration environment is as follows.
- Windows 10 Pro 64bit
- WSL2 Ubuntu 20.04, root User
3. Samba Server Installation on Ubuntu
(WSL2 Ubuntu)$ apt update
(WSL2 Ubuntu)$ apt install samba
(WSL2 Ubuntu)$ smbpasswd -a root
New SMB password:
Retype new SMB password:
Added user root.Install the Samba Server inside the WSL2 VM and add a root user for the Samba Server.
| |
Add the content from [File 1] to the /etc/samba/smb.conf file.
(WSL2 Ubuntu)# service smbd restartRestart the Samba Server.
4. Add Port Forwarding Rule to WSL2 VM
WSL2 VM IP changes every time it reboots. Therefore, configure a Port Forwarding Rule on Windows OS so that when a Samba connection occurs to localhost, the connection is forwarded to the WSL2 VM.
wsl -d ubuntu -u root service smbd restart
wsl -d ubuntu -u root ip addr add 192.168.10.100/24 broadcast 192.168.10.255 dev eth0 label eth0:1
netsh interface ip add address "vEthernet (WSL)" 192.168.10.50 255.255.255.0Create the script from [File 2]. The script makes connections to 192.168.10.100 connect to the Samba Server.
5. Register Script as Startup Script
(Windows)$ $trigger= New-JobTrigger -AtStartup -RandomDelay 00:00:15
(Windows)$ Register-ScheduledJob -Trigger $trigger -FilePath C:\route_ssh_to_wsl.ps1 -Name RouteSSHtoWSL6. Samba Server Access
After rebooting Windows OS, access the following address from File Browser.
- \\192.168.10.100\root