windows10下安装子系统linux(centos)
<blockquote><p>前提条件:</p>
<p> 1.打开WSL</p>
<p> 1.1方式一:使用管理员权限打开 powershell,执行</p>
<pre><code class="language-shell"> Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
</code></pre>
<p> 1.2方式二:控制面板->程序->启用或关闭windows功能->找到适用于Linux的Windows子系统勾选,确定后需要重启电脑生效。</p>
</blockquote>
<h1 id="方式一微软商店安装centos">方式一:微软商店安装centos</h1>
<blockquote>
<p>微软商店的centos均需要收费,放弃。</p>
</blockquote>
<h1 id="方式二github开源工具wsl-distribution-switcher">方式二:Github开源工具WSL-Distribution-Switcher</h1>
<blockquote>
<p>注意:该方式前提是系统内需要有一个linux子系统,可以在微软商店安装免费的ubuntu。</p>
<p>原因:WSL-Distribution-Switcher需要依赖一个ubuntu,现在不装,后期也需要安装。</p>
<p>参考网址:GitHub - RoliSoft/WSL-Distribution-Switcher: Scripts to replace the distribution behind Windows Subsystem for Linux with any other Linux distribution published on Docker Hub.</p>
<p>出现下载镜像报错:cmd切换为管理员模式</p>
</blockquote>
<p>1.下载WSL-Distribution-Switcher</p>
<p> 下载地址:https://github.com/RoliSoft/WSL-Distribution-Switcher/archive/master.zip</p>
<p>2.安装python3,如果有跳过这步</p>
<p> 下载地址:Welcome to Python.org</p>
<p> 下载windows的exe执行文件直接安装即可</p>
<p>3.通过WSL-Distribution-Switcher下载Centos7</p>
<p> 3.1在WSL-Distribution-Switcher的目录下使用cmd,可以到dockerhub上去查看具体的tag,也可以在WSL-Distribution-Switcher目录下打开Redme.md查看tag。</p>
<p> 3.2.获取centos镜像和依赖镜像</p>
<p> 获取镜像-》<code>python get-source.py centos:latest</code> 或者 <code>python get-source.py centos:centos7</code></p>
<p> 获取依赖镜像-》比如<code>python get-prebuilt.py centos:latest </code>或者<code>python get-prebuilt.py centos:centos7</code></p>
<p> 3.3安装</p>
<blockquote>
<p>注意:部分镜像采用了SquashFS 格式,需要安装一个python插件。指令:<code>pip3 install PySquashfsImage</code></p>
</blockquote>
<p> <code>python install.py centos:centos7</code></p>
<p> 报错:暂未解决。。。。</p>
<p> <code>The Linux subsystem is not installed. Please go through the standard installation procedure first.</code></p>
<p><img src="https://img2020.cnblogs.com/blog/2112733/202012/2112733-20201204115608368-974803199.png" alt="" loading="lazy"></p>
<h1 id="方式三lxrunoffline工具">方式三:LxRunOffline工具</h1>
<p>1.安装LxRunOffline</p>
<pre><code>方法一:下载 https://github.com/DDoSolitary/LxRunOffline/releases 解压
方法二:powershell中运行(会安装到C:\tools下):choco install lxrunoffline
</code></pre>
<p>2.下载系统镜像</p>
<p> 例如:rootfs_centos_centos7.tar.xz</p>
<p> 方式一:https://github.com/RoliSoft/WSL-Distribution-Switcher第二步的工具可以下载</p>
<p> 方式二:https://docs.microsoft.com/en-us/windows/wsl/install-manual (微软来源)</p>
<p>3.操作目录为D:\WSL作为安装使用目录,可任意更换</p>
<blockquote>
<p>准备工作:</p>
<p> 1.将LxRunOffline.exe和rootfs_centos_centos7.tar.xz复制到D:\WSL目录下。</p>
<p> 2.如果想随处使用LxRunOffline.exe,请加入系统环境变量,则不需要拷贝LxRunOffline.exe。</p>
</blockquote>
<p>4.安装镜像</p>
<pre><code class="language-powershell">#其中 -d 后面是要安装到的目录,-f 是前面下载的镜像, -n 用来指定名称。
D:\WSL>D:\WSL\LxRunOffline.exe install -n centos7 -d D:\WSL\centos7 -f D:\WSL\rootfs_centos_centos7.tar.xz
</code></pre>
<p>5.查看镜像</p>
<pre><code class="language-powershell">D:\WSL>LxRunOffline.exe list
Ubuntu
centos7
</code></pre>
<p>6.运行镜像</p>
<pre><code class="language-powershell">D:\WSL>LxRunOffline.exe run -n centos7
</code></pre>
<p>7.卸载镜像</p>
<pre><code class="language-powershell">D:\WSL\LxRunOffline.exe uninstall -n centos7
</code></pre>
<p>8.创建快捷方式(一般命令行创建失败,则使用管理员模式打开cmd)</p>
<pre><code class="language-powershell">D:\WSL>lxrunoffline s -n centos7 -f 'C:\Users\lingyang\Desktop\centos7.lnk'
</code></pre><br><br>
来源:https://www.cnblogs.com/luckyang/p/14085095.html
頁:
[1]