WSL2: Difference between revisions

From Wiki
mNo edit summary
mNo edit summary
 
(20 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Installation ==
== Links ==
# Run from Admin-PowerShell
* https://docs.microsoft.com/en-us/windows/wsl/wsl-config
<blockquote>
 
== WSL startup speed ==
<pre>
wsl --shutdown
wsl --list --running
wsl "dmesg"
</pre>
 
= Config =
* https://learn.microsoft.com/en-us/windows/wsl/wsl-config#configuration-settings-for-wslconfig
== /etc/wsl.conf ==
<pre>
<pre>
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
[boot]
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
systemd=false
wsl --set-default-version 2
 
[automount]
enabled = false      # /mnt/C
</pre>
</pre>
</blockquote>
# Update WSL Kernel
# Restart
# Install Ubuntu from Microsoft Store


== Using New Windows Terminal ==
== C:\Users\UserName\.wslconfig ==
* profiles.json
** set defaultProfile to Ubuntu
** for linux home dir:
<blockquote>
<pre>
<pre>
"commandline" : "wsl.exe ~ -d Ubuntu-18.04",
[wsl2]
memory=4GB      # Limits VM memory in WSL 2 to 4 GB
processors=2    # Makes the WSL 2 VM use two virtual processors
 
[experimental]
networkingMode=mirrored    # IPv6 support!!!
 
</pre>
</pre>
</blockquote>




<blockquote>
 
= Networking =
== Network bridge to Ethernet Adapter ==
* Enable Hyper-V
<pre>
Dism /online /enable-feature /featurename:Microsoft-Hyper-V -All /LimitAccess /ALL
</pre>
* Install Hyper-V Windows features -  "Turn Windows features on or off":
<pre>
<pre>
"profiles":
Hyper-V Management Tools > All
    [
Hyper-V Platform > All
        {
            "guid": "{c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40}",
            "source": "Windows.Terminal.Wsl",
            "name": "Ubuntu-18.04",
            "commandline": "wsl.exe ~ -d Ubuntu-18.04",
            "fontSize": 10
        },
        {
            "name": "server1",
            "commandline": "wsl.exe ~ -d Ubuntu-18.04 ssh server1",
            "fontSize": 10
        }
    ]
</pre>
</pre>
</blockquote>


== Running Linux Commands ==
* Script after every logon
* using bash.exe
<pre>
<pre>
bash.exe -c "jupyter-notebook ; /bin/bash"
set-vmswitch -name wsl -NetAdapterName Ethernet
</pre>
</pre>


* get new DHCP IP for WSL2
<pre>
sudo ip addr flush dev eth0
sudo dhclient eth0
</pre>


* using wsl
== WSL IPs ==
<pre>
<pre>
wsl jupyter-notebook &
wsl hostname -I
netsh interface ipv4 show neighbors
</pre>
</pre>


== fstab ==
== fstab ==
Line 65: Line 75:
</pre>
</pre>


== Docker in WSL ==
= Docker in WSL =
* install docker on linux
* install docker on linux
* add to ~/.bashrc
* add to ~/.bashrc
Line 77: Line 87:
</pre>
</pre>


 
= Other =
== Nmap ==
== Using New Windows Terminal ==
* Install Nmap for Windows
* profiles.json
* .bashrc:
** set defaultProfile to Ubuntu
** for linux home dir:
<blockquote>
<blockquote>
<pre>
<pre>
alias nmap='"/mnt/c/Program Files (x86)/Nmap/nmap.exe"'
"commandline" : "wsl.exe ~ -d Ubuntu-20.04",
</pre>
</pre>
</blockquote>
</blockquote>


== Linux GUI Apps on Windows ==
== Show DHCP Leases ==
<pre>
wsl.exe ~ -d Ubuntu ssh -t root@router cat /tmp/dhcp.leases && exec bash
</pre>
 
 
== Running Linux Commands ==
* using bash.exe
<pre>
<pre>
sudo apt install xrdp
bash.exe -c "jupyter-notebook ; /bin/bash"
sudo apt install xfce4 xfce4-goodies
</pre>


sudo cp /etc/xrdp/xrdp.ini /etc/xrdp/xrdp.ini.bak
* using wsl
sudo sed -i 's/3389/3390/g' /etc/xrdp/xrdp.ini
<pre>
sudo sed -i 's/max_bpp=32/#max_bpp=32\nmax_bpp=128/g' /etc/xrdp/xrdp.ini
wsl jupyter-notebook &
sudo sed -i 's/xserverbpp=24/#xserverbpp=24\nxserverbpp=128/g' /etc/xrdp/xrdp.ini
</pre>
echo xfce4-session > ~/.xsession
 
 
== Multiple Distro Instances ==
<pre>
* Settings -> Apps -> Ubuntu -> Advanced -> Reset to initial state


/etc/xrdp/startwm.sh:
wsl --list
change to:
wsl --export Ubuntu-20.04 Ubuntu_fresh_rootfs.tar.gz
  #test -x /etc/X11/Xsession && exec /etc/X11/Xsession
  #exec /bin/sh /etc/X11/Xsession
  startxfce4


sudo /etc/init.d/xrdp start
wsl --import DistroName InstallationPath Ubuntu_fresh_rootfs.tar.gz
wsl -d DistroName
</pre>
</pre>
* alternative: https://github.com/yuk7/wsldl


[[Category:Windows 11]]
[[Category:Windows 10]]
[[Category:Windows 10]]

Latest revision as of 13:41, 1 October 2024

Links

WSL startup speed

wsl --shutdown
wsl --list --running
wsl "dmesg"

Config

/etc/wsl.conf

[boot]
systemd=false

[automount]
enabled = false       # /mnt/C

C:\Users\UserName\.wslconfig

[wsl2]
memory=4GB      # Limits VM memory in WSL 2 to 4 GB
processors=2    # Makes the WSL 2 VM use two virtual processors

[experimental]
networkingMode=mirrored    # IPv6 support!!!


Networking

Network bridge to Ethernet Adapter

  • Enable Hyper-V
Dism /online /enable-feature /featurename:Microsoft-Hyper-V -All /LimitAccess /ALL
  • Install Hyper-V Windows features - "Turn Windows features on or off":
Hyper-V Management Tools > All
Hyper-V Platform > All
  • Script after every logon
set-vmswitch -name wsl -NetAdapterName Ethernet
  • get new DHCP IP for WSL2
sudo ip addr flush dev eth0
sudo dhclient eth0

WSL IPs

wsl hostname -I
netsh interface ipv4 show neighbors



fstab

z: /mnt/z drvfs rw,relatime 0 0

mount network share

mount -t drvfs '\\server\share' /mnt/share

Docker in WSL

  • install docker on linux
  • add to ~/.bashrc
# Start Docker daemon automatically when logging in if not running.
RUNNING=`ps aux | grep dockerd | grep -v grep`
if [ -z "$RUNNING" ]; then
    sudo dockerd > /dev/null 2>&1 &
    disown
fi

Other

Using New Windows Terminal

  • profiles.json
    • set defaultProfile to Ubuntu
    • for linux home dir:
"commandline" : "wsl.exe ~ -d Ubuntu-20.04",

Show DHCP Leases

wsl.exe ~ -d Ubuntu ssh -t root@router cat /tmp/dhcp.leases && exec bash


Running Linux Commands

  • using bash.exe
bash.exe -c "jupyter-notebook ; /bin/bash"
  • using wsl
wsl jupyter-notebook &


Multiple Distro Instances

* Settings -> Apps -> Ubuntu -> Advanced -> Reset to initial state

wsl --list
wsl --export Ubuntu-20.04 Ubuntu_fresh_rootfs.tar.gz

wsl --import DistroName InstallationPath Ubuntu_fresh_rootfs.tar.gz
wsl -d DistroName