几年没用过windows系统了,没想到现在时代已经变了,windows这种傻大粗也开始支持linux体系,可以直接开启linux子系统,丝滑切换。

现在的感受就跟mac差不多了,界面有windows窗口交互,命令行就直接切换到ubuntu terminal,虽然还是没有mac原生支持那么天然,但也已经实现了一套界面一套命令行,开发用起来应该没多大问题了。

wsl linux系统支持

开启wsl后,支持在microsft store上直接安装ubuntu,命令行直接切入ubuntu系统,在里面还能共用docker,继续开启虚拟linux系统

file

file

file

file

不错的视频

这几个十几分钟的教程不错。

WSL 2: 在windows里原生使用Ubuntu

WSL 2 with Docker: 无限套娃, 在windows中运行的ubuntu子系统里通过docker继续运行linux虚拟系统

windows powershell学习

虽然主要用linux命令,但还是得了解下windows基础的powershell语法,不至于一无所知。 这个十几分钟的教程不错。

alis别名

windows也支持常见的linux命令,ls/cp之类,其实背后都只是别名alias而已,瞒天过海。

file

file

调用基础命令

file

创建变量

file

管道复杂用法

file

不错的视频

PowerShell入门系列–学会基础的alias命令伪装成linux

PowerShell入门系列-拆解管道和别名了解复杂脚本的基础

python

执行python命令,自动弹出python13支持安装

file

PS C:\Users\colde> python --version
Python 3.13.2

python命令在windows里也是一个别名 alias

file

在windows store安装的python需要根据命令行提示修改环境变量, 在执行PATH里增加python的安装位置,然后就能在安装ipython后直接调用ipython了。

file


Windows PowerShell
版权所有(C) Microsoft Corporation。保留所有权利。

安装最新的 PowerShell,了解新功能和改进!https://aka.ms/PSWindows

PS C:\Users\colde> ipython
Python 3.13.2 (tags/v3.13.2:4f8bb39, Feb  4 2025, 15:23:48) [MSC v.1942 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 9.0.0 -- An enhanced Interactive Python. Type '?' for help.
Tip: IPython 9.0+ have hooks to integrate AI/LLM completions.

In [1]: import sys

In [2]: sys.version
Out[2]: '3.13.2 (tags/v3.13.2:4f8bb39, Feb  4 2025, 15:23:48) [MSC v.1942 64 bit (AMD64)]'

In [3]: sys.version_info
Out[3]: sys.version_info(major=3, minor=13, micro=2, releaselevel='final', serial=0)

In [4]:

wsl vpn 使用

windows上开启了vpn,但是在wsl ubuntu里无法直接连接使用,ping google无法ping通。 虽然可以在shell里配置http proxy,但还是麻烦了点,看github大家都用这个vpnkit。

https://github.com/sakai135/wsl-vpnkit

PS C:\Users\colde> wsl --import wsl-vpnkit --version 2 $env:USERPROFILE\wsl-vpnkit  .\wsl\wsl-vpnkit.tar.gz
操作成功完成。
PS C:\Users\colde> wsl -l -v
  NAME              STATE           VERSION
* Ubuntu-24.04      Running         2
  docker-desktop    Running         2
  wsl-vpnkit        Stopped         2
PS C:\Users\colde> wsl.exe -d wsl-vpnkit --cd /app wsl-vpnkit
wsl: 检测到 localhost 代理配置,但未镜像到 WSL。NAT 模式下的 WSL 不支持 localhost 代理。
+ VPNKIT_GATEWAY_IP=192.168.127.1
+ VPNKIT_HOST_IP=192.168.127.254
+ VPNKIT_LOCAL_IP=192.168.127.2
+ TAP_MAC_ADDR=5a:94:ef:e4:0c:ee
+ VMEXEC_PATH=/app/wsl-vm
+ GVPROXY_PATH=/app/wsl-gvproxy.exe
+ TAP_NAME=wsltap
+ CHECK_HOST=example.com
+ CHECK_DNS=1.1.1.1
+ DEBUG=0
+ set +x
+ WSL2_TAP_NAME=eth0
+ WSL2_GATEWAY_IP=10.255.255.254
+ '[' 0 -eq 0 ]
+ set +x
starting vm and gvproxy...
INFO[0000] waiting for packets...
time="2025-03-02T12:44:57+08:00" level=info msg="waiting for clients..."
time="2025-03-02T12:44:57+08:00" level=info msg="new connection from remote to 42796"
started vm and gvproxy
check: ✔️ ping success to IPv4 WSL 2 gateway / Windows host (10.255.255.254)
check: ✔️ ping success to IPv4 Windows host (192.168.127.254)
check: ✔️ ping success to IPv4 gateway (192.168.127.1)
check: ✔️ nslookup success for example.com A using 192.168.127.1
check: ✔️ nslookup success for example.com A using 10.255.255.254
check: ❌ nslookup fail for example.com A using 1.1.1.1
check: ✔️ ping success to IPv4 external host domain (example.com)
check: ✔️ ping success to IPv4 external host IP (1.1.1.1)
check: ✔️ nslookup success for example.com AAAA using 192.168.127.1
check: ✔️ nslookup success for example.com AAAA using 10.255.255.254
check: ❌ nslookup fail for example.com AAAA using 1.1.1.1
ping: bad address 'example.com'
check: ➖ ping fail to IPv6 external host (example.com)
wget: server returned error: HTTP/1.0 400 Bad Request
check: ❌ wget fail for http://example.com
487B5146267F0000:error:0A000438:SSL routines:ssl3_read_bytes:tlsv1 alert internal error:ssl/record/rec_layer_s3.c:1605:SSL alert number 80
ssl_client: SSL_connect
wget: error getting response: Connection reset by peer
check: ❌ wget fail for https://example.com

然后wsl里的ubuntu就能访问google了

file

wsl import 其实是个docker镜像包

https://github.com/sakai135/wsl-vpnkit

看了一下vpn toolkit的github代码,原来打包用来import的tar其实是个docker镜像包。

  • sakai135/wsl-vpnkit/distro/alpine.dockerfile
FROM docker.io/library/alpine:3.17.2 as gvisor-tap-vsock
WORKDIR /app/bin
RUN wget https://github.com/containers/gvisor-tap-vsock/releases/download/v0.6.1/gvproxy-windows.exe && \
    wget https://github.com/containers/gvisor-tap-vsock/releases/download/v0.6.1/vm && \
    chmod +x ./gvproxy-windows.exe ./vm
RUN find . -type f -exec sha256sum {} \;

FROM docker.io/library/alpine:3.17.2
RUN apk update && \
    apk upgrade && \
    apk add iproute2 iptables && \
    apk list --installed && \
    rm -rf /var/cache/apk/*
WORKDIR /app
COPY --from=gvisor-tap-vsock /app/bin/vm ./wsl-vm
COPY --from=gvisor-tap-vsock /app/bin/gvproxy-windows.exe ./wsl-gvproxy.exe
COPY ./wsl-vpnkit ./wsl-vpnkit.service ./
COPY ./distro/wsl.conf /etc/wsl.conf
ARG REF=https://example.com/
ARG VERSION=v0.0.0
RUN find ./ -type f -exec sha256sum {} \; && \
    ln -s /app/wsl-vpnkit /usr/bin/ && \
    echo "$REF" > ./ref && \
    echo "$VERSION" > ./version
  • sakai135/wsl-vpnkit/build.sh
    
    #!/bin/bash -xe

run from repo root

./build.sh

: "${DOCKER:=docker}" # docker/podman command (default: docker)
DUMP=wsl-vpnkit.tar.gz # exported rootfs file
TAG_NAME=wslvpnkit # build tag
BASE_DISTRO=$1

build

build_args=()
[ -z "${http_proxy}" ] || build_args+=( –build-arg http_proxy="${http_proxy}" )
[ -z "${https_proxy}" ] || build_args+=( –build-arg https_proxy="${https_proxy}" )
[ -z "${no_proxy}" ] || build_args+=( –build-arg no_proxy="${no_proxy}" )
${DOCKER} build –network host "${build_args[@]}" –tag ${TAG_NAME} –file ./distro/$BASE_DISTRO.dockerfile .
CONTAINER_ID=$(${DOCKER} create ${TAG_NAME})
${DOCKER} export "${CONTAINER_ID}" | gzip > ${DUMP}
${DOCKER} container rm "${CONTAINER_ID}"
ls -la ${DUMP}


## windows vim

使用命令行缺少vim总是麻烦,发现直接安装下载安装vim,然后配置环境变量PATH,也能够直接识别了。

![file](https://gee.cool/wp-content/uploads/2025/03/image-1740894760492.png)

https://www.vim.org/download.php

```bash
PS C:\Users\colde\wsl> ls

    目录: C:\Users\colde\wsl

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----          3/2/2025   1:51 PM           1540 .wsl-vpnkit-bash.ps.un~
-a----          3/2/2025   1:51 PM             44 wsl-vpnkit-bash.ps
-a----          3/2/2025  12:51 PM             43 wsl-vpnkit-bash.ps~
-a----          3/2/2025  12:41 PM       10849802 wsl-vpnkit.tar.gz

PS C:\Users\colde\wsl> vim .\wsl-vpnkit-bash.ps
PS C:\Users\colde\wsl>

vscode

vscode支持通过wsl插件无缝打通wsl ubuntu和windows

file

file

By gee

千里快哉风

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注