How You Can Help Test Ubuntu 20.04 LTS on WSL

This post first appeared in a series of posts on my personal blog.

There are two primary ways to try Ubuntu Focal Fossa, the codename for the release which will become Ubuntu 20.04 LTS (long term support). You can make a copy of your existing installation and upgrade it or you can download and side-load a fresh image from Canonical’s daily builds. Both methods need testing and we welcome feedback on, see: How to report a bug related to Ubuntu on WSL.

Upgrade an existing installation

We do not want to upgrade your existing working Ubuntu 16.04 or 18.04 installation at this time, not while testing. We will make a backup of your working installation, import it under a new name, and then upgrade it to Focal Fossa. This will give you the ability to switch back and forth between your working Ubuntu installation and your upgraded Focal image.

Open Command Prompt and run the following to find your WSL distro:

wsl.exe --list --all --verbose

You can see above we have Ubuntu installed as our WSL distro and and it is running on WSL 2. Don’t worry if you do not have WSL 2 yet.

Export our working installation of Ubuntu installation as a backup:

wsl.exe --export Ubuntu ubuntu-backup.tar.gz

Import our working installation of Ubuntu as our test installation:

wsl.exe --import UbuntuFocal C:\UbuntuFocal ubuntu-backup.tar.gz

If you have WSL2 enabled, instead run:

wsl.exe --import UbuntuFocal C:\UbuntuFocal ubuntu-backup.tar.gz --version 2

Explanation:

wsl.exe --import <name of your new distro> <path to store the file system> <path to tar.gz file>

And on systems with WSL 2 you can add --version 2 to ensure it is imported as WSL 2 if you have not set wsl.exe --set-default-version 2.

If you re-run the following you will see all of your WSL distros:

wsl.exe --list --all --verbose

You can run our test installation as follows:

wsl.exe -d UbuntuFocal -u <username>

Method 1: Edit /etc/apt/sources.list with nano

We upgrade this Ubuntu distro to Focal by editing /etc/apt/sources.list with nano:

$ sudo nano /etc/apt/sources.list

We want to replace all instances of ‘bionic’ with ‘focal’ so press Control [Ctrl] and backslash \ []

At “Search (to replace)” type: bionic

At “Replace with” type: focal

At “Replace this instance?” type: A

Then all instances of bionic in the text should be converted to focal:

Exit nano with Control + X then Y:

Method 2: sed

In lieu of nano you can also use the UNIX sed tool to search and replace strings within files:

$ sudo sed -i 's/bionic/focal/g' /etc/apt/sources.list

Upgrading After Methods 1 and 2

Now that sources.list is updated, we update apt to fetch the latest package listings from the focal repository:

$ sudo apt update

Then we upgrade installed packages:

$ sudo apt upgrade -y

This will take some time and is likely where some errors may occur.

Method 3: do-release-upgrade

You can use the do-release-upgrade tool:

$ sudo do-release-upgrade -d

Confirmation

To confirm the upgrade took place:

$ sudo cat /etc/os-release

When you run your working installation of Ubuntu you can switch into your test installation of Ubuntu with:

$ wsl.exe -d UbuntuFocal -u hayden

Sideload a fresh build

We will download a daily build of rootfs from the Ubuntu server and import it.

This will give you the ability to switch back and forth between your working installation and Focal.

It will not bring over any of your existing applications or dotfiles. It is a fresh start.

Open Command Prompt and run the following to see your existing WSL distro:

wsl.exe --list --all --verbose

You can see above we have Ubuntu installed as our WSL distro and and it is running on WSL 2.

Run your existing WSL distro:

ubuntu.exe

Change to a download folder on Windows (your username will vary):

$ cd /mnt/c/Users/Hayden/Downloads

Then use wget on WSL to download our rootfs tar file from the Ubuntu cloud image server:

$ wget https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64-wsl.rootfs.tar.gz

Note: If you are on arm64, use: https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-arm64-wsl.rootfs.tar.gz

Exit your WSL environment and return to the Command Prompt:

$ exit

Then import your new file into WSL:

On WSL1:

wsl.exe --import UbuntuFocal C:\UbuntuFocal Downloads\ focal-server-cloudimg-amd64-wsl.rootfs.tar.gz

On WSL2:

wsl.exe --import UbuntuFocal C:\UbuntuFocal Downloads\ focal-server-cloudimg-amd64-wsl.rootfs.tar.gz  --version 2

Explanation:

wsl.exe --import

And on systems with WSL 2 you can add --version 2 to ensure it is imported as WSL 2 if you have not set wsl.exe --set-default-version 2.

Then verify by running again:

wsl.exe --list --all --verbose

Boot the new image:

wsl.exe -d UbuntuFocal

This will drop you in as root.

Check we are on Focal:

$ cat /etc/os-release

To create a new default user, use:

$ adduser hayden

To give this user the ability to run sudo, add them to the sudo group:

$ usermod -aG sudo hayden

Finally, exit your Focal WSL distro:

$ exit

And re-enter as your new user:

wsl.exe -d UbuntuFocal -u hayden

This command also runs from your existing Ubuntu install:

You can now:

$ sudo apt update
$ sudo apt upgrade -y

and get the latest packages released in just the last few hours:

2 Likes

Hi Anton:

  1. sudo apt install gnome-terminal dbus-x11
  2. on wsl1:
    export DISPLAY=:0
    on wsl2:
    export DISPLAY=$(awk ‘/nameserver / {print $2; exit}’ /etc/resolv.conf 2>/dev/null):0
    (you can append these in .bashrc so they load automatically in the future)
  3. install and start an X server in Windows (X410, VcXsrv, or Xming)
  4. $ gnome-terminal

See the WSL wiki for more: https://wiki.ubuntu.com/WSL#Running_Graphical_Applications

1 Like

To access X on WSL2 your X client, like VcXsrv, needs to be configured to be accessible on a public network because the VM WSL2 environment is running on virtualized NAT’d subnetwork. On WSL1 it was easier because everything was on localhost. The reason I recommend X410 is because it walks you through the process of setting it up for WSL2 so it is worth a look.

Regarding your response to Anton. I get the following

posix_spawn avoided (fd close requested)

Error constructing proxy for org.gnome.Terminal:/org/gnome/Terminal/Factory0: Error spawning command line “dbus-launch --autolaunch=7ce249f544a0790428ada4b55e9ceb70 --binary-syntax --close-stderr”: Child process exited with code 1

I think wsl.exe --export Ubuntu ubuntu-backup.tar.gz does not create a tar.gz-file only a tar-file which happen to have the extension tar.gz.
So it won’t really get compressed.
You need to pipe it to a compresser that can compress from stdin (like gzip)

wsl.exe --export Ubuntu -| gzip > ubuntu-backup.tar.gz

assuming gzip.exe is in the path.

Just to elaborate:
wsl --help:

...
Arguments to manage Windows Subsystem for Linux:

    --export <DistributionName> <FileName>
        Exports the distribution to a tar file.
        The filename can be - for standard output.

    --import <DistributionName> <InstallLocation> <FileName>
        Imports the specified tar file as a new distribution.
        The filename can be - for standard input.
...

A tip to experimenting with the wsl import export functionality without having to wait for the long compression/decompression times is to install Alpine Linux from the store. It’s very small in size, ~10MB just tarred and ~5MB tar.gz’ipped.

To be honest - haven’t been able to make the --import ... -, (extract from std input), work so I just unpack the tar.gz to tarand import that.

ps: Is there an edit options for posts in discourse? (~24h edit limit for new users)

Edit:
Had a lot of problems importing it directly through tar -xOzf ubuntu-backup.tar.gz| wsl.exe --import UbuntuFocal C:\UbuntuFocal ubuntu-backup.tar.gz - so I resorted to 7zip to do the export/import thing:

wsl.exe --export Ubuntu - | 7z a -si ubuntu-backup.tar.7z

7z x -so ubuntu-backup.tar.7z | wsl --import UbuntuFocal C:\UbuntuFocal -

Can anybody in the know tell me how to do this with gzip from ubuntu(wsl session)/Git For Windows - Bash/msys2 ?
I speculate that I ran in to some weird incompatibility between the internally used tar in wsl.exe and the gzip from those mentioned tools!???

“Error- sleep: cannot read realtime clock: Invalid argument”

Solution:

sudo -i

sudo mv /bin/sleep /bin/sleep~ ; touch /bin/sleep ; chmod +x /bin/sleep

Or

Libc6 dependency issue

Follow the given commands:

wget https://launchpad.net/~rafaeldtinoco/+archive/ubuntu/lp1871129/+files/libc6_2.31-0ubuntu8+lp1871129~1_amd64.deb

sudo dpkg --install libc6_2.31-0ubuntu8+lp1871129~1_amd64.deb

sudo apt-mark hold libc6

sudo apt --fix-broken install

Again run upgrade command:

sudo apt full-upgrade

Hope, now you would be able to upgrade without any problem

Check the current version of Ubuntu WSL App:

cat /etc/os-release

Source: https://www.how2shout.com/how-to/how-to-upgrade-ubuntu-18-04-lts-to-20-04-lts-on-wsl-windows-10.html