Skip to content

Instantly share code, notes, and snippets.

@shakahl
Last active March 26, 2024 22:43
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save shakahl/8b6c969768b3a54506c0fc4905d729a0 to your computer and use it in GitHub Desktop.
Save shakahl/8b6c969768b3a54506c0fc4905d729a0 to your computer and use it in GitHub Desktop.
How to seamlessly integrate Windows Subsystem for Linux (WSL) with Windows

How to seamlessly integrate Windows Subsystem for Linux (WSL) with Windows

Installation

Install an Ubuntu version from Microsoft Store.

Please check out the Windows 10 Installation Guide written by Microsoft itself.

Configuring to handle file permissions correctly on windows

By default the file permissions are incorrectly handled when modifying a Windows file from WSL.

Solution: Mount windows partitions with metadata mount option.

The WSL can do this by default with correct configuration.

Create /etc/wsl.conf with the following content.

[automount]

enabled = true
root = /mnt/
options = "uid=1000,gid=1000,umask=22,fmask=11,metadata"
mountFsTab = true
 
[network]

generateHosts = true
generateResolvConf = true
 
[interop]

enabled = true
appendWindowsPath = true

Set correct permissions.

sudo chmod 0644 /etc/wsl.conf

Now restart the shell.

exit

In windows CMD, type:

bash.exe

Now you are in WSL again.

After that you should check out if it works.

$ mount -l
rootfs on / type lxfs (rw,noatime)
none on /dev type tmpfs (rw,noatime,mode=755)
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,noatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,noatime)
devpts on /dev/pts type devpts (rw,nosuid,noexec,noatime,gid=5,mode=620)
none on /run type tmpfs (rw,nosuid,noexec,noatime,mode=755)
none on /run/lock type tmpfs (rw,nosuid,nodev,noexec,noatime)
none on /run/shm type tmpfs (rw,nosuid,nodev,noatime)
none on /run/user type tmpfs (rw,nosuid,nodev,noexec,noatime,mode=755)
binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,noatime)
C: on /mnt/c type drvfs (rw,noatime,uid=1000,gid=1000,umask=22,fmask=11,metadata,case=off)

Az utolsó sorban a "C:" sorában szerepelnie kell a "metadata" opciónak.

Using windows Pageant in WSL

Related project: weasel-pageant

Download the binary archive weasel-pageant-1.1.zip and extract it somewhere like C:/weasel-pageant/weasel-pageant.

Run the following under WSL:

chmod +x /mnt/c/weasel-pageant/weasel-pageant

Add the following to your .bashrc

eval $(/mnt/c/weasel-pageant/weasel-pageant -r)

Disable SUDO password

Run in WSL.

sudo echo "$USER ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/$USER
sudo chmod 0644 /etc/sudoers.d/$USER

Now you can run sudo without typing the password.

Links

License

MIT


Free Software, Hell Yeah!

[automount]
enabled = true
root = /mnt/
options = "uid=1000,gid=1000,umask=22,fmask=11,metadata"
mountFsTab = true
[network]
generateHosts = true
generateResolvConf = true
[interop]
enabled = true
appendWindowsPath = true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment