win系统使用wsl子安装centos

win环境准备

  1. 搜索:启动或关闭windows功能;

  2. 打开 启动或关闭windows功能,勾选:1,适用于 Linux 的 Windows 子系统,2,虚拟机平台;

  3. 确定,重启主机。

注销旧系统

如果原来已有旧子系统,想换个新的要先注销。

在win终端下执行命令,查看当前存在的发行版。

C:\Users\root>wsl --list
适用于 Linux 的 Windows 子系统分发版:
CentOS7 (默认)

然后注销:

wsl --unregister centOS7

接下来把旧centOS7文件夹删除,然后重新解压缩一份新的再打开就可以了。

安装

CentOS-WSL下载想要的centos版本,然后解压缩,用管理员身份运行CentOS7.exe,等一会就好了。

更换yum源

备份/etc/yum.repos.d/CentOS-Base.repo

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

然后vi编辑

vi /etc/yum.repos.d/CentOS-Base.repo

复制以下代码:

# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the 
# remarked out baseurl= line instead.
#
#
 
[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#released updates 
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

然后执行:

yum makecache && yum -y update

还要安装一个东西:

yum install centos-release-scl -y

安装完成后在 /etc/yum.repos.d 目录下会出现 CentOS-SCLo-scl.repo 和 CentOS-SCLo-scl-rh.repo 两个文件,安装后源默认启用

修改CentOS-SCLo-scl.repo的baseurl

vi /etc/yum.repos.d/CentOS-SCLo-scl.repo
[centos-sclo-sclo]
name=CentOS-7 - SCLo sclo
baseurl=https://mirrors.aliyun.com/centos/7/sclo/x86_64/sclo/
# mirrorlist=http://mirrorlist.centos.org?arch=$basearch&release=7&repo=sclo-sclo
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo

修改CentOS-SCLo-scl-rh.repo的baseurl

vi /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo
[centos-sclo-rh]
name=CentOS-7 - SCLo rh
baseurl=https://mirrors.aliyun.com/centos/7/sclo/x86_64/rh/
# mirrorlist=http://mirrorlist.centos.org?arch=$basearch&release=7&repo=sclo-rh
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo

 最后刷新缓存:

yum repolist && yum clean all && yum makecache

共享文件

在wsl子系统中访问/mnt可以看到win系统下的硬盘,

通过挂载来共享文件夹。

在centos中来到/root目录下执行:

ln -s /mnt/e/testProject testProject

就可以直接在linux下修改win的文件了。

如果要删除软链,则执行:

rm testProject

注:如果有涉及到系统环境的工作比如编译工程,不要在共享目录下操作。

根据提供的引用内容,wsl2安装CentOS的步骤如下: 1. 首先,在Windows系统上启用Hyper-V功能。 2. 在Hyper-V上安装WSL2(Windows Subsystem for Linux 2)。 3. 在WSL2上安装Ubuntu分发版。可通过Microsoft Store或手动下载安装。 4. 在Ubuntu分发版上安装Docker。可以使用以下命令安装Docker: ``` sudo apt update sudo apt install docker.io ``` 5. 安装Docker后,可以使用以下命令来下载并安装CentOS7镜像: ``` sudo docker pull centos:centos7 ``` [2] 这样就完成了在WSL2上安装CentOS的过程。请注意,以上步骤仅适用于安装WSL2环境中使用CentOS镜像。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [windows下wsl2安装centos容器](https://blog.csdn.net/youaremyalllove/article/details/129699210)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] - *2* [WSL2:安装CentOS7(或任何你想安装的Linux发行版)【方法①:利用docker拉镜像,再导出】【方法②:直接利用...](https://blog.csdn.net/u013250861/article/details/129018998)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值