WSL2: Difference between revisions

From Wiki
m (Marcluer verschob die Seite Windows 10/Linux Subsystem nach Windows 10/WSL)
mNo edit summary
 
(31 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Installation ==
== Links ==
# Activate Windows-Subsystem for Linux
* 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>
[boot]
systemd=false
 
[automount]
enabled = false      # /mnt/C
</pre>
 
== C:\Users\UserName\.wslconfig ==
<pre>
[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>
 
 
 
= 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>
Hyper-V Management Tools > All
Hyper-V Platform > All
</pre>
 
* Script after every logon
<pre>
set-vmswitch -name wsl -NetAdapterName Ethernet
</pre>
 
* get new DHCP IP for WSL2
<pre>
sudo ip addr flush dev eth0
sudo dhclient eth0
</pre>
 
== WSL IPs ==
<pre>
wsl hostname -I
netsh interface ipv4 show neighbors
</pre>
 
 
 
 
== fstab ==
<pre>
z: /mnt/z drvfs rw,relatime 0 0
</pre>
 
== mount network share ==
<pre>
mount -t drvfs '\\server\share' /mnt/share
</pre>
 
= Docker in WSL =
* install docker on linux
* add to ~/.bashrc
<pre>
<pre>
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
# 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
</pre>
</pre>
</blockquote>
# Restart
# Install Ubuntu from Microsoft Store


= Other =
== Using New Windows Terminal ==
== Using New Windows Terminal ==
* profiles.json
* profiles.json
Line 15: Line 94:
<blockquote>
<blockquote>
<pre>
<pre>
"commandline" : "wsl.exe ~ -d Ubuntu-18.04",
"commandline" : "wsl.exe ~ -d Ubuntu-20.04",
</pre>
</pre>
</blockquote>
</blockquote>


 
== Show DHCP Leases ==
<blockquote>
<pre>
<pre>
"profiles":
wsl.exe ~ -d Ubuntu ssh -t root@router cat /tmp/dhcp.leases && exec bash
    [
        {
            "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 ==
== Running Linux Commands ==
Line 45: Line 109:
bash.exe -c "jupyter-notebook ; /bin/bash"
bash.exe -c "jupyter-notebook ; /bin/bash"
</pre>
</pre>


* using wsl
* using wsl
Line 52: Line 115:
</pre>
</pre>


== fstab ==
 
== Multiple Distro Instances ==
<pre>
<pre>
z: /mnt/z drvfs rw,relatime 0 0
* 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
</pre>
</pre>
* alternative: https://github.com/yuk7/wsldl




== Nmap ==
[[Category:Windows 11]]
* Install Nmap for Windows
[[Category:Windows 10]]
* .bashrc:
<blockquote>
<pre>
alias nmap='"/mnt/c/Program Files (x86)/Nmap/nmap.exe"'
</pre>
</blockquote>

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