User Tools

Site Tools


other:win10wsl

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
other:win10wsl [2020/01/20 17:55]
jypeter [Mounting disks and network drives]
other:win10wsl [2020/02/20 11:23]
jypeter [Linux version installed] '18.04.4' after latest update
Line 1: Line 1:
-====== Windows Subsystem for Linux, and Ubuntu ======+====== Windows Subsystem for Linux (WSL), and Ubuntu ======
  
-<note warning>​What is described on this page was tested with **WSL v1**, and not WSL2 (WSL2 will be available for testing mid-2019, and maybe available for actual use in 2020). It should be possible to install both WSL v1 and v2 on the same computer and WSL v2 will theoretically have faster I/O, but we recommend you use WSL v1 for now</​note>​+<note warning>​What is described on this page was tested with **WSL v1**, and not WSL 2 ([[https://​docs.microsoft.com/​en-us/​windows/​wsl/​wsl2-index|WSL 2]] will be available for testing mid-2019 ​through the //Windows Insider Program//, and maybe available for actual use in 2020). 
 + 
 +It should be possible to install both WSL v1 and v2 on the same computer and WSL v2 will theoretically have faster I/O, but **we recommend you use WSL v1 for now**</​note>​
  
 Read just the top of the [[https://​docs.microsoft.com/​en-us/​windows/​wsl/​about|Windows Subsystem for Linux Documentation]] for a quick **WSL** description on the Microsoft site Read just the top of the [[https://​docs.microsoft.com/​en-us/​windows/​wsl/​about|Windows Subsystem for Linux Documentation]] for a quick **WSL** description on the Microsoft site
  
-In a few words, WSL is not Linux, it's more a way to [[https://​blogs.msdn.microsoft.com/​wsl/​2016/​06/​15/​wsl-file-system-support/​|share files between Windows and Linux]] (it's OK to skip this rather technical link!). That's why you need //WSL **and** a Linux distribution//​.+In a few words, WSL is not Linux, it's more a way to [[https://​blogs.msdn.microsoft.com/​wsl/​2016/​06/​15/​wsl-file-system-support/​|share files between Windows and Linux]] (it's OK to skip this rather technical link!). [[https://​docs.microsoft.com/​en-us/​windows/​wsl/​faq#​are-files-in-the-linux-drive-different-from-the-mounted-windows-drive|Files under the Linux root (i.e. /) are controlled by WSL which mimics Linux specific behavior [...follow the link for details...]]]. That's why you need //to activate ​WSL **and then install ​a Linux distribution**//.
  
 ===== Prerequisites ===== ===== Prerequisites =====
Line 15: Line 17:
       * Note: there is sometimes a delay between the official release and the time when Windows Update will actually tell you that a major update is available for **your** computer (e.g. the //September YY09// update may become available for you only in December)       * Note: there is sometimes a delay between the official release and the time when Windows Update will actually tell you that a major update is available for **your** computer (e.g. the //September YY09// update may become available for you only in December)
   * //Enough// space on ''​C:​\''​. Microsoft instructions say //The Windows Subsystem for Linux only runs on your system drive (usually this is your C: drive)//   * //Enough// space on ''​C:​\''​. Microsoft instructions say //The Windows Subsystem for Linux only runs on your system drive (usually this is your C: drive)//
-    * The initial installation of Ubuntu ​does not //seem// to use much disk space (< 1 Gb), but you will get a basic Linux with no graphics, ​and you will probably ​need space for installing more applications+    * Exporting a //​simple// ​Ubuntu ​configuration (after doing everything from //Base installation// to //Advanced configuration//​ below) with the [[other:​win10wsl#​creating_a_backup_of_the_linux_running_in_wsl|wsl --export]] command generated a 2.7 Gb tar file (uncompressed), so it's probably good to **start ​with at least 3 Gb of free space on ''​C:​\''​** (and you always ​need to keep enough free space on ''​C:​\'' ​for regular Windows operation)
     * The Linux ''/''​ and ''/​home''​ partitions will always be on ''​C:'',​ but the data files can be on any Windows disk/​partition (or external drive) of the computer     * The Linux ''/''​ and ''/​home''​ partitions will always be on ''​C:'',​ but the data files can be on any Windows disk/​partition (or external drive) of the computer
       * the Windows partitions will be available and accessible in ''/​mnt/'',​ so you can store data on other partitions (e.g. the content of the Windows ''​D:​\''​ partition will be available in ''/​mnt/​d''​ in Linux)       * the Windows partitions will be available and accessible in ''/​mnt/'',​ so you can store data on other partitions (e.g. the content of the Windows ''​D:​\''​ partition will be available in ''/​mnt/​d''​ in Linux)
Line 21: Line 23:
       * Checking the properties of ''​C:​\Users\<​your_login>''​ will **not** report an accurate size and number of files, because lots of files and directories are hidden! On the test laptop, the reported size of the user backed up directory (with [[other:​win10apps#​syncbackfree|SyncBackFree]]) was ~20 Gb (user data, WSL+Ubuntu, custom install of the CDAT 8.1 python distribution)       * Checking the properties of ''​C:​\Users\<​your_login>''​ will **not** report an accurate size and number of files, because lots of files and directories are hidden! On the test laptop, the reported size of the user backed up directory (with [[other:​win10apps#​syncbackfree|SyncBackFree]]) was ~20 Gb (user data, WSL+Ubuntu, custom install of the CDAT 8.1 python distribution)
       * Be sure to monitor the remaining free space on ''​C:''​!       * Be sure to monitor the remaining free space on ''​C:''​!
 +  * Note: it seems that [[other:​win10wsl#​restoring_a_wsl_backup|wsl --import]] can restore a backed-up Linux to a user specified location. Maybe this can be used for moving Ubuntu...
  
 ===== Base installation ===== ===== Base installation =====
Line 28: Line 31:
   * Follow **closely** the steps listed in [[https://​docs.microsoft.com/​en-us/​windows/​wsl/​install-win10|WSL Windows 10 Installation Guide]]. <wrap hi>Open this [[https://​docs.microsoft.com/​en-us/​windows/​wsl/​install-win10|WSL Windows 10 Installation Guide]] in another window, so that you can **read the useful hints below at the same time!**</​wrap>​   * Follow **closely** the steps listed in [[https://​docs.microsoft.com/​en-us/​windows/​wsl/​install-win10|WSL Windows 10 Installation Guide]]. <wrap hi>Open this [[https://​docs.microsoft.com/​en-us/​windows/​wsl/​install-win10|WSL Windows 10 Installation Guide]] in another window, so that you can **read the useful hints below at the same time!**</​wrap>​
     * When you have to //Open PowerShell as Administrator//,​ go to ''​Start''​=>''​W''​=>''​Windows PowerShell''​ then right-clik on ''​Windows PowerShell''​ and select //Run as Administrator//​     * When you have to //Open PowerShell as Administrator//,​ go to ''​Start''​=>''​W''​=>''​Windows PowerShell''​ then right-clik on ''​Windows PowerShell''​ and select //Run as Administrator//​
 +    * FIXME At this stage, we could try to restore/​clone a previously installed/​customized/​backed-up version of Ubuntu if we have one (see [[other:​win10wsl#​restoring_a_wsl_backup|Restoring a WSL backup]])
     * In the //Install your Linux Distribution of Choice//, we will use the very easy //install from the Microsoft Store// option     * In the //Install your Linux Distribution of Choice//, we will use the very easy //install from the Microsoft Store// option
       * Open the **Microsoft Store** with: ''​Start''​=>''​Microsoft Store''​       * Open the **Microsoft Store** with: ''​Start''​=>''​Microsoft Store''​
Line 124: Line 128:
 === Linux files seen from Windows === === Linux files seen from Windows ===
  
-The content of the Ubuntu ​''/'' ​directory is actually located ​in the following ​//hidden// sub-directory of the user'​s ​Windows //home// directory''​C:\Users\<​your_login>​\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs''​+  * You can access ​the Linux files in ''/'' ​from Windows by opening the //virtual// ''​\\wsl$''​ path in the Windows explorer (since [[https://docs.microsoft.com/​en-us/​windows/wsl/release-notes#​build-18342|Windows ​build 18342]]) 
 +    * Your Linux //home// directory ​is located in ''​\\wsl$\Ubuntu\home\<​your_login>​''​
  
-<note important>​[[https:​//blogs.msdn.microsoft.com/commandline/2016/11/17/do-not-change-linux-files-using-windows-apps-and-tools/|Do not change Linux files in '/' ​from Windows!]]+  * The content of the Ubuntu ''​/''​ directory is actually located in the following ​//hidden// sub-directory of the user's Windows ​//home// directory: ''​C:​\Users\<​your_login>​\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs'​'
  
-If you need to update files from both Linux and Windows, put them in a regular Windows directory (not in the hidden directory mentioned above, where the Linux system is installed)</​note>​+<note important>​[[https://​blogs.msdn.microsoft.com/​commandline/​2016/​11/​17/​do-not-change-linux-files-using-windows-apps-and-tools/​|Do not change Linux files in '/'​ from Windows!]] (it's safe **only** if you use the ''​\\wsl$''​ path) 
 + 
 +If you need to easily ​update files from both Linux and Windows, put them in a regular Windows directory (not in the hidden directory mentioned above, where the Linux system is installed)</​note>​
  
 === Windows files seen from Linux === === Windows files seen from Linux ===
 +
 +Note: When you are in an explorer window, you can open a Windows terminal with Linux by holding Shift and right-clicking on a directory and choosing Linux in the context menu.
  
 The Windows partitions are mounted under ''/​mnt''​ in Linux: The Windows partitions are mounted under ''/​mnt''​ in Linux:
Line 152: Line 161:
 ==== Linux version installed ==== ==== Linux version installed ====
  
-<​code>​$ lsb_release -a+<​code>​$ date 
 +Thu Feb 20 11:18:57 CET 2020 
 + 
 +$ lsb_release -a
 No LSB modules are available. No LSB modules are available.
 Distributor ID: Ubuntu Distributor ID: Ubuntu
-Description: ​   Ubuntu 18.04.LTS+Description: ​   Ubuntu 18.04.LTS
 Release: ​       18.04 Release: ​       18.04
 Codename: ​      ​bionic Codename: ​      ​bionic
Line 412: Line 424:
 == Authorizing ssh to use old dsa keys == == Authorizing ssh to use old dsa keys ==
  
-//dsa// ssh keys are disabled by default (becoming obsolete). ''​ssh''​ will ask for your password even if you have a ''​~/​.ssh/​id_dsa''​ file. ''​ssh -v''​ will print ''​Skipping ssh-dss key /​home/<​your_login>/​.ssh/​id_dsa - not in PubkeyAcceptedKeyTypes''​. The solution is to use the user config file to authorize dsa ([[https://​unix.stackexchange.com/​a/​247614|source]])+//dsa// ssh keys are disabled by default (becoming obsolete). ''​ssh''​ will ask for your password even if you have a ''​~/​.ssh/​id_dsa''​ file. ''​ssh -v''​ will print ''​Skipping ssh-dss key /​home/<​your_login>/​.ssh/​id_dsa - not in PubkeyAcceptedKeyTypes''​. The solution is to generate a new couple of public/​private keys not based on //dsa// encryption, or to use the user ssh ''​config'' ​file to authorize ​//dsa// ([[https://​unix.stackexchange.com/​a/​247614|source]])
     * Add ''​PubkeyAcceptedKeyTypes +ssh-dss''​ to ''​~/​.ssh/​config''​ (**before** the ''​HOST''​ sections)     * Add ''​PubkeyAcceptedKeyTypes +ssh-dss''​ to ''​~/​.ssh/​config''​ (**before** the ''​HOST''​ sections)
     * Make sure the config file has the correct access rights: ''​chmod 600 config''​     * Make sure the config file has the correct access rights: ''​chmod 600 config''​
Line 449: Line 461:
 === ssh to WSL === === ssh to WSL ===
  
-FIXME+FIXME Maybe check [[https://​docs.microsoft.com/​en-us/​windows/​wsl/​troubleshooting#​openssh-server-connection-issues|OpenSSH-Server connection issues]]
  
 Maybe it could be useful to do a ''​ssh''​ from the Win10 part of the machine to the WSL part, and from outside the machine to the WSL part Maybe it could be useful to do a ''​ssh''​ from the Win10 part of the machine to the WSL part, and from outside the machine to the WSL part
Line 473: Line 485:
 ==== Mounting disks and network drives ==== ==== Mounting disks and network drives ====
  
-By default, the local disks and the external USB disks available (and decrypted!) when the first WSL terminal is opened are automatically available (//​mounted//​) in ''/​mnt''​ : the content of ''​C:​\''​ is available in ''/​mnt/​c'',​ etc... The list is refreshed when Windows (or just WSLis rebooted ​.+By default, the local disks and the external USB disks available (and decrypted!) ​when WSL is started (i.e. when the first WSL terminal is openedare automatically available (//​mounted//​) in ''/​mnt''​ : the content of ''​C:​\''​ is available in ''/​mnt/​c'',​ etc... The list of available disks is refreshed when the Windows ​session is restarted ​(the user logs out and in, or Windows is rebooted) or when just [[other:​win10wsl#​rebooting_wsl|WSL is restarted]].
  
 Extra local disks or //network drives// (what you can access by opening ''​\\dfshost\dfs\''​ in the file explorer when you are on the LSCE network) can be either mounted on the fly with the ''​mount''​ command, or automatically by configuring the ''/​etc/​fstab''​ file. Extra local disks or //network drives// (what you can access by opening ''​\\dfshost\dfs\''​ in the file explorer when you are on the LSCE network) can be either mounted on the fly with the ''​mount''​ command, or automatically by configuring the ''/​etc/​fstab''​ file.
Line 480: Line 492:
  
 <wrap hi>​Warning!</​wrap>​ In all cases, the owner, groups and permissions displayed may not be accurate (but the actual access rights will apply). <wrap hi>​Warning!</​wrap>​ In all cases, the owner, groups and permissions displayed may not be accurate (but the actual access rights will apply).
-  * the user/group of the files may appear as ''​your_login''/''​your_login''​ or ''​root''/''​root''​ +  * the user/group of the files may appear as ''​your_login''/''​your_login''​ or ''​root''/''​root''​. Example of a local file belonging to the current Windows //jypeter// user, and a system file 
-  * the access rights may appear as ''​rwxrwxrwx''​ even if the actual rights are more restrictive +    * <​code>​$ ls -l /​mnt/​c/​Users/​jypeter/​Desktop/​File_on_Desktop.txt 
-  more details in the //metadata// section+-rwxrwxrwx 1 jypeter jypeter 0 Jan 21 11:50 /​mnt/​c/​Users/​jypeter/​Desktop/​File_on_Desktop.txt 
 + 
 +$ ls -l /​mnt/​c/​Windows/​notepad.exe 
 +-r-xr-xr-x 3 jypeter jypeter 181248 Mar 19  2019 /​mnt/​c/​Windows/​notepad.exe 
 +</​code>​ 
 +  * the access rights may appear as ''​rwxrwxrwx''​ even if the actual rights are more restrictive. Example after mounting the LSCE ''/​home/​scratch01''​ disk 
 +    <​code>#​ File access rights seen from WSL+Ubuntu 
 +$ ls -l /​mnt/​scratch01/​jypeter/​Chrome_backup.zip 
 +-rwxrwxrwx 1 root root 2755154 Jan 13 15:10 /​mnt/​scratch01/​jypeter/​Chrome_backup.zip 
 + 
 +# Actual access rights (on the Linux server) 
 +>ls -l /home/scratch01/jypeter/​Chrome_backup.zip 
 +-rw-r--r-- 1 jypeter lsce 2755154 Jan 13 15:10 /​home/​scratch01/​jypeter/​Chrome_backup.zip 
 + 
 +# You can't change the access rights from WSL+Ubuntu, but you can remove a file, or create a new one 
 +$ chmod 600 /​mnt/​scratch01/​jypeter/​Chrome_backup.zip 
 +chmod: changing permissions of '/​mnt/​scratch01/​jypeter/​Chrome_backup.zip':​ Operation not permitted 
 +$ rm /​mnt/​scratch01/​jypeter/​Chrome_backup.zip 
 +$ ls -l /​mnt/​scratch01/​jypeter/​Chrome_backup.zip 
 +ls: cannot access '/​mnt/​scratch01/​jypeter/​Chrome_backup.zip':​ No such file or directory 
 + 
 +$ touch /​mnt/​scratch01/​jypeter/​new_file_from_wsl.txt 
 +jypeter@lsce5203:/​mnt/​scratch01/​jypeter$ ls -l /​mnt/​scratch01/​jypeter/​new_file_from_wsl.txt 
 +-rwxrwxrwx 1 root root 0 Jan 21 11:37 /​mnt/​scratch01/​jypeter/​new_file_from_wsl.txt 
 + 
 +# The new file has the correct (default) access rights on the Linux server 
 +>ls -l /​home/​scratch01/​jypeter/​new_file_from_wsl.txt 
 +-rw-r--r-- 1 jypeter lsce 0 Jan 21 11:37 /​home/​scratch01/​jypeter/​new_file_from_wsl.txt 
 +</code>
  
 === Enabling metadata === === Enabling metadata ===
  
-Some access rights handling can be partially corrected ​by automatically enabling the ''​metadata''​ mount option. This will allow you to use ''​chmod''/''​chown''​ on local NTFS disks (e.g. ''/​mnt/​c/​Users/​your_login''​).+Some access rights handling can be slightly improved ​by automatically enabling the ''​metadata''​ mount option. This will allow you to use ''​chmod''/''​chown''​ on **local NTFS disks** (disks directly connected to your computer, ​e.g. ''/​mnt/​c/​Users/​your_login''​).
  
   - become //root// in a terminal with: ''​sudo -s''​   - become //root// in a terminal with: ''​sudo -s''​
Line 494: Line 534:
 You need to [[other:​win10wsl#​rebooting_wsl|restart WSL+ubuntu]] to activate the new content of ''/​etc/​wsl.conf''​. See below an example of the ''​mount -l''​ output: You need to [[other:​win10wsl#​rebooting_wsl|restart WSL+ubuntu]] to activate the new content of ''/​etc/​wsl.conf''​. See below an example of the ''​mount -l''​ output:
   * Before: ''​C:​ on /mnt/c type drvfs (rw,​noatime,​uid=1000,​gid=1000,​case=off)''​   * Before: ''​C:​ on /mnt/c type drvfs (rw,​noatime,​uid=1000,​gid=1000,​case=off)''​
-  * After: ''​C:​ on /mnt/c type drvfs (rw,​noatime,​uid=1000,​gid=1000,​metadata,​case=off)''​+  * After enabling //​metadata//​: ''​C:​ on /mnt/c type drvfs (rw,​noatime,​uid=1000,​gid=1000,​metadata,​case=off)''​
  
-Optional: more details about [[https://​devblogs.microsoft.com/​commandline/​automatically-configuring-wsl/​|wsl.conf]] and [[https://​devblogs.microsoft.com/​commandline/​chmod-chown-wsl-improvements/​|metadata and access rights management]]+Optional: more details about ''​wsl.conf''​ in [[https://​docs.microsoft.com/​en-us/​windows/​wsl/​wsl-config#​set-wsl-launch-settings|WSL launch settings]], ​[[https://​devblogs.microsoft.com/​commandline/​automatically-configuring-wsl/​|How to use wsl.conf]] and [[https://​devblogs.microsoft.com/​commandline/​chmod-chown-wsl-improvements/​|metadata and access rights management]]
  
 === On-the-fly mount === === On-the-fly mount ===
Line 502: Line 542:
 You have to create a //mount point// in the existing ''/​mnt''​ directory and then use the ''​mount''​ command You have to create a //mount point// in the existing ''/​mnt''​ directory and then use the ''​mount''​ command
  
-<​code>​$ sudo -s+<​code>​# Must be root for most '​mount'​ related commands 
 +$ sudo -s
  
-# Create the mount point (once)+# Create the mount point (once), e.g. for accessing /​home/​scratch01 on the local LSCE servers 
 +# This works when the Windows 10 computer is on the LSCE network
 $ mkdir /​mnt/​scratch01 $ mkdir /​mnt/​scratch01
  
Line 510: Line 552:
 $ mount -t drvfs '​\\dfshost\dfs\scratch01'​ /​mnt/​scratch01 $ mount -t drvfs '​\\dfshost\dfs\scratch01'​ /​mnt/​scratch01
  
 +# List the mounted disks
 $ mount -l $ mount -l
 [...] [...]
Line 539: Line 582:
  
 # Create the mount points (once) # Create the mount points (once)
-$ mkdir /mnt/home_jyp ​/mnt/scratch_jyp+# The example below is to access the LSCE /home/users and /​home/​scrath01 disks 
 +$ mkdir /mnt/users /mnt/scratch01
  
-# Make a backup copy of /etc/fstab+# Make a backup copy of /​etc/​fstab ​before modifying it (for safety reasons!)
 $ cp -p /etc/fstab /​etc/​fstab.bak $ cp -p /etc/fstab /​etc/​fstab.bak
  
Line 547: Line 591:
 $ cat /etc/fstab $ cat /etc/fstab
 LABEL=cloudimg-rootfs ​  / ​       ext4   ​defaults ​       0 0 LABEL=cloudimg-rootfs ​  / ​       ext4   ​defaults ​       0 0
-\\dfshost\dfs\users\jyp /mnt/home_jyp ​drvfs defaults 0 0 +\\dfshost\dfs\users /mnt/users drvfs defaults 0 0 
-\\dfshost\dfs\scratch01\jyp /mnt/scratch_jyp ​drvfs defaults 0 0+\\dfshost\dfs\scratch01 /mnt/scratch01 ​drvfs defaults 0 0
  
 # Try to mount all the disks in /etc/fstab # Try to mount all the disks in /etc/fstab
-$ mount -a</​code>​+$ mount -a
  
-=== Resources ​===+# Check the result 
 +$ mount -l 
 +[...] 
 +\\dfshost\dfs\users on /mnt/users type drvfs (rw,​relatime,​case=off) 
 +\\dfshost\dfs\scratch01 on /​mnt/​scratch01 type drvfs (rw,​relatime,​case=off) 
 +</​code>​ 
 + 
 +=== Accessing remote file systems with sshfs === 
 + 
 +FIXME 
 + 
 +It seems this can be done with a combination of [[https://​github.com/​billziss-gh/​winfsp|WinFsp]] and [[https://​github.com/​billziss-gh/​sshfs-win|SSHFS-Win]] (see [[https://​superuser.com/​questions/​1423371/​sshfs-remote-directory-mounting-syntax|SSHFS remote directory mounting syntax]] for details 
 + 
 +=== Extra resources ​===
  
 Useful ''​mount''​ options: Useful ''​mount''​ options:
Line 578: Line 635:
  
 WSL can be rebooted (all the terminals and processed will be closed/​killed) by restarting the //WSL service// (''​LxssManager''​) WSL can be rebooted (all the terminals and processed will be closed/​killed) by restarting the //WSL service// (''​LxssManager''​)
 +  * from a //Windows PowerShell//​ (no need to run as administrator):​\\ type ''​wsl --terminate Ubuntu''​
   * from the //​Services//​ tab of the Task manager or the //​Services//​ program (launch ''​services.msc''​)   * from the //​Services//​ tab of the Task manager or the //​Services//​ program (launch ''​services.msc''​)
     * Right-click on the ''​LxssManager''​ service and select //Restart//     * Right-click on the ''​LxssManager''​ service and select //Restart//
Line 585: Line 643:
 Source: google ''​wsl lxssmanager''​ ([[https://​www.how2shout.com/​how-to/​how-to-reboot-wsl-windows-subsystem-linux-in-windows-10.html|most usable answer]]) Source: google ''​wsl lxssmanager''​ ([[https://​www.how2shout.com/​how-to/​how-to-reboot-wsl-windows-subsystem-linux-in-windows-10.html|most usable answer]])
  
-==== Creating a backup ====+==== Creating a backup ​of the Linux running in WSL ====
  
-Best thing is probably to create tar file of the user's home directory, and get list of installed applications ​and updated settings ​(e.g ''​/etc/fstab''​)+There are several types of directories that you may want to back up: 
 +  * Your //home// directory in Linux (''/​home/<​your_login>''​),​ or some specific sub-directories of the Ubuntu running in WSL (sub-directories of ''/''​):​ all these files are located in a [[other:​win10wsl#​location_of_the_files|hidden sub-directory of you Windows directory]],​ and the best way to save them is probably to create ​a **tar file** from Linux, and put this tar file in specific Windows folder 
 +    * <​code>​$ cd /home 
 +$ du -sh <​your_login>​ 
 +232K    <​your_login>​ 
 +$ tar cfz /​mnt/​c/​Scratch/<​your_login>/<​your_login>​_home_<​some_date>​.tgz <​your_login>​ 
 +</​code>​ 
 +  * Windows folders that are not in ''/'':​ you can use ''​tar''​ from Linux, as above, or use any usual way of backing up Windows files (drag and drop, some specific backup software) 
 +  * The **full Linux/​Ubuntu installation** running in WSL (following [[https://​docs.microsoft.com/en-us/windows/​wsl/​faq#​how-can-i-back-up-my-wsl-distros|How can I back up my WSL distros?​]]). The following steps will save the full installation in a tar file, that can be used later for restoring the full installation (//​restoration//​ not tested yet) 
 +    * Open a Windows terminal (preferably a PowerShell if you need easy copy/​paste) 
 +    * [[other:​win10wsl#​rebooting_wsl|Stop WSL+Linux]] 
 +    * Determine the name of the current Linux installation used in WSL 
 +      * <​code>>​ wsl --list --all 
 +Distributions du sous-système Windows pour Linux : 
 +Ubuntu (par défaut)</​code>​ 
 +    * Export the current Linux to a tar file: ''​wsl %%--%%export Ubuntu C:​\Scratch\<​your_login>​\ubuntu_<​your_login>​_<​some_date>​.tar''​ 
 +    * Get some information about the created file (size and number of saved files/​directories), in a Linux terminal 
 +      * <​code>​$ ls -lh /​mnt/​c/​Scratch/<​your_login>/​ubuntu_<​your_login>​_<​some_date>​.tar 
 +2.6G Jan 21 14:25 /​mnt/​c/​Scratch/<​your_login>/​ubuntu_<​your_login>​_200121.tar 
 + 
 +jypeter@lsce5203:/​mnt/​c/​Scratch/​jypeter$ tar tvf /​mnt/​c/​Scratch/<​your_login>/​ubuntu_<​your_login>​_200121.tar | wc -l 
 +105600 
 +</​code>​ 
 + 
 +==== Restoring a WSL backup ==== 
 + 
 +FIXME Read [[https://​www.howtogeek.com/​426562/​how-to-export-and-import-your-linux-systems-on-windows-10/​|How to Export and Import Your Linux Systems on Windows 10]] and [[https://​winaero.com/​blog/​export-import-wsl-linux-distro-windows-10/​|Export and Import WSL Linux Distro in Windows 10]] and similar threads 
 + 
 +FIXME Check if [[https://​wslhub.com/​|WSL Manager]] is maintained and can be useful
  
-Check [[https://askubuntu.com/questions/9135/how-to-backup-settings-and-list-of-installed-packages|How to backup settings ​and list of installed packages]]+This assumes that you have followed the steps above to create a full backup of your Linux distribution in a ''​ubuntu_<​your_login>​_<​some_date>​.tar''​ file. This file can theoretically be restored with: 
 +  * ''​wsl %%--%%import <​DistributionName>​ <​InstallLocation>​ ubuntu_<​your_login>​_<​some_date>​.tar''​ 
 +    * Note: found a page mentioning that you should be in a terminal with admin rights when using ''​%%--%%import''​ 
 +    * Can we use the same ''<​DistributionName>''​ (e.g. ''​Ubuntu''​) as the one we are trying to restore without first removing it with ''​unregister''​ ([[https://docs.microsoft.com/en-us/​windows/wsl/wsl-config#​unregister-and-reinstall-a-distribution|Unregister ​and reinstall a distribution]])?​ 
 +    * If we use a new distribution name, it will probably not appear anymore in the Microsoft Store and will not be updated. Is this a problem? 
 +    * It seems we can use ''<​InstallLocation>''​ to install anywhere! What should we do if we want to restore to the default location (in the hidden directory)?​ 
 +      * Can we install out of the current user's Windows folder? 
 +      * Can we install out of ''​C:​\''?​ 
 +    * Can we restore (//clone//) a backed up Linux distribution on another Windows 10 computer for another user? 
 +      * if the default user (and its password) has to be changed, you probably have to follow the steps to [[https://​docs.microsoft.com/​en-us/​windows/​wsl/​user-support#for-fall-creators-update-and-later|reset the Linux password]] and find a way to create a new account when the ''​root''​ password is activated
 ==== Uninstalling WSL ==== ==== Uninstalling WSL ====
  
Line 598: Line 693:
   * and then disable WSL???   * and then disable WSL???
 ===== Other WSL resources and links ===== ===== Other WSL resources and links =====
 +
 +  * [[https://​docs.microsoft.com/​en-us/​windows/​wsl/​release-notes|Release Notes for Windows Subsystem for Linux]]
  
   * [[https://​docs.microsoft.com/​en-us/​windows/​wsl/​faq|Frequently Asked Questions]]   * [[https://​docs.microsoft.com/​en-us/​windows/​wsl/​faq|Frequently Asked Questions]]
other/win10wsl.txt · Last modified: 2020/09/16 17:34 by jypeter