红联Linux门户
Linux帮助

体验.net core跨平台之系统环境:安装Windows10内置Linux子系统

发布时间:2017-05-13 09:55:04来源:linux网站作者:wz901234567
启用
1.启用开发者模式:在开始-设置-更新-开发者 中:
体验.net core跨平台之系统环境:安装Windows10内置Linux子系统
2.在 控制面板-程序和功能-添加/关闭windows功能中,开启Windows Subsystem for Linux (目前还是个Beta版);
体验.net core跨平台之系统环境:安装Windows10内置Linux子系统
之后会要求重启。
 
安装
这是最坑的一步。
重启之后,先将系统区域设置美国,打开cmd或着powershell,输入 lxrun /install /y 命令启动在线安装,期间会要求输入用户名密码(已安装无法截图),下载非常非常慢(100兆光纤下,区域设置为美国速度有明显提升,但依旧很慢);如果只是提示服务器连接失败,有两种选择:1是开代理(经测试本人所在公司网络需要蓝灯),2是参照:
How to install Windows Subsystem for Linux (BashOnWindows) offline on Windows
Requirements:
1.Fiddler
2.HTTP Web server (Apache/Nginx/Any other)
Downloads:
trusty-server-cloudimg-amd64-root.tar.gz(https://wsldownload.azureedge.net/trusty-server-cloudimg-amd64-root.tar.gz) – Official Ubuntu 14.04 image provided by Microsoft
trusty-server-cloudimg-amd64-root.tar.gz(https://cloud-images.ubuntu.com/trusty/current/trusty-server-cloudimg-amd64-root.tar.gz) – Daily Ubuntu 14.04 builds provided by Canonical
xenial-server-cloudimg-amd64-root.tar.gz(https://cloud-images.ubuntu.com/xenial/current/xenial-server-cloudimg-amd64-root.tar.gz) – Daily Ubuntu 16.04 builds provided by Canonical
How To:
First enable Windows Subsystem for Linux from “Program and Features” -> “Turn Windows features on or off”
Restart Windows (MS has a thing for rebooting)
Download one of the image and host it on your local web server if not done already
Start Fiddler and enable “Automatic Breakpoints” (Alt+F11)
Start command prompt and run “lxrun /install /y”
Switch to Fiddler. You will see a request to “https://go.microsoft.com/fwlink/?LinkID=730581”. Click on “Headers” tab -> Right click on “Location” -> “Edit Header” -> Paste your local link URL (i.e. http://localhost/xenial-server-cloudimg-amd64-root.tar.gz) and click on Save -> Run to Completion
There will be another request to “http://localhost/xenial-server-cloudimg-amd64-root.tar.gz”.  Just click on “Run to completion” this time.
After some time, there will again another request to download “ubuntu.ico”. Just allow it.
Create a new user and you are ready to go!
Note for Ubuntu 16.04 users:
There is an issue with “sudo” command in Ubuntu 16.04 build. You will get sudo: no tty present and no askpass program specified. There are two simple possible solutions that I am aware of to fix it.
Use “sudo -S” each time. Execute
echo $'\n'"alias sudo='sudo -S'" >> ~/.bashrc
to create a permanent alias for it
Set the default user as root. Execute “LxRun.exe  /setdefaultuser root” in command prompt to do that
设置离线安装(未测试)。
昨晚的 Build 2017 介绍windows rs3更新后可以直接在商店中下载3个不同版本的Linux,应该可以拜托这种方式了。
 
使用
安装完成之后(希望大家都能安装成功),开始菜单中会有一个名为"Bash on Ubuntu on Windows"的快捷方式,指向系统文件夹中的bash.exe;打开这个bash,发现是一个命令行,尝试在其中敲一些Linux命令:
体验.net core跨平台之系统环境:安装Windows10内置Linux子系统
上面使用 cat /proc/version 查看了刚安装的Linux内核版本为4.4.0,再通过 lsb_release -a 得到发行版本为 代号xenial的Ubuntu 16.04.2 LTS,算是一个比较大众的版本
bash默认打开的终端窗口支持复制粘贴,建议通过在PowerShell输入 bash 的方式打开(注意两种方式打开时的默认路径不一样)。
尝试安装使用应用screenfetch(为了看 logo,我的最终目的当然还是安装dotnet core相关环境):
体验.net core跨平台之系统环境:安装Windows10内置Linux子系统
安装包下载的时候难免失败(几乎没有一次性过的安装,感慨天朝的网络),需要多试几次;通过su passwd拿到root权限会方便很多。
使用体验还是比较满意,比使用Hyper-v好太多。
 
继续探索
通过ifconfig、ping、curl等命令发现该子系统直接享用外部主系统网络配置,其他共享特性以及暂时不在我的研究范围之内。
子系统系统默认安装在 Uses\用户名\AppData\Local\lxss 下,暂时没有命令参数可以改变安装路径;不过我想应该可以通过 移动用户文件夹 的方式间接改变其安装盘符(系统盘满了的时候试试,有试过的请告知下结果)。
子系统默认挂载了主系统所有盘符( lxss/mnt,可读写);可创建仅字母大小写不同的文件(夹),windows 资源管理器中也能查看,但默认只能打开大写的那个,删除的时候要注意。
其他后面继续补充。
 
关于GUI桌面(不推荐)
这个子系统默认不包含桌面环境,一是因为没必要还占资源,二是这种子系统的限制。要体验Linux桌面建议还是vm走起;如果非要在这里使用,需要在外部windows中安装Xming ,然后bash中运行带有GUI的应用(如FireFox)命令的时候在前面加上 DISPLAY=:0  (如 DISPLAY=:0 FireFox )就能将GUI显示在Xming中,以此类推,桌面也是一个GUI应用,只要安装一套桌面(如 Xfce4)再执行相同命令就可以了;估计这样会很卡。
 
本文永久更新地址:http://www.linuxdiyf.com/linux/30743.html