First, the conclusion, the solution at the end:
Launching the browser essentially launches the graphical interface, which is also applicable to other GUI programs.
It is relatively simple to start the graphical interface in WSL environment by VCXSRV this x server, but there are still compatibility problems, the configuration still needs to be perfected.
Environment:
WIN10 System Installation ubuntu18.04 command-line tool (installed via Microsoft Store)
Background:
Reading the P445 of headfirst C (that is, Hi-c) involves the following code to launch a specific browser on different systems to launch a particular browser;
void open_url(char *url)
{ char launch[255];
sprintf(launch, "cmd /c start %s", url);
system(launch);#windows
sprintf(launch, "x-www-browser ‘%s‘ &", url);
system(launch);#linux
sprintf(launch, "open ‘%s‘", url);
system(launch);#mac os
}
Want to be able to simulate the launch of a specific browser under Linux on the Ubuntu command line.
Process:
Finally select Install Chromium-browser, an open source browser, run the following command:
$ sudo Install Chromium-browser
After the installation is complete, run:
[email protected]:~$ chromium-browser
(chromium-browser:3733): Gtk-WARNING **: 22:32:21.618: cannot open display: :0.0
Displays the cannot open display, i.e. the graphical interface cannot be opened;
Initially thought to be root permission problem, start root, run for the first time, fail;
Follow the prompts to join the--no-sandbox command, run the second time, failure, the same display cannot open display;
The results are as follows:
[email protected]:~# chromium-browser
[3764:3764:0911/223502.207627:ERROR:zygote_host_impl_linux.cc(89)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.
[email protected]:~# chromium-browser --no-sandbox
(chromium-browser:3771): Gtk-WARNING **: 22:37:11.445: cannot open display: :0.0
Here can basically determine is not the authority problem, but at that time did not respond to, still with the authority problem to explore;
① an article mentions to modify the following files separately
/usr/share/lightdm/lightdm.conf.d/50-unity-greeter.conf
/ETC/PAM.D Gdm-autologin and Gdm-password
Vi/root/.profile
Test Result: Invalid, if you are installing Ubuntu 18.04 LTS for Windows 10 (and of course there is a desktop version, interested in trying to download the command line),
Will find that they can not find the first three files, namely LIGHTDM and GDM, both the Graphics Manager package, are not installed, you have to install before you can modify, test.
② an article mentions the command "Xhost +", which grants all users access to X Window server, so that all users can use the current graphical interface.
First, you must explicitly run this command, there is a vulnerability, the hidden danger of the same Linux system.
by Xhost + "name", grant specific client permissions, but still invalid, unable to successfully start the browser.
Here, only a different way of thinking, no intention to find a package called X server,
A little understanding of the first to understand in the native Linux ecosystem, the graphical interface function is called only when needed, there is a specific protocol, configuration of a specific manager, the server can be successfully invoked, and the Windows interface and the system itself is the integration of the characteristics of a completely different.
ubuntu18.04 The following error was found after the X server was started and terminates itself:
Fatal server error:
(EE) parse_vt_settings: Cannot open /dev/tty0 (Input/output error)
(EE)
(EE)
Please consult the The X.Org Foundation support
at http://wiki.x.org for help.
(EE) Please also check the log file at "/var/log/Xorg.0.log" for additional information.
(EE)
(EE) Server terminated with error (1). Closing log file.
In fact, there is no/dev/tty0 this file, view log and according to the error message temporarily failed to find a solution, the basic determination is the interface problem;
In the middle of the attempt to install the Xinit package, trying to start X server through StartX, but always show "unable to connect to X Server:connection refused", many attempts to debug, no results.
Final Solution:
Consider a different x server, after a simple screening, found that vcxsrv is very suitable for use in WSL environment;
Do not support the Direct Bash command installation, can be downloaded after the following link to install, launch after successful installation, select display number (typically 0), until "next" until completion, at which time the server should be running in the background.
Vcxsrv Download Link https://sourceforge.net/projects/vcxsrv/
Before starting chromium, set the environment variable dispaly:
$ export DISPALY =: 0.0 #temp setting
$ sudo vim / etc / profile #permanently set
#Add the following statement, save
export DISPALY =: 0.0
$ source profile #make it effective
After the setup is complete, you can finally start the chromium successfully, but you will still see the following error message:
[1999:2014:0910/221026.556210:ERROR:bus.cc(394)] Failed to connect to the bus: Failed to connect to socket /var/run/dbus/system_bus_so
shared memfd open() failed: Function not implemented
[1999:2084:0910/221027.474278:ERROR:bus.cc(394)] Failed to connect to the bus: Could not parse server address: Unknown address type (e
nd on UNIX "unix")
libGL error: No matching fbConfigs or visuals found
libGL error: failed to load driver: swrast
(chromium-browser:1999): LIBDBUSMENU-GLIB-WARNING **: 22:10:28.019: Unable to get session bus: Unknown or unsupported transport “disa
[1999:1999:0910/221028.173247:ERROR:gpu_process_transport_factory.cc(1016)] Lost UI shared context.
[4:12:0910/221028.255848:ERROR:command_buffer_proxy_impl.cc(113)] ContextResult::kFatalFailure: Shared memory handle is not valid
Error Resolution:
First ERROR:bus.cc (394), WSL need to manually start the Dbus service before you can establish a connection to the chromium socket.
sudo service dbus start
Besides, this LIBGL error, no matching frame cache settings and views, no corresponding swrast drivers
You can see that when the OpenGL option is turned off, the error disappears, stating that WGL (the Windows own image processor) has compatibility issues with chromium.
The last part of the error message about the GPU there is no workaround, it can be clear that Ubuntu 18.04 LTS for Windows 10 does not provide GPU support, if you want developers to provide this feature, you may wish to go to the following link to cast a ticket.
https://wpdev.uservoice.com/forums/266908-command-prompt-console-bash-on-ubuntu-on-windo/suggestions/16108045- Opencl-cuda-gpu-support
In addition, when you start chromium, you will find that Chinese does not display properly, because the font library is missing and the following command repair is performed:
$ sudo apt install ttf-wqy-microhei
$ sudo apt install fonts-wqy-microhei
$ sudo apt install ttf-wqy-zenhei
Expand:
Understanding the role of X server in graphical interface invocation
Graphics start the basic architecture operating system-->x server<-x Protocol (communication between Server and manager), window Manager (GDM)-->x application
The OS makes a request to X server, and the server forwards the request through the X protocol to the Manager,manager to return the license information, such as by continuing to issue a boot process instruction to the X application, which results in a graphical interface.
To be resolved:
① Installing Linux graphics drivers such as navdia-390 to resolve swrast issues, will it conflict with Windows drivers?
② the Windows-based VCXSRV address type in the second ERROR:bus.cc (394), the Dbus library is obviously unable to resolve it, what can be done?
③contextresult do not find the relevant information, and shared memory what is the relationship?
Important Reference Links :
https://github.com/Microsoft/WSL/issues/2941
https://github.com/Microsoft/WSL/issues/1788
Https://www.ibm.com/support/knowledgecenter/ssw_aix_71/com.ibm.aix.cmds6/xhost.htm
Https://zh.wikipedia.org/wiki/X%E6%98%BE%E7%A4%BA%E7%AE%A1%E7%90%86%E5%99%A8
80606106
Https://zhidao.baidu.com/question/18378361.html
WSL using VCXSRV to start chromium browser and common error resolution (ubuntu18.04, graphical interface)