Some notes on using Windows Subsystem for Linux

Created: 2019-12-30   Updated: 2020-10-19   Category: windows   Print this pageBack to Home


This post contains some notes on using Windows Subsystem for Linux.

File permissions in WSL

Here, we describe how to handle file permission in Windows Subsystem for Linux. It was originally from here.

Windows Subsystem for Linux (WSL) usually mounts Windows drives under /mnt. However, the Linux file permission seems to be awful. To fix this issue, simply add to /etc/wsl.conf (if the file does not exist, simply create it):

enabled = true
options = "metadata,umask=22,fmask=11"

In short, every files now have permission 0644 and every directories have permission 0755.

Also, add the following to ~/.profile to fix the permission of newly created files and directories.

if [[ "$(umask)" = "0000" ]]; then
	umask 0022

Export and import WSL Distros

  • Export: Let say I want to export my Arch WSL Distro which I downloaded from this page and customized for my personal use (it was pretty much like what I did in my real Arch system). The following command, executed in cmd, will compress the distro into a single file %userprofile%\Desktop\ArchWSL.tar. (The %userprofile% directory is C:\Users\[your-username].)

    wsl --export Arch %userprofile%\Desktop\ArchWSL.tar

    Additionally, as the size of my ArchWSL.tar is too big (around 8GB), I decided to compress it with 7-Zip using the following command

    "C:\Program Files\7-Zip\7z.exe" a -tzip %userprofile%\Desktop\ -m0=LZMA -mx=9 %userprofile%\Desktop\ArchWSL.tar

    Basically, the above command will create an archive in the folder %userprofile%\Desktop with “ultra” compression (option -mx=9, the highest compression level used by 7-Zip) using the LZMA compression method (option -m0=LZMA), which is the default and general compression method of 7z format. Use the -sdel option if you want to delete %userprofile%\Desktop\ArchWSL.tar after compression (Be careful!). If you want to protect the archive with a password, use the option -p[your-password] (there is no space between -p and your password).

  • Import: To import back the exported distro, in case we compressed ArchWSL.tar with 7-Zip before, we first need to extract, say, to the %userprofile%\Desktop folder.

    "C:\Program Files\7-Zip\7z.exe" x -o%userprofile%\Desktop

    If the archive is password-protected, the program will ask you to enter the password you used at the time it was created. Now, we can import back the distro by running in cmd the following command:

    wsl --import Arch %localappdata%\Packages\yuk7.archwsl_35zwpb4sx6e50\LocalState %userprofile%\Desktop\ArchWSL.tar

Copy contents of a file to clipboard

clip.exe < file.txt # do not miss the .exe part

Valid CSS! Valid HTML 4.01 Transitional Back to top
Powered by Jekyll
The content on this site is shared under a CC BY-SA 4.0 license, unless otherwise noted Last Modified: October 19, 2020