一、介绍:
WSL是“Windows Subsystem for Linux”的缩写,顾名思义,WSL就是Windows系统的Linux子系统,其作为Windows组件搭载在Windows10周年更新(1607)后的Windows系统中。
二、实际安装:
借鉴安装方法:Win10手动安装.appx格式UWP应用的方法 https://windows10.pro/install-appx-appbundle-uwp/
进入“设置 - 更新和安全 - 针对开发人员”设置界面。选中“旁加载应用”.然后我们就可以像安装传统的.exe程序一样双击.appx或.appbundle格式的UWP应用安装包进行安装了,按照提示点击“安装”和“启动”按钮即可。当然,你也可以运行PowerShell命令进行安装 ,命令格式如下:Add-AppxPackage .appx格式文件路径及名称.
实际安装方法:
win10 LTSC 1809安装wsl步骤:
1)在appwiz.cpl中安装wsl
2)下载https://aka.ms/wsl-ubuntu-1804 得到Ubuntu_1804.2019.522.0_x64.appx在shellpower中运行 Add-AppxPackage d:\Ubuntu_1804.2019.522.0_x64.appx(不确定这一步是否有用)。将Ubuntu_1804.2019.522.0_x64.appx文件改为Ubuntu_1804.2019.522.0_x64.zip,解压缩到D:\Ubuntu_1804.2019.522.0_x64下,运行ubuntu1804.exe
非管理员运行ubuntu1804.exe出现下面的错误:
Installing, this may take a few minutes...
WslRegisterDistribution failed with error: 0x80070005
Error: 0x80070005 ?????
解决方法:运行以上的Ubuntu.exe时采用管理员权限
管理员权限安装,ok
Installing, this may take a few minutes...
Please create a default UNIX user account. The username does not need to match your Windows username.
For more information visit: https://aka.ms/wslusers
Enter new UNIX username: ywh
Enter new UNIX password: ywh
Retype new UNIX password:
passwd: password updated successfully
Installation successful!
To run a command as administrator (user "root"), use "sudo
See "man sudo_root" for details.
此时就进入到了bash的界面,可以修改root密码了,如下:
sudo passwd root
三、几个比较重要的命令
3.1、+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
下面比较重要ubuntu1804.exe 其实是可以带参数进行运行的ubuntu config --default-user root每次启动采用root运行 这个命令只是设置好以root启动,设置完成后还需要运行ubuntu1804.exe:
D:\Ubuntu_1804.2019.522.0_x64>ubuntu1804.exe /?
Launches or configures a Linux distribution.
ubuntu1804.exe Usage:据我的观察:
第2个参数install不加--root参数,就是安装后提示输入非root用户和密码然后退出;加上install --root,直接安装完毕,不进入shell,也不提示给root用户设置密码(实际上root是设置了我们不知道的初始root密码,需要passwd修改),进入时直接bash即可。
<no args>
Launches the user‘s default shell in the user‘s home directory.
install [--root]
Install the distribuiton and do not launch the shell when complete.
--root
Do not create a user account and leave the default user set to root.
run <command line>
Run the provided command line in the current working directory. If no
command line is provided, the default shell is launched.
config [setting [value]]
Configure settings for this distribution.
Settings:
--default-user <username>
Sets the default user to <username>. This must be an existing user.
help
Print usage information.
3.2、wsl的使用
使用: wsl.exe [选项] ......
选项:
-d, --distribution <DistributionName>
启动指定的分发。
-e, --exec <CommandLine>
执行指定的 Linux 命令。其余的参数
用作命令行执行。
-u, --user <UserName>
作为指定用户运行。
--帮助
显示使用信息。
--
停止解析参数,并将其余部分传递给 Linux 进程。
3.3、 bash的使用
待补充
如何启动wsl,有2种方式,直接运行Ubuntu.exe,这种方式的默认工作目录是/home/ywh;另一种方式,在powershell或者cmd中运行wsl或bash,此时用户进入的默认方式是cmd或者powershell所在目录。
3.4、wslconfig
/t 参数使用:如果wsl ubuntu系统shell已经登录了 ,此时wslconfig /t ubuntu-18.04会将已经登录的shell踢掉。
/upgrade 参数使用如下:
D:\Ubuntu_1804.2019.522.0_x64>wslconfig /upgrade ubuntu-18.04
正在升级...
升级已成功完成。
/l, /list [/all]
列出已注册的分发版。
/all - 有选择地列出所有分发版,包括
当前正在安装或卸载的分发版。
/s, /setdefault <DistributionName>
将该分发版设为默认。
/t, /terminate <DistributionName>
终止分发。
/u, /unregister <DistributionName>
取消分发版注册。
/upgrade <DistributionName>
将分发版升级至 WslFs 文件系统格式。
四、wsl挂载U盘
挂载u盘(实际为fat32格式,实际为在windows中的路径为e:盘),如下在wsl子系统中操作:
mkdir -p /mnt/e
mount -t drvfs e: /mnt/e
mount输出如下:
C: on /mnt/c type drvfs (rw,noatime,uid=0,gid=0,case=off)
D: on /mnt/d type drvfs (rw,noatime,uid=0,gid=0,case=off)
e: on /mnt/e type drvfs (rw,relatime,case=off)
取消U盘挂载需要现在wsl中umount,然后在win10中弹出U盘。
参考:win10 wsl linux子系统可以挂载ntfs文件夹以及网络磁盘 https://www.v2ex.com/t/356158
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
五、参考:
Win10 LTSC安装WSL+oh-my-zsh https://www.cnblogs.com/wufeiyun/p/12095520.html
参考网站:
https://devblogs.microsoft.com/commandline/
https://ask.ms
https://docs.microsoft.com/zh-cn/windows/wsl/install-on-server
原文:https://www.cnblogs.com/weihua2020/p/13923252.html