How To Run CentOS 8.2 Under New WSL2?

Home » CentOS » How To Run CentOS 8.2 Under New WSL2?
CentOS 1 Comment

I want to run CentOS 8.2 (2004) under Windows 10 Pro (2004) that comes with WSL2

1. Is there a list of steps anywhere, that would help me download what I
need, and get CentOS 8.2 running under WSL2?
2. What would I need to download? (need direct URL – there are so many options for CentOS 8.2 , I am confused)
3. What steps would I need to take to get this running locally on my Windows 10 machine?

Notes:
==> I don’t want to run any existing CentOS available in the Windows store, I want to roll my own
==> I don’t want to run CentOS 8.2 under VirtualBox or any other virtualization technology, just WSL2
==> I don’t want to download any .zip from a previous release that is not CentOS 8.2, ideally would like to be self-sufficient and gain the knowledge on how to do this myself.

One thought on - How To Run CentOS 8.2 Under New WSL2?

  • Okay, so there are a few things here. We (the CentOS Project) don’t currently publish anything that’s easily consumable into WSL2 on the mirrors or download pages. That’s probably something we should address, or at least talk about fixing. I can provide some directions below, but they’re very rough as I only started experimenting with this last night once I saw your email.

    First, create a directory on your windows system where you’re going to store your custom distro. I used C:\distros but you can use whatever makes sense to you.

    Second, you’re going to need something that can understand the xz archive format that’s used these days rather than the older gz style.
    7zip should do this fine, or optionally the tools straight from the project/author – https://tukaani.org/xz/

    Next, you’ll want to pull the tarball we use to publish images to the dockerhub. We use versions branches in this repo, so you pick what you want. Here’s the one for CentOS 8 currently ->
    https://github.com/CentOS/sig-cloud-instance-images/blob/CentOS-8-x86_64/docker/CentOS-8-x86_64.tar.xz
    (Advanced users can make their own tarballs here with livemedia-creator or whatever is preferred)

    Uncompress this archive, but don’t unpack it. You want to end up with CentOS-8-x86_64.tar

    From there, fire up a command prompt (Windows Terminal, cmd, powershell, whatever). You can import this into wsl2 by running:
    wsl.exe –import CentOS C:\distros\CentOS \path\to\CentOS-8-x86_64.tar

    At this point you’re “done” but it’s not quite there.

    if you want to stop here, you can simply run: wsl.exe -d CentOS

    It’ll work but you’ll be running as root.

    If you want to add your user, set up sudo, things like that you need to do a bit more.

    wsl.exe -d CentOS # to run it as root useradd yourusername dnf -y update dnf -y install sudo # and whatever else you want id -u yourusername # this is probably 1000
    visudo # give your new user sudo access otherwise you’ll lock yourself out.

    Now, at this point I don’t know an easy way to find the GUID of the custom distro. I cheated and used the value from Windows Terminal’s json config file. Take that GUID and your user’s UID and fire up regedit to set your user as the default.

    You’ll want to look at Computer\HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Lxss\$DISTRO_GUID
    and set DefaultUid as a REG_DWORD to your user’s uid (typically 1000).

    That’s as far as I’ve taken things so anything you want to do after this you’re kinda on your own.