windows上安装和使用WSL

  • 启用WSL功能
    在Windows搜索栏中搜索“启用或关闭Windows功能”,打开该设置,然后勾选“适用于Linux的Windows子系统”选项,点击“确定”并重启你的电脑。

在线安装

  • 查看支持的linux版本
    wsl --list --online
    
  • 安装对应版本的linux系统
    wsl --install -d Ubuntu-24.04
    

离线安装

  • 手动安装:https://learn.microsoft.com/en-us/windows/wsl/install-manual
    kunlingou/huawei@123
    

使用

  • root登录(powershell 窗口)
    wsl -u root
    
  • 密码初始化
    passwd root
    
  • 执行命令
    C:\WINDOWS\System32\wsl.exe -d openEuler-22.03 -e sh -c if [ -d ~/.vscode-server/bin/7d842fb85a0275a4a8e4d7e040d2625abbf7f084 ]; then printf 'install-found '; fi; if [ -f /etc/alpine-release ]; then printf 'alpine-'; fi; uname -m;
    
  • 查看位置
    # 在linux内执行
    wslpath -w '/'
    
    # 在PowerShell执行
    Get-ChildItem -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss" | ForEach-Object {
        $distroName = (Get-ItemProperty -Path $_.PSPath).DistributionName
        $basePath = (Get-ItemProperty -Path $_.PSPath).BasePath
        Write-Host "发行版: $distroName, 路径: $basePath"
    }
    
  • windows访问wsl的文件
    \\wsl.localhost\openEuler-22.03\opt
    
  • 设置wsl默认登录账号
    wsl -l
    openEuler22.03.exe config --default-user root
    
  • 停止wsl
    wsl --shutdown