如何在Windows WSL下安装和运行CentOS 8.2?

时间:2020-06-29 21:36:03

标签: windows windows-subsystem-for-linux centos8

问题#1 如果我想在Windows WSL下运行CentOS 8.2,我应该下载什么?

问题2 在任何地方都可以找到分步说明来显示要下载的内容,如何解压缩下载的内容以及如何组织目录结构以在Windows WSL下运行CentOS 8.2?

1 个答案:

答案 0 :(得分:0)

您可以通过 docker 镜像将其安装为 Microsoft explains

如果你想在不通过 docker 的情况下构建 centOS:

总结

  • 获取通用云图像的压缩包
  • 提取主图像并将其作为焦油
  • 导入到 wsl

详情

PS = Powershell 提示

$ = 内部 wsl 实例

安装 7zip 或其他一些存档工具来解压缩 tarball。

PS winget install 7zip.7zip

获取一份generic cloud image

PS wget https://cloud.centos.org/centos/8/x86_64/images/CentOS-8-Container-8.3.2011-20201204.2.x86_64.tar.xz

提取 layer.tar

PS 7z e CentOS-8-Container-8.3.2011-20201204.x86_64.tar.xz
# Create an install location
PS mkdir C:\wsl\centOS8
# bring in to wsl
# wsl --import wsl-name pathToInstallWSLImage pathToExtratedTar
# make sure `layer.tar` is linked
PS wsl --import centOS8 C:\wsl\CentOS8 .\path\to\previously\extracted\layer.tar
# list images
PS wsl -l -v
# set as default (optional)
PS wsl --set-default centOS8
# run it
PS wsl -d centOS8

现在在 centOS 内

# install a few dependencies mostly for user management
$ dnf install dnf-plugins-core dnf-utils findutils sudo passwd cracklib cracklib-dicts
# configure a user {youruser}
$ useradd -G wheel youruser
$ passwd
> enter a password
$ exit

回到powershell

# log in to wsl as youruser
PS wsl -d centOS8 -u youruser
# in centOS
$ id -u
1000
# in powershell set default user for wsl, match id from previous step
PS Get-ItemProperty Registry::HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss\*\ DistributionName | Where-Object -Property DistributionName -eq centOS8  | Set-ItemProperty -Name DefaultUid -Value 1000
# logging back in should default to the newly created user
PS wsl
[youruser@host wsl]$

从那里定制。