User Tools

Site Tools


other:win10_wsl_1

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
other:win10_wsl_1 [2020/09/16 12:38]
jypeter [Opening a terminal] Improved WSLtty and Win terminal
other:win10_wsl_1 [2022/08/12 12:25] (current)
jypeter other:win10wsl renamed to other:win10_wsl_1 (Moved the original page to WSL_1, before starting a WSL2 version (with the same name as the original page))
Line 9: Line 9:
 The user can choose to install Linux using WSL1 or WSL2. Check the [[https://​docs.microsoft.com/​en-us/​windows/​wsl/​compare-versions|differences between WSL1 and WSL2]] before choosing</​note>​ The user can choose to install Linux using WSL1 or WSL2. Check the [[https://​docs.microsoft.com/​en-us/​windows/​wsl/​compare-versions|differences between WSL1 and WSL2]] before choosing</​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+ 
 +===== What is WSL ? ===== 
 + 
 +Useful reading: 
 +  * Have a look at the beginning ​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 [[https://​wiki.ubuntu.com/​WSL|What is WSL]] on the Ubuntu site 
 +    * There is more useful information on the //​WSL@Ubuntu page//, you can read the rest later
  
 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**//​. 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**//​.
Line 114: Line 120:
 Microsoft is working on a powerful replacement of the old ''​cmd''​ terminal! Check [[https://​github.com/​microsoft/​terminal|Windows Terminal, Console and Command-Line @ github]] Microsoft is working on a powerful replacement of the old ''​cmd''​ terminal! Check [[https://​github.com/​microsoft/​terminal|Windows Terminal, Console and Command-Line @ github]]
  
-Note: the //Windows Terminal// looks really promising, but will be nice when there is a GUI for editing the options (rather the editing a //json// file with a text editor...) and a way to select //​xterm-style//​ copy-pasting+Note: the //Windows Terminal// looks really promising, but will be nice when there is a GUI for editing the options (rather the editing a //json// file with a text editor...) and a way to select //​xterm-style//​ copy-pasting. See [[https://​github.com/​microsoft/​terminal/​issues/​7646|Feature request: add xterm-style select/​copy/​paste options]]
  
   * [[https://​aka.ms/​terminal|Getting the Windows Terminal from the Microsoft Store]]   * [[https://​aka.ms/​terminal|Getting the Windows Terminal from the Microsoft Store]]
Line 299: Line 305:
 ==== Installing an X server ==== ==== Installing an X server ====
  
-<WRAP center round tip 60%> +Read the [[other:x_conf|Installing and configuring ​an X server]] ​page
-The //X server// will allow you to display graphical windows (i.e. //X windows//) from remote servers or from your local WSL+Ubuntu +
-</​WRAP>​ +
- +
- +
-<WRAP center round important 60%> +
-After the X server is installed and running, some graphical applications and images (or the text displayed by those applications) may appear blurry. This is due to some servers or some Linux applications not handling high resolution (//HiDPI//) screens correctly +
- +
-X410 has several options for this (see [[https://​token2shell.com/​howto/​x410/​running-x410-on-hidpi-screens/​|Running X410 on HiDPI Screens]]) but it may also work correctly with non commercial applications +
-</​WRAP>​ +
- +
-=== Installing ​VcXrsv === +
- +
-<note tip>​VcXrsv is pre-installed on the LSCE computers!</​note>​ +
- +
-Type: <wrap em>​free</​wrap>​ +
- +
-Download the installer from [[https://​sourceforge.net/​projects/​vcxsrv/​|VcXrsv]] ​and install VcXrsv. +
- +
-== VcXrsv Configuration == +
- +
-You need to configure VcXrsv to work in //multiple windows// mode. The following steps will show you how to create a shortcut on your desktop to start VcXrsv in this appropriate mode +
- +
-  * Start //​Xlaunch//:​ ''​Start''​ => ''​VcXrsv''​ => ''​Xlaunch''​ +
-  * Check ''​Multiple windows''​ (the default choice) then ''​Next''​ +
-  * Check ''​Start no client''​ then ''​Next''​ +
-  * Keep the default ''​Clipboard''​ settigs, uncheck ''​Native opengl''​ (not sure about that) then ''​Next''​ +
-  * Click on ''​Save configuration''​ and save an ''​X_Server.xlaunch''​ configuration file on your Desktop, then ''​Terminate''​. You should now have a new ''​X_Server''​ icon/​shortcut on your Desktop +
-  * Click on the new ''​X_Server''​ icon, and check that an ''​X''​ icon appears in the right side of the taskbar (you may have to look for it in the //Display hidden icons// pull-up menu) +
-    * Note: you can right-click on the ''​X''​ icon and select ''​Exit...''​ if you need to quit the X server +
-  * Note: if you notice later that the content of some displayed //X windows// appear **blurry**, see if you can [[other:​win10misc#​vcxsrv_x_server|fix the compatibility settings]], or try to use **x410**. +
-  * You are now **ready**, if you only need VcXrsv to display graphical windows from remote servers +
- +
-  * The following steps allow you to test the X server in a **local** WSL+Ubuntu terminal. **Do not set the DISPLAY variable yourself when you are connected to a remote server with ''​ssh''​!** +
-    * Open a **local** terminal (in WSL+Ubuntu) +
-    * Type ''​export DISPLAY=localhost:​0.0''​ +
-    * Type ''​xterm''​ and check that a new //xterm// terminal appears +
- +
- +
-=== Installing x410 === +
- +
-Type: <wrap em>​commercial</​wrap>​ +
- +
-[[https://​token2shell.com/​x410/​|x410]] is a low cost commercial X server that can be directly installed from the [[https://​www.microsoft.com/​store/​apps/​9nlp712zmn9q|Microsoft store]]. Once installed, it will be automatically updated by the Microsoft Store application. +
- +
-**Starting, configuring and exiting X410**: you can start X410 by clicking on it in the Windows Start Menu, or choose to [[https://​token2shell.com/​howto/​x410/​automatically-start-x410-on-login/​|Automatically Start X410 on Login]] +
-  * Note: nothing actually happens when you start X410, as it is just waiting to display graphics! You will just get a new **X** icon in the //hidden// icons of the taskbar. +
-  * You can configure (and exit) X410 by right clicking on its **X** icon +
- +
-=== Installing MobaXterm === +
- +
-Type: <wrap em>​commercial</​wrap>​ +
- +
-Available at [[https://​mobaxterm.mobatek.net/​|MobaXterm]],​ not tested. This seems to be more than just an X server, and may be an overkill if you just need an X server+
  
 ==== Configuration (in your local Linux account) ==== ==== Configuration (in your local Linux account) ====
  
-  * Set the DISPLAY variable in the shell (by hand, or in the bash shell init file) +  * Set the ''​DISPLAY'' ​variable in the shell by hand, or automatically ​in the shell configuration ​file(s): 
-    * ''​export DISPLAY=localhost:0.0''​ +    * //bash// shell: ​''​export DISPLAY=localhost:​0.0''​\\ Can be defined in the ''​~/.bashrc'' ​file 
-    * <wrap em>​Warning!<​/wrap> ​''​export DISPLAY=:​0.0'' ​will also work for using graphical windows locally, but will fail when trying to open a window on a remote computer, with a ''​connect /tmp/.X11-unix/​X0:​ No such file or directory'' ​error message ([[https://unix.stackexchange.com/questions/57138/​why-does-my-x11-forwarding-attempt-fail-with-connect-tmp-x11-unix-x0-no-such/​|source]]) +    * //tcsh// shell: ''​setenv ​DISPLAY ​localhost:​0.0''​\\ Can be defined ​in the ''​~/.login''​, or the ''​~/.cshrc'' ​file  ​
- +
-  * VcXsrv **and WSL2** ​check ''​export ​DISPLAY=$(cat /​etc/​resolv.conf | grep nameserver | awk '​{print $2}'):​0.0''​ in [[https://solvercube.com/​how-to-install-ubuntu-20-04-on-windows-using-wsl/​|How to install Ubuntu 20.04 on Windows using WSL]] +
- +
-  *  FIXME Need to determine if/​when ​''​export LIBGL_ALWAYS_INDIRECT=1'' ​is useful +
-    * it breaks ​''​glxgears''​ with x410+
  
-==== Resources ====+  * <wrap em>​Warning!</​wrap>​ ''​export DISPLAY=:​0.0''​ will also work for using graphics locally, but **will fail when trying to use graphics on a remote computer**, with a ''​connect /​tmp/​.X11-unix/​X0:​ No such file or directory''​ error message ([[https://​unix.stackexchange.com/​questions/​57138/​why-does-my-x11-forwarding-attempt-fail-with-connect-tmp-x11-unix-x0-no-such/​|source]])
  
-You can skip this! m(+  * FIXME **//X server// and WSL2** : check ''​export DISPLAY=$(cat /​etc/​resolv.conf | grep nameserver | awk '​{print $2}'​):​0.0''​ in [[https://​solvercube.com/​how-to-install-ubuntu-20-04-on-windows-using-wsl/​|How to install Ubuntu 20.04 on Windows using WSL]]
  
-  * Check [[https://​askubuntu.com/​questions/​993225/​whats-the-easiest-way-to-run-gui-apps-on-wsl-as-of-2018|What'​s the easiest way to run GUI apps on WSL as of 2018?]] 
-  * Check the X410 [[https://​token2shell.com/​howto/​x410/​|Tips and Tricks]] that can probably apply to other X servers 
-  * Check the rest of [[https://​github.com/​QMonkey/​wsl-tutorial|wsl-tutorial]] 
  
 ==== Adding useful packages ==== ==== Adding useful packages ====
Line 398: Line 343:
 ===== Updating WSL and ubuntu ===== ===== Updating WSL and ubuntu =====
  
-<note tip>You don't have to worry about this if you have just installed WSL+Ubuntu!</​note>​+<note tip>You don't have to worry about the //Upgrade// section ​if you have just installed WSL+Ubuntu, because you are already using the latest Ubuntu stable release!</​note>​
 ==== WSL ==== ==== WSL ====
  
-WSL is automatically updated ​when Windows 10 is updated+**Nothing to do!** WSL is automatically updated, provided you have **enabled** the [[other:​win10maintain#​updating_microsoft_office|Get updates for other Microsoft products]] option
  
 [[https://​docs.microsoft.com/​en-us/​windows/​wsl/​wsl-config#​managing-multiple-linux-distributions| WSL command line options]] [[https://​docs.microsoft.com/​en-us/​windows/​wsl/​wsl-config#​managing-multiple-linux-distributions| WSL command line options]]
Line 486: Line 431:
 -rwxr-xr-x 1 root root 35000 Jan 18  2018 /​bin/​sleep.back -rwxr-xr-x 1 root root 35000 Jan 18  2018 /​bin/​sleep.back
 -rwxr-xr-x 1 root root 39256 Sep  5  2019 /​bin/​sleep.back2</​code>​ -rwxr-xr-x 1 root root 39256 Sep  5  2019 /​bin/​sleep.back2</​code>​
 +
 +
 +==== Cleaning up things ====
 +
 + * [[https://​linoxide.com/​how-to-clear-apt-cache/​|How to Clear Apt Cache]]
 ===== Advanced configuration ===== ===== Advanced configuration =====
  
Line 715: Line 665:
 It is not possible to **stop or reboot WSL** like a regular Linux computer It is not possible to **stop or reboot WSL** like a regular Linux computer
   * ''​shutdown -r now''​ will generate an error message   * ''​shutdown -r now''​ will generate an error message
-  * WSL keeps on running even when all the terminals are closed+  * WSL keeps on running even when all the Linux terminals are closed
  
-Shutting down or rebooting the Windows computer will of course stop WSL but it's useful to be able to only stop/​restart WSL in order to:+Shutting down or rebooting the Windows computer will of course stop WSL but it's useful to be able to just stop/​restart WSL in order to:
   * force WSL to **recognize new disk drives** and make them available as ''/​mnt/<​new_drive_letter''​   * force WSL to **recognize new disk drives** and make them available as ''/​mnt/<​new_drive_letter''​
   * force WSL to recognize drives that were still encrypted when the first WSL terminal was opened   * force WSL to recognize drives that were still encrypted when the first WSL terminal was opened
  
-WSL can be stopped the following way. Warning: ​all the opened ​terminals and running processes ​will be terminated!+WSL can be stopped the following way. Warning: ​all the open terminals and running processes ​will be terminated!
   * from a Windows terminal (''​cmd'',​ ''​PowerShell'',​ ... no need to run as administrator):​   * from a Windows terminal (''​cmd'',​ ''​PowerShell'',​ ... no need to run as administrator):​
-    * Get the name of the installed (and running) Linux: **''​wsl %%--%%list %%--%%all''​** +    * Get the name of the installed (and running) Linux: **''​wsl %%--%%list %%--%%verbose''​** 
-    * Stop this instance of Linux (e.g. if it is named //​Ubuntu//​):​ **''​wsl %%--%%terminate Ubuntu''​**+    * Stop //this instance// of Linux (e.g. if it is named //​Ubuntu//​):​ **''​wsl %%--%%terminate Ubuntu''​** 
 +    * or Stop //all// the currently running Linux distributions:​ **''​wsl %%--%%shutdown''​**
  
-Alternative (and less convenient) ways: 
-  * from the //​Services//​ tab of the Task manager or the //​Services//​ program (launch ''​services.msc''​) 
-    * Right-click on the ''​LxssManager''​ service and select //Restart// 
-  * from a //​Powershell//​ in admin mode (right-click on the Windows //Start// button) 
-    * Type ''​Get-Service LxssManager | Restart-Service''​ 
- 
-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 of the Linux running in WSL ==== ==== Creating a backup of the Linux running in WSL ====
  
 There are several types of WSL related directories that you may want to back up: There are several types of WSL related directories that you may want to back up:
-  ​* <wrap hi>Your Linux //home// directory</​wrap>​ (''/​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 a specific Windows folder+ 
 +  ​* <wrap hi>Your Linux //home// directory</​wrap>​ (''/​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 a specific Windows ​//WSL backup ​folder// (we will use below the directory ''/​mnt/​c/​Scratch/<​your_login>''​ or ''​c:​\Scratch\<​your_login>''​)
     * <code bash>$ cd /home     * <code bash>$ cd /home
-# $ du -sh <​your_login>​+
 $ du -sh $USER $ du -sh $USER
 232K    <​your_login>​ 232K    <​your_login>​
-# $ tar cfz /​mnt/​c/​Scratch/<​your_login>/<​your_login>​_home_<​some_date>​.tgz <​your_login>​ + 
-# We assume below that there is an existing /​mnt/​c/​Scratch/​$USER/ directory +# We assume below that there is an existing /​mnt/​c/​Scratch/​<​your_login>​/ directory 
-# It's a WINDOWS directory C:\Scracth\$USER+# It's a WINDOWS directory C:\Scratch\<​your_login>​
 $ tar cfz /​mnt/​c/​Scratch/​$USER/​${USER}_home_`date +%y%m%d_%H%M`.tgz $USER $ tar cfz /​mnt/​c/​Scratch/​$USER/​${USER}_home_`date +%y%m%d_%H%M`.tgz $USER
-</​code>​+ 
 +# Check the size of the new (and existing old) backup(s) 
 +$ ls -ltr /​mnt/​c/​Scratch/​$USER/​${USER}_*.tgz 
 +81K Jan 21  2020 /​mnt/​c/​Scratch/<​your_login>/<​your_login>​_home_200121.tgz 
 +93K Aug 22  2020 /​mnt/​c/​Scratch/<​your_login>/<​your_login>​_home_200822_1151.tgz 
 +95K Feb 24 12:09 /​mnt/​c/​Scratch/<​your_login>/<​your_login>​_home_210224_1209.tgz</​code>​ 
   * <wrap hi>​Regular Windows folders</​wrap>​ where you store data used by WSL: you can use ''​tar''​ in a Linux terminal, as above, or use any usual way of backing up Windows files (drag and drop, some specific [[other:​win10apps#​backup_software|backup software]])   * <wrap hi>​Regular Windows folders</​wrap>​ where you store data used by WSL: you can use ''​tar''​ in a Linux terminal, as above, or use any usual way of backing up Windows files (drag and drop, some specific [[other:​win10apps#​backup_software|backup software]])
 +
   * <wrap hi>The **full** Linux/​Ubuntu installation</​wrap>​ running in WSL (based on [[https://​docs.microsoft.com/​en-us/​windows/​wsl/​faq#​how-can-i-back-up-my-wsl-distros-or-move-them-from-one-drive-to-another|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)   * <wrap hi>The **full** Linux/​Ubuntu installation</​wrap>​ running in WSL (based on [[https://​docs.microsoft.com/​en-us/​windows/​wsl/​faq#​how-can-i-back-up-my-wsl-distros-or-move-them-from-one-drive-to-another|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) +    * Open a **Windows terminal** (preferably a //​PowerShell//​ if you need easy copy/paste)\\ The //Windows// terminal is where you will type the ''​wsl''​ commands shown below 
-    * Determine the name of the current Linux installation used in WSL+    * Determine the name of the current Linux installation used in WSL (and see if it is running, and using //WSL 1// or //WSL 2//)
       * <​code>>​ wsl --list --all       * <​code>>​ wsl --list --all
-Distributions du sous-système Windows pour Linux +Distributions du sous-système Windows pour Linux 
-Ubuntu (par défaut)</​code>​+Ubuntu (par défaut) 
 + 
 +> wsl --list --verbose 
 +  NAME      STATE           ​VERSION 
 +* Ubuntu ​   Running ​        1</​code>​
     * [[other:​win10wsl#​rebooting_wsl|Stop WSL+Linux]]     * [[other:​win10wsl#​rebooting_wsl|Stop WSL+Linux]]
-    ​* Export the current Linux to a tar file:\\ ''​wsl %%--%%export Ubuntu C:​\Scratch\<​your_login>​\<​your_login>​_ubuntu-<​ubuntu_version>​-full_<​some_date>​.tar''​ +      * <​code>>​ wsl --list --verbose 
-    * You can optionally open a new terminal (this will start again WSL+Ubuntu) to get some information about the created file (size and number of saved files/​directories),​ and compress it to save some space+  NAME      STATE           ​VERSION 
 +* Ubuntu ​   Running ​        1 
 + 
 +> wsl --shutdown 
 + 
 +> wsl --list --verbose 
 +  NAME      STATE           ​VERSION 
 +* Ubuntu ​   Stopped ​        ​1</​code>​ 
 +    ​* Export the current Linux to a //tar// file: 
 +      * <​code>​ > wsl --export Ubuntu C:​\Scratch\<​your_login>​\<​your_login>​_ubuntu-<​ubuntu_version>​-full_<​some_date>​.tar</​code>​ 
 +    * You can optionally open a new terminal (this will start again WSL+Ubuntu) to get some information about the created file (size and number of saved files/​directories),​ and compress it in order to save some disk space
       * <​code>​$ cd /​mnt/​c/​Scratch/<​your_login>​       * <​code>​$ cd /​mnt/​c/​Scratch/<​your_login>​
-$ ls -lh <​your_login>​_ubuntu-full_200514.tar + 
-2.6G May 14 16:29 <​your_login>​_ubuntu-full_200514.tar +$ ls -ltrh *ubuntu*tar* 
-$ tar tvf <​your_login>​_ubuntu-full_200514.tar | wc -l +976M Jan 21  2020 <​your_login>​_200121.tar.gz 
-105600 +2.8G Aug 22  2020 <​your_login>​-16.04-full_200822.tar 
-$ gzip <​your_login>​_ubuntu-full_200514.tar +3.4G Feb 24 14:06 <​your_login>​-20-04-1-full_210224.tar 
-$ ls -lh <​your_login>​_ubuntu-full_200514.tar.gz + 
-976M May 14 16:29 +# Determine the number of files/​directories in the backup 
 +$ tar tvf <​your_login>​-20-04-1-full_210224.tar | wc -l 
 +112711 
 + 
 +$ gzip *ubuntu*.tar 
 + 
 +$ ls -ltrh *ubuntu*tar* 
 +976M Jan 21  2020 <​your_login>​_200121.tar.gz 
 +1.2G Aug 22  2020 <​your_login>​-16.04-full_200822.tar.gz 
 +1.8G Feb 24 14:06 <​your_login>​-20-04-1-full_210224.tar.gz
 </​code>​ </​code>​
  
Line 790: Line 765:
   * Find how to unregister Ubuntu on the [[https://​docs.microsoft.com/​en-us/​windows/​wsl/​wsl-config|Manage and configure Windows Subsystem for Linux]] page   * Find how to unregister Ubuntu on the [[https://​docs.microsoft.com/​en-us/​windows/​wsl/​wsl-config|Manage and configure Windows Subsystem for Linux]] page
   * and then disable WSL???   * and then disable WSL???
 +
 +===== Miscellaneous =====
 +
 +  * Determining from **inside** the running Linux if you are using WSL (or another type of virtual machine)\\ <​code>​$ systemd-detect-virt
 +wsl</​code>​
 +
 ===== Other WSL resources and links ===== ===== Other WSL resources and links =====
  
other/win10_wsl_1.1600259935.txt.gz · Last modified: 2020/09/16 12:38 by jypeter