This post contains some notes on using Windows Subsystem for Linux.
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
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):
[automount] enabled = true options = "metadata,umask=22,fmask=11"
In short, every files now have permission
0644 and every directories have permission
Also, add the following to
~/.profile to fix the permission of newly created files and directories.
if [[ "$(umask)" = "0000" ]]; then umask 0022 fi
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% directory is
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\ArchWSL.tar.zip -m0=LZMA -mx=9 %userprofile%\Desktop\ArchWSL.tar
Basically, the above command will create an archive
ArchWSL.tar.zip 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
7-Zip before, we first need to extract
ArchWSL.tar.zip, say, to the
"C:\Program Files\7-Zip\7z.exe" x ArchWSL.tar.zip -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
clip.exe < file.txt # do not miss the .exe part