在开机启动目录C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp加入vbs脚本

Set ws = WScript.CreateObject("WScript.Shell")
cmd = "C:\Windows\System32\bash.exe -c ""bash /home/init.sh"""
' 运行命令不显示cmd窗口
ws.Run cmd, 0, false
Set ws = Nothing
WScript.quit

创建/home/init.sh文件

#!/bin/bash

# 自动输入sudo密码
sudo -S service ssh start << EOF
.
EOF

# 启用32bit支持
sudo service binfmt-support start

# 运行bash.exe不退出
while true
do
    sleep 600
done

开启wsl 32bit支持(通过qemu模拟, 参考https://github.com/Microsoft/WSL/issues/2468#issuecomment-374904520)

……

Continue reading