Life for Linux users can be a bit difficult. Sometimes you must-or want-to run Windows. Why Windows? Sometimes your work computer or laptop is not supported by Linux. Or it may be software. Although there are many programs that can edit Word documents, there is always a document that cannot be translated correctly. Things like video conferencing software can sometimes run on Linux, but may have fewer features.
So what would you do? Of course, you can dual boot, but this is not very convenient. If you have enough capacity, you can run Windows in a virtual machine. There is also Wine, but it usually has its own set of problems in terms of the characteristics and stability of complex programs. However, the latest version of Windows provides the Windows Subsystem (WSL) for Linux.
With WSL, you can have most of the Linux features you like in a Windows session. You just need to know how to set it up, and I will show you a method that works for me in a fairly stable version of Windows 10.
About WSL
WSL is very powerful because it provides you with a good Linux environment, and it is closely optimized with Windows. However, there are some caveats. There are actually two variants of WSL. The first version 1 worked well, but did not have full compatibility and slow disk I/O. Most ordinary programs can run, but programs such as Docker and FUSE cannot. Version 2 requires your computer to support virtualization, but it runs much faster. It also provides a real Linux kernel, so most things will run using WSL2.
If you are willing to use the latest developer version of Windows 10, you can even Run the graphics program If you are willing to run far beyond the edge. But it turns out that you don’t have to use the developer version at all. If X is good at one thing, it is to have the server run on one machine and the client run on another machine. So there is no reason not to run the X client in WSL and use a Windows-based X server to display.
First, get an X server
There is no shortage of free and commercial Windows-based X servers. I used Cygwin, and more specifically, I used a pre-configured Cygwin X11 setup called Swan.Unfortunately, the Swan project seems to no longer exist, but Segwin It still exists and works fine.
Another option is Server And several other similar projects. The best part about these is that they don’t have a lot of extra stuff. Cygwin has a lot of things that are usually very useful, but these things will duplicate what you want to install under WSL.
I suggest you run the X server first and then test it on another Linux machine or virtual machine. If you have a system like Cygwin, you can just run native applications. If your X server fails to work for some reason, WSL will not be able to use it.
Performance version 2
If you have been using WSL for a while, you should check if you are still using version 1. You can switch between versions very easily, and you can even use different versions for multiple installations. To determine which one you have, open PowerShell as an administrator:
wsl --list --verbose
You should see a line and a version number for each Linux distribution installed. If you are using version 1, please make sure that you turn on virtualization support in the BIOS, and make sure that the “Virtual Machine Platform” Windows feature is turned on. Then enter:
--set-version Ubuntu 2
Of course, use any name you see in the list, which may or may not be “Ubuntu”. This will take some time, otherwise you will receive an error message if your BIOS and Windows settings are incorrect.You can also get some instructions Download some updated kernel support. Just follow the instructions. If the command does not take long to run, you may be complaining that some settings are incorrect. You can use the list command again to verify.
The version is important because the network settings are different from the old version. Although the older WSL can be configured in the same way, you can also enjoy performance improvements. However, if your machine or operating system does not meet the requirements, you may have to stick to version 1.
You can also set version 2 as the default value of PowerShell:
wsl --set-default-version 2
If you happen to be running Windows 10 version 2004 or later, then Easier to install wsl Now. However, you still need to make sure that you are running version 2.
Connectivity
X11 clients know how to access their display through the DISPLAY variable. Usually, you will see it set to :0 or :0.0 and this is understood as the first screen on the current machine. However, this does not work here because WSL is on a virtual network different from your Windows operating system.
Basically, you need to complete three steps to make things work:
- Open port 6000 on your PC firewall, if you use one
- Tell the X server to allow connections from different computers (virtual computers in this case)
- Set the DISPLAY variable to point to the WSL address corresponding to the Windows computer
The specific steps depend on the firewall and server you are using. However, the general steps are the same for any tool you happen to use.
If you use Windows Defender Firewall, you can open port 6000 by searching the settings of Windows Defender Firewall. Select Advanced, and then create a new inbound rule for TCP port 6000. However, Windows may pop up a firewall window when you run the server for the first time, asking you whether to allow the connection. In this case, you may not have to manually configure the firewall.
Setting up access control for your X server will depend on the server you use.For Cygwin, try to run xhost +
From the Cygwin prompt. For VcXsv, you need to check the startup options that allow external connections. You may not like the idea of opening the X server, but if you can restrict firewall settings or use XAuthority files. First, let it work, and then you can strengthen security. If you are behind a home router, you can use its firewall to block things.
The DISPLAY variable is the simplest of them. A quick way to learn about the Windows IP address from the WSL side is to see how the name server is set up.Dump /etc/resolv.conf
You should see something like this:
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf: # [network] # generateResolvConf = false nameserver 172.25.32.1
This means that the DISPLAY variable should be set to 175.25.32.1:0.0, as shown below:
export DISPLAY=175.25.32.1:0.0
You can use, for example, awk
But keep in mind that the correct shell script will not set up your environment. You need to obtain a script to allow this.For example, this is a /usr/local/bin/setWinX
:
WINIP=$(awk '/^nameserver / { gsub("nameserver ",""); print; }' /etc/resolv.conf) export DISPLAY="$WINIP:0.0"
Of course, you can also schedule it to run at startup by starting .profile
:
source /usr/local/bin/setWinX
Depending on your X server and application, you may need to boot the program to use a specific output driver. For example, I heard that this line will solve some problems:
export LIBGL_ALWAYS_INDIRECT=1
Once you have a good Linux/Windows integration, you can add some Launcher support. Set your X server to start automatically, and you can happily mix and match Windows and Linux applications on the same screen.
unfair!
This does not seem fair. Getting Windows stuff to run under Linux is tricky, because Windows is shut down. Because Linux is open, it is much easier to make Linux run under Windows. Of course, sometimes you really have to actually run Linux. For example, I need to read the mouse directly and find that the way WSL routes input events is different from the regular Linux installation. Nevertheless, it still runs very well and performs very well.
This is not the first time we have studied WSL. If you are just starting out, that article has some good tips. How do you deal with using Windows and Linux? The ideal answer is that you don’t, you just stick to one of them. But please tell us what you are doing in the comments.