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
other:win10wsl [2020/08/21 14:17]
jypeter [Windows Subsystem for Linux (WSL), and Ubuntu] More WSL2 notes
other:win10wsl [2021/02/24 14:44] (current)
jypeter [WSL]
Line 28: Line 28:
       * 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...   * 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...
 +    * Check [[https://​github.com/​MicrosoftDocs/​WSL/​issues/​412|how to move the vhdx of wsl2 to other disk]] and [[https://​github.com/​microsoft/​WSL/​issues/​4320|[WSL 2] move VHD File]] for relocating a WSL (1 or 2) installation if you don't have enough space on ''​C:''​
  
 ===== Base installation ===== ===== Base installation =====
Line 74: Line 75:
  
 There are several ways to open a default terminal: There are several ways to open a default terminal:
-  * select ​//Ubuntu// from the ''​Start''​ menu +  * Select ​//Ubuntu// from the ''​Start''​ menu 
-  * click on the //Ubuntu// icon on the task bar+  * Click on the //Ubuntu// icon on the task bar
     * if you don't have a //Ubuntu// icon on the task bar yet: right-click on the //Ubuntu// icon (in the ''​Start''​ menu) -> More -> Pin to the task bar     * if you don't have a //Ubuntu// icon on the task bar yet: right-click on the //Ubuntu// icon (in the ''​Start''​ menu) -> More -> Pin to the task bar
     * to open more terminals: right-click on the //Ubuntu// icon on the task bar -> Ubuntu     * to open more terminals: right-click on the //Ubuntu// icon on the task bar -> Ubuntu
-  * type ''​ubuntu''​+<​Enter>​ or ''​wsl''​+''<​Enter>''​ in the (Cortana) Search field on the task bar+  * Type ''​ubuntu''​+<​Enter>​ or ''​wsl''​+''<​Enter>''​ in the (Cortana) Search field on the task bar
  
 == Copy/paste in the default terminal == == Copy/paste in the default terminal ==
Line 91: Line 92:
 === The WSLtty terminal === === The WSLtty terminal ===
  
-<note tip>This is the recommended (by JYP) option for now</​note>​+<note tip> 
 +  * This is the recommended (by JYP) option for now 
 + 
 +  * If you can't open a terminal after Windows upgrades from WSL to WSL v2, get and install the latest version of WSLtty ! 
 +</​note>​
  
 [[https://​github.com/​mintty/​wsltty|WSLtty]] allows you to use the efficient //Mintty// as a terminal for WSL. **You do not need to have an //X server// running to use it!** [[https://​github.com/​mintty/​wsltty|WSLtty]] allows you to use the efficient //Mintty// as a terminal for WSL. **You do not need to have an //X server// running to use it!**
  
   * Download and execute the latest [[https://​github.com/​mintty/​wsltty/​releases|64bit installer]] (the most recent ''​wsltty-*-install-x86_64.exe''​ file)   * Download and execute the latest [[https://​github.com/​mintty/​wsltty/​releases|64bit installer]] (the most recent ''​wsltty-*-install-x86_64.exe''​ file)
-  * You will then have different ​ways to start a terminal: +  * After installing, you will get several ​ways to open a terminal: 
-    * //WSL terminal// shorcut ​on the desktop +    * Double-click on the ''​WSL terminal''​ icon on the desktop 
-    * //Ubuntu terminal// and //WSL Terminal// in the ''​Start''​ menu +    * ''​U''​=>''​Ubuntu terminal'' ​and ''​W''​=>''​WSL Terminal'' ​in the ''​Start''​ menu 
-  * Open a terminal and right-click in it to discover/​use ​the options +      * There is also a ''​W''​=>''​WSLtty''​ folder, than you don't really need 
-    * More options with CTRL+right-click+  * Open a terminal and right-click in it to check the available ​options 
 +    * You can access even more options with CTRL+right-click
     * You can cycle between the open WSLtty terminals with CTRL+Tab and Shift+CTRL+Tab     * You can cycle between the open WSLtty terminals with CTRL+Tab and Shift+CTRL+Tab
   *  [[https://​github.com/​mintty/​mintty/​wiki|Technical stuff]] (on the Mintty wiki)   *  [[https://​github.com/​mintty/​mintty/​wiki|Technical stuff]] (on the Mintty wiki)
Line 106: Line 112:
 === The new Windows Terminal === === The new Windows Terminal ===
  
-Microsoft is working on a powerful replacement of the old ''​cmd''​ terminal, but it still needs to be improved ([[https://devblogs.microsoft.com/commandline/windows-terminal-preview-v0-8-release/​|Windows Terminal ​Preview v0.8 Release]])+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]]
  
-You can install it from the Microsoft Storesearch ​//Windows Terminal (Preview)//+Notethe //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://github.com/​microsoft/​terminal|Windows terminal ​@ github]]+  * [[https://aka.ms/terminal|Getting the Windows ​Terminal from the Microsoft Store]] 
 +  * [[https://​docs.microsoft.com/​en-us/​windows/​terminal/​|Documentation]]
  
 === Terminals started from Linux === === Terminals started from Linux ===
Line 352: Line 359:
     * ''​export DISPLAY=localhost:​0.0''​     * ''​export DISPLAY=localhost:​0.0''​
     * <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]])     * <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]])
 +
 +  * 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   *  FIXME Need to determine if/when ''​export LIBGL_ALWAYS_INDIRECT=1''​ is useful
Line 389: Line 398:
 ===== 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 420: Line 429:
 578 /​mnt/​h/​Scratch/​jyp/​pkg_190221.txt</​code>​ 578 /​mnt/​h/​Scratch/​jyp/​pkg_190221.txt</​code>​
  
 +==== Upgrading ubuntu ====
  
 +<WRAP center round tip 60%>
 +You can skip this section if you have just installed ubuntu, since you are already running the latest stable release available
 +</​WRAP>​
 +
 +
 +The **updates** are for maintaining the same version of ubuntu (e.g. you go from version ''​18.04.2''​ to ''​18.04.5''​),​ while **upgrades** are for going from one major version to the next (e.g ''​16.xx''​ => ''​18.xx''​ => ''​20.xx''​). We try to only use the stable major releases, that have an even version number.
 +
 +We use the **LTS versions** (//Long Time Support//) to ensure even more stability, which means that we will get updates of a given major release for quite some time after the next major release is available, so it is not mandatory to updgrade ubuntu if you are still receiving updates for the release you use
 +
 +There should not be any risk, but it may be a good idea to [[other:​win10wsl#​creating_a_backup_of_the_linux_running_in_wsl|create a backup]] of your current ubuntu before upgrading it!
 +
 +Use ''​sudo''​ for each command below, or just become root by using ''​sudo su -''​
 +
 +  * before the Linux upgrade:
 +    * [[other:​win10wsl#​creating_a_backup_of_the_linux_running_in_wsl|create a backup]]
 +    * Check how much space is left on ''​C:''​
 +    * make sure you have a network connection
 +    * read the official WSL [[https://​devblogs.microsoft.com/​commandline/​upgrading-ubuntu/#​upgrading-your-distribution|Upgrading your distribution]] instructions
 +
 +  * Launch the upgrade with the ''​do-release-upgrade''​ command and follow the instructions
 +    * if you get a //There is no development version of an LTS available// message, use ''​do-release-upgrade -d''​
 +    * if you get a //Please install all available updates for your release before upgrading// message, use ''​apt-get dist-upgrade''​ and then try ''​do-release-upgrade -d''​ again (see [[https://​www.liquidweb.com/​kb/​troubleshooting-please-install-available-updates-release-upgrading/​|How to Solve the Upgrade Ubuntu Install Updates Error]])
 +    * if you get ''​sleep:​ cannot read realtime clock: Invalid argument''​ error, temporarily replace the ''​sleep''​ binary with an executable empty file. Do not forget to restore the original sleep command after the upgrade!!
 +      * <​code>#​ sleep 1
 +sleep: cannot read realtime clock: Invalid argument
 +# mv /bin/sleep /​bin/​sleep.back
 +# ls -l /​bin/​sleep.back
 +-rwxr-xr-x 1 root root 35000 Jan 18  2018 /​bin/​sleep.back
 +# touch /bin/sleep
 +# chmod +x /bin/sleep
 +# sleep 1
 +#</​code>​
 +      * Note: you may have to use the //empty sleep command trick// again, if the sleep command itself is updated and breaks the upgrading process again. Do not forget to restore the original sleep command after the upgrade!!\\ <​code>​[...]
 +Restarting services possibly affected by the upgrade:
 +  cron: stopping...sleep:​ cannot read realtime clock: Invalid argument
 +dpkg: error processing package libpam0g:​amd64 (--configure):​
 + ​installed libpam0g:​amd64 package post-installation script subprocess returned error exit status 1
 +E: Sub-process /​usr/​bin/​dpkg returned an error code (1)
 +# ls -l /bin/sleep
 +-rwxr-xr-x 1 root root 39256 Sep  5  2019 /bin/sleep
 +# mv /bin/sleep /​bin/​sleep.back2
 +# touch /bin/sleep
 +# chmod +x /bin/sleep
 +# </​code>​
 +    * see also [[https://​www.how2shout.com/​how-to/​how-to-upgrade-ubuntu-18-04-lts-to-20-04-lts-on-wsl-windows-10.html|How to Upgrade Ubuntu 18.04 LTS to 20.04 LTS on WSL (Windows 10)]]
 +    * Do not forget to restore the correct ''​sleep''​ executable, if you had to move it
 +      * <​code>#​ ls -l /bin/sleep*
 +-rwxr-xr-x 1 root root     0 Aug 23 23:57 /bin/sleep
 +-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
 +# cp -p /​bin/​sleep.back2 /bin/sleep
 +# ls -l /bin/sleep*
 +-rwxr-xr-x 1 root root 39256 Sep  5  2019 /bin/sleep
 +-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>​
 ===== Advanced configuration ===== ===== Advanced configuration =====
  
Line 648: Line 713:
 ==== Rebooting WSL ==== ==== Rebooting WSL ====
  
-It is not possible to 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
  
-Rebooting ​the Windows computer will of course ​reboot ​WSL but it's useful to be able to just reboot ​WSL: +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
-  * 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''​ 
-  * to force WSL to recognize drives that were still encrypted when the first terminal was started+  * force WSL to recognize drives that were still encrypted when the first WSL terminal was opened
  
-WSL can be rebooted by using either one of the following ​methods ​(the first is the easiest!). Warning: ​all the terminals and processes ​will be closed/​​killed+WSL can be stopped ​the following ​way. Warning: ​all the open terminals and running ​processes ​will be terminated
-  * from a //Windows ​PowerShell// ​(no need to run as administrator):​\\ type ''​wsl %%--%%terminate Ubuntu''​ +  * from a Windows ​terminal ​(''​cmd'',​ ''​PowerShell'',​ ... no need to run as administrator):​ 
-  from the //Services// tab of the Task manager or the //Services// program (launch ''​services.msc''​) +    * Get the name of the installed (and running) Linux: **''​wsl %%--%%list %%--%%verbose''​** 
-    ​Right-click on the ''​LxssManager'' ​service and select //Restart// +    Stop //this instance// of Linux (e.g. if it is named //Ubuntu//): **''​wsl %%--%%terminate Ubuntu''​** 
-  from a //Powershell// in admin mode (right-click on the Windows //Start// button) +    or Stop //all// the currently running Linux distributions:​ **''​wsl %%--%%shutdown''​**
-    ​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/<​your_login>/ ​directory 
 +# 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-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>​
  
other/win10wsl.1598019461.txt.gz · Last modified: 2020/08/21 14:17 by jypeter