WSL2: Difference between revisions

From Wiki
mNo edit summary
mNo edit summary
 
(13 intermediate revisions by the same user not shown)
Line 2: Line 2:
* https://docs.microsoft.com/en-us/windows/wsl/wsl-config
* https://docs.microsoft.com/en-us/windows/wsl/wsl-config


== Using New Windows Terminal ==
== WSL startup speed ==
* profiles.json
<pre>
** set defaultProfile to Ubuntu
wsl --shutdown
** for linux home dir:
wsl --list --running
<blockquote>
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>
<pre>
"commandline" : "wsl.exe ~ -d Ubuntu-20.04",
Hyper-V Management Tools > All
Hyper-V Platform > All
</pre>
</pre>
</blockquote>


* Script after every logon
<pre>
set-vmswitch -name wsl -NetAdapterName Ethernet
</pre>


== Running Linux Commands ==
* get new DHCP IP for WSL2
* using bash.exe
<pre>
<pre>
bash.exe -c "jupyter-notebook ; /bin/bash"
sudo ip addr flush dev eth0
sudo dhclient eth0
</pre>
</pre>


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


== Network bridge to Ethernet Adapter ==
 




Line 37: 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 48: Line 86:
fi
fi
</pre>
</pre>
= Other =
== Using New Windows Terminal ==
* profiles.json
** set defaultProfile to Ubuntu
** for linux home dir:
<blockquote>
<pre>
"commandline" : "wsl.exe ~ -d Ubuntu-20.04",
</pre>
</blockquote>
== 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>
bash.exe -c "jupyter-notebook ; /bin/bash"
</pre>
* using wsl
<pre>
wsl jupyter-notebook &
</pre>


== Multiple Distro Instances ==
== Multiple Distro Instances ==
Line 63: Line 130:




[[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