Windows Subsystem for Linux 简称 WSL

Windows Subsystem for Linux 简称 WSL

Microsoft loves Linux — Satya Nadella

安装方式

先启用 WSL

  • 以管理员身份运行
    Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux。
  • 图形用户界面路径
    控制面板->启用或关闭 windows 功能->适用于 Linux 的 Windows 子系统。

然后在 AppStore 中搜索 ubuntu 或者 linux,然后安装。

WSL 管理套件

在 C:\WINDOWS\system32 下

  • wsl.exe
  • wslconfig.exe

WSL 启动方式

  • 开始->Ubuntu 18.04
  • C:\WINDOWS\system32\wsl.exe
  • C:\WINDOWS\system32\bash.exe
  • CMD或PowerShell下启动wsl.exe
  • CMD或PowerShell下启动bash.exe

常用命令

查看版本

wslconfig /l      
  Legacy (默认)       
  Ubuntu-18.04      

设置默认版本

wslconfig /s Ubuntu-18.04    
wslconfig /l      
  Ubuntu-18.04 (默认)      
  Legacy    

启动

wsl -d Ubuntu-18.04 -u root      
wsl -d Ubuntu-18.04      
wsl -u root      
wsl      
bash      

访问 windows 空间

windows 的文件系统载在 /mnt 下

$ cd /mnt    
$ ls    
c  d  e  f  g  h  i  j  k    

挂载U盘

假设 window 下 d 盘是 U 盘

sudo mkdir -p /mnt/d      
sudo mount -t drvfs d: /mnt/d    

注意:目前经测试 git clone … 和 sudo git clone … 在 /mnt/d 下都无法正常工作,估计是创建文件的权限问题。

在文件夹中打开 wsl

正常情况下,安装了 wsl 后,ctrl+shift+右击弹出菜单有在此处打开Linux shell选项,可以启动 wsl。
否则可以手动添加

  1. Win+ R打开运行命令,键入 regedit ,打开注册表。
  2. 右击HKEY_CLASSES_ROOT\Directory\Background\shell,选择新建并点击项(K),命名WSL_bash
  3. 点击WSL_bash,在右侧点击默认,输入在此处打开wsl bash
  4. 右击新建的WSL_bash,选择新建,选择项(K),命名command
  5. 点击command,在右侧点击默认,输入C:\Windows\System32\wsl.exe或者 C:\Windows\System32\bash.exe

其他

wsl.exe --help       

  d, --distribution <DistributionName>                         
    启动指定的分发。    

  e, --exec <CommandLine>    
    执行指定的 Linux 命令。其余的参数    
    用作命令行执行。    

  -u, --user <UserName>    
    作为指定用户运行。    

  --help       
    显示使用信息。      

  --    
    停止解析参数,并将其余部分传递给 Linux 进程。    


wslconfig --help       

  /l, /list [/all]      
    列出已注册的分发版。      
    /all - 有选择地列出所有分发版,包括       
          当前正在安装或卸载的分发版。    

  /s, /setdefault <DistributionName>    
    将该分发版设为默认。    

  /t, /terminate <DistributionName>    
    终止分发。    

  /u, /unregister <DistributionName>    
    取消分发版注册。    

  /upgrade <DistributionName>    
    将分发版升级至 WslFs 文件系统格式。       

参考

https://docs.microsoft.com/zh-cn/windows/wsl/about
https://en.wikipedia.org/wiki/Windows_Subsystem_for_Linux

猜你喜欢

转载自blog.csdn.net/u011714033/article/details/88918269