Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save rhee-elten/f4c5f931513bb37c9f50ca1f5d95cc3c to your computer and use it in GitHub Desktop.

Select an option

Save rhee-elten/f4c5f931513bb37c9f50ca1f5d95cc3c to your computer and use it in GitHub Desktop.
# wsl boot scripts (win side, linux side) - wsl-on-boot.bat .wslconfig wsl.conf wsl-on-boot.bash
# gist: https://gist.github.com/rhee-elten/f4c5f931513bb37c9f50ca1f5d95cc3c
(1) wsl-on-boot.bat (windows side)
@rem wsl-on-boot.bat
wsl --mount \\.\PHYSICALDRIVE1 --partition 2 --name ext
wsl cat /etc/issue.net
for /f "tokens=1" %%i in ('wsl hostname -I') do set WSL_ADDR=%%i
netsh interface portproxy add v4tov4 listenport=5522 listenaddress=0.0.0.0 connectport=5522 connectaddress=%WSL_ADDR%
netsh advfirewall firewall add rule name="SSH-5522" protocol=TCP localport=5522 action=allow dir=in
wsl -u root -- service ssh start
rundll32.exe user32.dll,LockWorkStation
wsl bash --login -i -c "btm"
(2) %USERPROFILE%\.wslconfig
[wsl2]
memory=32GB
swap=0
guiApplications=false
#dnsTunneling=false
#networkingMode=mirrored
#nestedVirtualization=false
pageReporting=false
[experimental]
## autoMemoryReclaim default is 'dropCache'
autoMemoryReclaim=disabled
#autoMemoryReclaim=gradual
#autoMemoryReclaim=dropCache
(3) /etc/wsl.conf
[boot]
command="bash /wsl-on-boot.bash"
#systemd=true
[automount]
#enabled=false
[interop]
#enabled=false
#appendWindowsPath=false
[gpu]
#enabled=false
[time]
#useWindowsTimezone=false
(4) wsl-on-boot.bash
% cat wsl-on-boot.bash
:
exec > /tmp/wsl-on-boot.log 2>&1
set -x
if test "0" != "$(id -u)"
then
echo "root permission required" 1>&2
exit 1
fi
echo -1 > /proc/sys/fs/binfmt_misc/WSLInterop || true
ntpdate ntp.ubuntu.com
service ssh start
#sudo su - -c 'bash /home/rhee/Scripts/000-startup.bash' rhee
bash /home/rhee/Scripts/020-mount-nas.bash
bash /home/rhee/Scripts/025-start-docker.bash
sudo su - -c 'bash ~/Scripts/030-start-pm2.bash' rhee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment