Ubuntu on Windows: Install Ubuntu on WSL2; XUbuntu Desktop + VcXsrv X-Server + PulseAudio Server

When you want to do cross-compiling, Ubuntu is more flexible than Windows 10. In fact, Windows 10 Pro supports Linux as its subsystem. So we can switch these two systems quite easily. If you don't want to alter your PC, you can rent a virtual PC on the cloud to do the same job. ✌️Most cloud providers have a *3 to 24* months *Free-trial* period to let you play happily😍 with your apps.

  1. Powershell
  2. Update to WSL - 2
  3. Install Ubuntu 20.04
  4. Continue to Update WSL-2
  5. Install XUbuntu Desktop(XFCE)
  6. Install XLaunch and PauseAudio
  7. Connect X Server to Xubuntu-Desktop
  8. Advance Bash Script
  9. Virtualization Disabled Bug

Powershell

Image for post

Open PowerShell as Administrator and run:


Restart your PC .

Update to WSL - 2

WSL-2 has f aster performance than WSL-1, except you want to keep the function of cross-reading the documents between Windows and Linux. Furthermore, you cannot use browser in WSL-1. So let's update to WSL-2.

Let's set WSL-2 by open PowerShell as Administrator.


It was not working and shows the help info. Then I checked OS Version.

Image for post

So I went to update my Windows right away.

Image for post

This is the right version. Let's check again.

Image for post

It's WSL-1. By instruction from Microsoft, I need to turn on Virtual Machine Platform.


Image for post

The Virtual Machine Platform has installed. Restart again…

Open PowerShell as Administrator, again.

Image for post

More requirement: I need to download wsl_update_x64.msi and run.

Image for post

I notice that I have to become an Insider to make WSL2 work. That's hidden.

Windows Insider Program

Explore the future of Windows INSTALL BUILDS Join millions of people around the world to help shape the next evolution… insider.windows.com

After I register the Insider, I choose "Get Started" to link my Microsoft account.

Image for post

Inside the settings, I need to check features.

Image for post

To make sure those red boxes are checked before the restart, AGAIN.

Image for post

You must go to section 3 to install Ubuntu at this point.

Install Ubuntu 20.04

Please enter Microsoft Store. Now, let's search for Linux and install one of them.

Image for post

Wow, there are 99 kinds of Linux 😋. I pick Ubuntu 20.04.

Image for post

After installation, the Ubuntu will ask you about username and password. Please keep that secret information in your safe sector. You can save it to the cloud in case you forget. I prefer to save a password with another substitute, such as your luck chant, instead of a plain text. For example, it can be

*plainword+@+my lucky animal*.

Continue to Update WSL-2

🏇Open PowerShell as Administrator, again.


No good, it's another error. Let's unlock the settings.


Furthermore, you need to uncompress the package.

Image for post

Next,

Image for post

Uncheck the box of "Compress contents to save disk space", so the OS will uncompress the package. It takes a while to be done depending on your CPU speed. After that, let's run the set version again.

Image for post

That's right, version 2.

Install XUbuntu Desktop(XFCE)

Without GUI, it's hard to manage the files. Ubuntu shell is just like the Windows' predecessor DOS. So we need a Linux GUI.

In the Ubuntu shell: update and upgrade


After, we can use tasksel manager, which can help us to install multiple packages all at once.


After that, you can run tasksel.


Let's pick Xubuntu desktop and check OK. Or type directly in command line,


After the installation, restart the terminal.

Install XLaunch and PauseAudio

VcXsrv is a Windows X Server.

This software will help us to load the Ubuntu Desktop. After you downloaded and installed the X server, you will see XLaunch icon.

Image for post

Let's run it.

Image for post

One large window is fine.

Image for post

"Start no client" is OK.

Image for post

It will activate the cursor in the terminal.

Image for post

Next, let's save the configuration into a "bin" folder or your folder.

Download and unzip "Pulse Audio" into a "bin" folder.

This program transfers audio signal from Linux to the X server. At bin\pulseaudio-1.1\etc\pulse folder, you need to edit *default.pa .*

Line 42:


Line 61:


Second, edit *deamon.conf* at line 39th.

Image for post

Create Batch File: *startx.bat*

In the "bin" folder, shift+rigth-click to load PowerShell.

Image for post


Image for post

You cannot run the Microsoft Store App directly by entering the name of the executable file. Please follow these steps:

  • PowerShell,

  • Notepad 123.txt and search for ubuntu:

Image for post

  • You have your file location. Next, open its *AppxManifest.xml* file.

Image for post

You need to package name and ID to call the App. For example,


This is my batch input:


Next, we need server IP for the DISPLAY and PULSE_SERVER. In Powershell,


Image for post

In the Ubuntu shell:


Go to the end of the file and input the DISPLAY and PULSE_SERVER.

Image for post

Ctrl+x to save it. Restart the Ubuntu shell.

Connect X Server to Xubuntu-Desktop

Now, let's run the *starx.bat*.

Image for post

In ubuntu shell:


Image for post

The X Server:

Image for post

Let's check the connection of the PulseAudio Server.

Image for post

Advance Bash Script

If you want to autoload the Xfce, please add "xfce4-session" at the *.bashrc*.

Image for post

Now, close all of the opened windows and run the batch file again. You shall have everything automatically opened but you have to close them manually.

However, your PC will change the host IP after you restart Windows. You have to manually change IP again and again.

😲What?!

……………………..Here is the solution.

You can grab IP from */etc/resolv.conf*


This cat command, which prints out the content of a file. We can just print the line of nameserver with grep command.


The bar separator "|" can connect commands.

The awk command can help us to print formatted text. By using the grep result as an example, "nameserver" is $1 var, and IP is $2 var. So you can awk IP by $2.


In the bash script, we can use commands. Then we can save output into a variable:


It's easy to concatenate the strings by "${A} with ${B}".


It's bad for debugging with a blank screen. So I add some echoes. The final result at the end of .bashrc will be:


When Ubuntu is booting, you see:

Image for post

🏄Isn't it looking good?

Virtualization Disabled Bug

If you restart the windows and turn on Ubuntu, you may catch this bug:


Image for post

That's the problem. Let's enable it.

Image for post

And you need to turn on Hyper-V.

Image for post

Restart. If your Ubuntu is still not working, please check your update for the new version of Windows.

Mine is Windows 10 Pro 20H2. Ubuntu is working properly.

Image for post