Skip to content

Latest commit

 

History

History
269 lines (225 loc) · 7.96 KB

File metadata and controls

269 lines (225 loc) · 7.96 KB

Windows tis

Use WSL2 & Docker

  • install WSL2 on Win10

    wsl.exe --install
    • reboot, and wait to finish Ubuntu setup
    • update apt
      sudo apt update && apt upgrade -y 
  • install docker

    $ curl -fsSL https://test.docker.com -o test-docker.sh
    $ sudo sh test-docker.sh
    ...
    # IMPORTANT: if systemctl not enabled, do this: (otherwise, see how to enable systemctl on WSL2 below)
    #   use service instead
    $ sudo service docker start
    • now make docker rootless... it's painful under WSL2...
      • so I decide to add a group user...
      $ sudo groupadd docker
      $ sudo usermod -aG docker $USER 

Run ML container accelerated by NVidia CPU On WSL2

https://docs.microsoft.com/zh-cn/windows/wsl/tutorials/gpu-compute

  1. Install NVIDIA GeForce Game Ready or NVIDIA RTX Quadro Windows 11 display driver
  2. Install NVIDIA Container Toolkit
    distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
    curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
    curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
    sudo apt-get update
    sudo apt-get install -y nvidia-docker2
    
    sudo service docker restart
    • Troubleshooting
      nvidia-docker run --gpus all --rm nvcr.io/nvidia/k8s/cuda-sample:nbody nbody -gpu -benchmark
  3. Test
    nvidia-docker run --gpus all -it --rm nvcr.io/nvidia/pytorch:22.06-py3
    $ python
    >>> import torch
    >>> print(torch.cuda.is_available())
    True

SSH to Win10 WSL2

  • modify sshd port
    • /etc/ssh/sshd_config
    Port 2222
    #AddressFamily any
    ListenAddress 0.0.0.0
    ...
    PasswordAuthentication yes
  • restart sshd
    • on Ubuntu
    $ sudo systemctl restart ssh
    • on centos
    $ sudo systemctl restart sshd
  • you wsl2 ip address is something like 172.x.x.x, mine is 172.23.129.80
  • FORWARD PORTS INTO WSL2
    • from an win10 Administrator Windows prompt, add a portproxy rule
      netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport=2222 connectaddress=172.23.129.80 connectport=2222
    • You can list all your portproxy rules like this if you're concerned:
      netsh interface portproxy show v4tov4 
    • You can remove them all if you want with
      netsh int portproxy reset all
    • or remove specific one
      > netsh interface portproxy delete v4tov4 listenport=33057 listenaddress=0.0.0.0
    • BUT... the IP of wsl will change after rebooting...
      • PS: follow script NOT work
        @echo off
        
        For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%c-%%a-%%b)
        For /f "tokens=1-2 delims=/:" %%a in ('time /t') do (set mytime=%%a%%b)
        echo %mydate%_%mytime% > D:/netproxy_time.txt
        
        
        REM netproxy.bat
        REM    Run this script on start up on Windows 10
        REM    taskschd.msc , add this script to task manager
        REM    remember to check `Run with Highest Privileges`
        
        REM start ssh / docker service
        wsl.exe -u root service ssh start
        wsl.exe -u root service docker start
        
        REM fake unix $() command by BAT FOR /F
        for /f %%i in ('wsl hostname -I') do set WSLIP=%%i
        echo WSLIP is %WSLIP%
        
        for %%p in ( 2222 8001 80 33056 33057 5050 ) do (
            echo try open filewaill %%p
        
            :: (if command errors) || (exec this command)
            netsh advfirewall firewall show rule name="Open Port %%p for WSL2" >nul || netsh advfirewall firewall add rule name="Open Port %%p for WSL2" dir=in action=allow protocol=TCP localport=%%p
        
            echo netproxy %%p
            netsh interface portproxy set v4tov4 listenaddress=0.0.0.0 listenport=%%p connectaddress=%WSLIP% connectport=%%p
        )
        
        netsh interface portproxy show v4tov4
        
        REM expose some local k8s service
        REM  %~dp0 is pwd
        START /B  call %~dp0\exposeRedis.cmd
      • exposeMysql.cmd
        @echo off
        
        :1
        wsl.exe  kubectl -n ns-redis  --address 0.0.0.0   port-forward statefulset.apps/redisdb-test 6379:6379
        goto 1
  • OPEN THE FIREWALL
    • from the same Administrator Windows prompt, open an incoming Firewall Port.
    • You can do it from the Advanced Firewall Settings, but even easier you can use netsh again!
    netsh advfirewall firewall add rule name=”Open Port 2222 for WSL2” dir=in action=allow protocol=TCP localport=2222
  • delete firewall rule
    > netsh advfirewall firewall show rule status=enabled name=all | FIND /I "WSL"
    Rule Name:                            Open Port 33056 for WSL2
    Rule Name:                            Open Port 33057 for WSL2
    Rule Name:                            Open Port 8001 for WSL2
    Rule Name:                            Open Port 2222 for WSL2
    > netsh advfirewall firewall delete rule name="Open Port 33056 for WSL2"
    Deleted 1 rule(s).

Miarate WSL2 distro

  1. 管理员身份运行 cmd terminal
  2. shutdown WLS
    wsl --shutdown
  3. 导出指定发行版, e.g. Arch
    wsl -l -v
    wsl --export Arch D:\arch_backup.tar
  4. 注销(卸载)原发行版
    wsl --unregister Arch
  5. 在 D 盘创建新目录
    md D:\WSL\Arch\
  6. 导入备份到 D 盘
    wsl --import Arch  D:\WSL\Arch\ D:\arch_backup.tar --version 2
  7. 设置默认用户(避免以 root 启动), e.g. 默认用户 arch
    wsl [-d Arch]
    echo -e "[user]\ndefault = arch" | sudo tee /etc/wsl.conf
    exit
    wsl --shutdown
  8. 启动 systemd
    • 编辑 /etc/wsl.conf , 添加以下内容
    [boot]
    systemd=true

Store version terminal app Color Scheme

# home brew
        {
            "background": "#000000",
            "black": "#000000",
            "blue": "#2472C8",
            "brightBlack": "#666666",
            "brightBlue": "#3B8EEA",
            "brightCyan": "#00E5E5",
            "brightGreen": "#00D900",
            "brightPurple": "#E500E5",
            "brightRed": "#E50000",
            "brightWhite": "#E5E5E5",
            "brightYellow": "#E5E500",
            "cursorColor": "#23FF18",
            "cyan": "#00A6B2",
            "foreground": "#00FF00",
            "green": "#00A600",
            "name": "Homebrew",
            "purple": "#B200B2",
            "red": "#990000",
            "selectionBackground": "#083905",
            "white": "#BFBFBF",
            "yellow": "#999900"
        }

where does scheme config file saved ?

%LOCALAPPDATA%\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\

Normally, you can just edit/add by click 'Open by JSON'