1. Summarize the problem
How would I create a rootfs.tar of CentOS 7.1905 for use with wsl --import
(Windows Subsystem for Linux)
I have not found a rootfs.tar file I can download of CentOS 7.1905 in order to use with wsl --import
.
I would like to be able to roll my own rootfs.tar using the dnf command, I have spent the evening searching, trying various things.
If anyone has built a rootfs.tar file for use with WSL, please post.
mkosi (ubuntu utilility) does not work, it cannot be used to build centos images, try it.
Downloading the .raw.tar.gz file does not work with wsl --import
, try it.
I am attempting the following command in a Windows .bat file, but cannot find a suitable rootfs.tar file to use, or find a way to build one.
File: create-rootfs.bat
rem <DistributionName> <InstallLocation> <FileName>
wsl --import centos_7.6.1905 c:wslcentos7.6.1905 g:downloadscentcentosrootfs.tar
2. Provide background including what you’ve already tried.
I have spent the evening reading documentation, trying various incantations of dnf with no luck. There are no examples out there, there are places where dnf and mkosi are recommended, and links to those, but there are no actual, concrete examples that work.
4. Describe expected and actual results including any error messages.
I would like to build a rootfs.tar file of CentOS 7.6.1905, for use with wsl --import
.
I am looking for actual examples that work, that have been tried, and proven.
2
Answers
Here we can make CentOS rootfs tarball ourselves. It will be easier if you have a real Linux distribution installed in machine. But here we download a ready-made docker tarball (tar.xz) and convert it to tar.gz because WSL uses
bsdtar
to extract and install distributions. For this procedure, there should be a pre-installed distribution in WSL. Run that distribution and follow these steps as root user in/root
folder to intact file permissions.Open this CentOS docker git repository, go to latest CentOS version branch (not the master), download the
centos-7-docker.tar.xz
file.Repackage the XZ archive into a GZIP archive:
xz -d -c centos-7-docker.tar.xz | gzip -c -2 > centos-7-docker.tar.gz
Move that tar.gz folder to Windows drive:
mv test.tar.gz /mnt/c/MyFolder
Import that tar.gz file as a new distribution:
wsl.exe --import CentOS MyFolder test.tar.gz
Verify the distribution was installed:
wsl.exe --list -v
Start the container and log into it:
wsl.exe -d CentOS
dnf
is not installed in this docker file. So, userpm
oryum
to install it,yum install dnf
. Make sure Windows Firewall does not block it. For more distributions, you can see my WslInstall repository.It is possible to convert the CentOS cloud QCOW2 images to a rootfs.tar.gz.
Such QCOW2 images are found here: https://cloud.centos.org/centos/
Here is an example script that performs the conversion (requires
qemu-utils
to be installed):I also maintain scripts for other CentOS versions, as well as ready-to-import
rootfs.tar.gz
files here: https://github.com/mishamosher/CentOS-WSL