1. home page
  2. Unclassified

[Transfer from Cold King] Dark technology running Linux directly under WIN10

From the tutorial of King Ling. It's convenient for self inspection after stealing

-------------------------------

I have been working on a project of unity webplayer for some time. Various combination schemes have been tried, including Windows+Linux virtual machine, Linux+unity beta, Windows+Linux dual machine. However, no matter how you tumble, you feel uncomfortable.

Just a few days ago, after the National Day, I took a look at the legendary WSL (Windows Subsystem for Linux). I didn't want to be very amazing, so I wrote it down, shared it, and took it as a note.

If dual system development is unavoidable, WSL may be the most comfortable solution at present.

WSL Advantages/Disadvantages

The biggest advantage of WSL is seamless. Linux programs can directly access Windows disks and share port pools with Windows. In terms of user experience, it really kills several streets of virtual machines.

In terms of shortcomings, as a development system, it can really be called perfect. If you have to find faults, the biggest one is that WSL inherits all the disadvantages of Windows: slow. But after all, aren't we just using it for development?

Installation/Setup

The installation of WSL is not discussed much. Microsoft's own documents are very detailed, The portal is here However, the Windows installation instructions are too wordy. In fact, there are only two steps:

1: Open in administrator mode PowerShell , then run

 Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

After the command runs, you will be prompted to restart, and then restart.

2: Click here Download the Ubuntu package, double click Install, set the account according to the prompt, and then everything is done.

This is the ultimate user experience. Give 10086 likes to Microsoft students....

Fix the default folder creation permission problem

After installation, you will normally enter bash. But at this time, the default folder permissions of WSL are different from those of native Linux (the default folder creation permissions of Linux are 755, but the default folder creation permissions of WSL are 777). This will cause problems in a series of applications. You must deal with this problem before proceeding to the next step.

It is not difficult to solve this problem ~/.bashrc Add:

 umask 022

Modification completed ~/.bashrc After, use . ~/.bashrc Enable the setting, or directly turn off and then turn on ubuntu

Clean PATH variable to avoid interference with Linux program running

By default, WSL will automatically convert the environment variable of Windows to the PATH variable of Linux. This is a cool feature, such as running in bash $ notepad.exe , and Notepad will be enabled in Windows. However, if you install cygwin, mingw, or nodejs in Windows, there will be all kinds of mutual interference, which will cause the script to hang inexplicably. Therefore, it is also necessary to clear these variables.

This problem is not difficult to solve ~/.bashrc Add:

 export PATH = ` echo  $PATH | sed 's/:/mnt/c/[^:]*//g' `

Modification completed ~/.bashrc After, use . ~/.bashrc Enable the setting, or directly turn off and then turn on ubuntu

Enable X11

Then I ran a graphical interface. When I handled this, I really felt the power of WSL. Because it is very simple.

At first, I wanted to run KDE on WSL, but after a long time, I still had problems. Finally, I stopped masochism for the time being and got an xfce4:

 $ sudo apt-get install xfce4 xfce4-terminal

Then install X11 Server under Windows. There are several different options. Try again or VcXsrv It is best to use it. First, it is open source and free. Second, it can correctly display the icon of the program in the case of multiple top-level windows. click here Download and install.

There are some options when starting VcXsrv after installation. You can do the next step along the way. There is a page asking you four startup methods:

 one

If you want to start the entire Linux desktop, you can select the one in the lower right corner. In this way, all Linux programs can be started up like running in a virtual machine. But I prefer the default option. In this way, Linux programs look more like native Windows programs.

And then ~/.bashrc Add two environment variables in

 export DISPLAY = :0 export LIBGL_ALWAYS_INDIRECT = one

Modification completed ~/.bashrc After, use . ~/.bashrc Enable settings.

Then run xfce4-terminal You can start the console of xfce4. If you want to start the whole desktop game, you need to set the options in the screenshot above to One Window mode, and then run startxfce4

Fix Chinese display problem

Then you will find that it cannot be displayed at noon. This is simple, just install a Chinese font.

 sudo apt-get install fonts-wqy- *

Fix the problem of Chinese input method

The next troublesome problem is the input method. Programs under WSL cannot use Windows input method. But the good news is that you can install a Linux input method.

 sudo apt-get install fcitx fcitx-googlepinyin

After installation, drop the required environment variables into ~/.bashrc

 export XMODIFIERS = @im = fcitx export GTK_IM_MODULE = fcitx export QT_IM_MODULE = fcitx

Then again, the application configuration, . ~/.bashrc Then start the input method.

 $ export  $( dbus-launch )      #A user level dbus must be started before starting fcitx
 $ fcitx &

At this time, the input method should not be used because the Chinese language is not added. Open IME configuration

 $ fcitx-config-gtk3

And set google ping in.

If your Win10 system has English language, press Win+Space to switch to English language, and then press Ctrl+Space to switch to fcitx. If Win10 only has Chinese, Ctrl+Space should conflict with each other (I haven't tried). Just add languages to the system.

Last picture:

 five

Hide the original command line window you do not want

After writing the whole article, I always feel that something is missing, hahaha. It turns out that I am too used to RBTray. I don't think it's a thing anymore.

WSL will start a bash window by default, which is "obviously not easy to use". Otherwise, why install an xfce4-terminal? Right.

There are two ways to kill this window. Scheme 1: use setsid to start xfce4-terminal

 setsid xfce4-terminal ^D #Press Ctrl-d to return the unwanted bash. At this time, xfce4-terminal will not be returned

Another solution is to install one RBTray This group is really a magic weapon. As long as tens of kilos are needed, all unwanted windows are hidden. The most typical is vmware. Headless is not allowed in the free version. It doesn't matter. You can hide them directly. Ha ha ha.

Automatic X11, input method, system service

So far, basically everything can be used, but it is a little cumbersome. Every time, you need to start X11, then start the input method, and then start a series of services. Some students may have a habit of cleanliness, and the following can be ignored directly.

Auto start X11

Start XLauncher, select your favorite configuration, and then go all the way to the last step. Click Save Configuration and save it to any location.

 two

Copy the shortcut of XLauncher, right click the attribute, open the setting, and add "- run xluancher configuration save path config. xlaunch" after the target.

 three

Exit the current XLauncher, double-click the shortcut, and verify whether it is consistent with the expectation.

Move shortcut to: C: ProgramDataMicrosoftWindowsStart MenuProgramsStartUp

 four

Open the startup panel of the task manager to confirm that That's All.

Auto start input method

The self starting input method is a bit painful because WSL does not follow the standard system startup process. There are many discussions about this on the Internet, and many people suggest using vb script to solve this problem. Vbs is obviously not my dish. And even the vbs scheme itself is not so beautiful.

Based on the principle of pragmatism, let's just fool around:

open ~/.bashrc And join:

 if  ! pgrep fcitx > /dev/null ;  then    #If fcitx is not found, start a new one
     export  $( dbus-launch ) fcitx & fi

Self starting service

Then as a developer, it is necessary to start all kinds of strange things, such as MySQL. Personally, I think it is acceptable to start it manually. After all, you don't want to work on the backend every time you open the wsl, do you. But if you are too lazy to do this, just continue to transform our bashrc. (It's so dirty anyway, hahaha)

Compared with the input method problem, the difference is that you need su permission to start the service. It's easy to say that you can google sudo nopassword directly.

be without

After these steps, WSL can basically be used like a normal Linux. For the rest, I like vim and emacs. Pure bash party installs tmuxinator.

WSL Properties

IP address sharing

This should be the most surprising part of WSL. Programs in WSL can share IP with Windows. Therefore, if nginx is installed and started under WSL, it can be accessed in the Windows browser 127.0.0.1 It's pretty cool.

disk access

It is very easy to access Windows disks under Linux. All disks are mounted under/mnt. For example,/mnt/c is disk c, and/mnt/d is disk d.

However, there is a problem with accessing Windows disks under Linux. The file permissions are not correct. Copying to Linux has all executable permissions, which is a rather troublesome problem.

It is also very easy to access Linux disks under Windows C:Users<UserName>AppDataLocalPackagesCanonicalGroupLimited. Ubuntu18.04onWindows_79rhkp1fndgscLocalStaterootfs (This is Ubuntu, depending on the installed system). However, the WSL official strongly recommends not to directly access this directory, so don't bother yourself.

Disk permissions

In WSL, except for the Windows disk attached to/mnt, all have Linux standard permissions, so it has good compatibility with Linux. But don't think too much about selinux.

/The Windows disks attached to the mnt directory are all Windows permissions. For example, the permissions of all created files are 777. Special care should be taken in this area. For example, do not mix the git repository of Windows and Linux, because git will trace the executable permissions of files when they are stored in the repository.

colinux

It's really great to use WSL, but I have to mention one once called colinux Items for. But it's just a pity colinux Finally, it failed in the 32/64 bit system alternation. It's not good to remember all these years.

Unexpectedly, Microsoft has invested in such a magic weapon for several years. It's really a round trip, hahaha.

 

Reprinted from: https://mechanical-consciousness.com/2018/10/19/wsl-quick-setup-zh.html

score five , full marks 5-star
one ticket
fabulous zero
After reading and collecting, you can find it next time
  • Copyright notice: This article is published based on the Knowledge Sharing Attribution - Sharing in the Same Way 3.0 Mainland China License Agreement. Please follow this agreement for reprinting
  • Article link: https://moe.xin/1254.html [ copy ](Please indicate the source and link of this article when reprinting)
Previous:
: Next

9 comments

 gravatar

  1. The theme of blogger is very kawaii~~

    #1st floor
  2. Isn't the virtual machine very good? I think the most comfortable ones are two computers

    #2nd floor
    1. @ Sand Sea in Autumn -V - I also think the virtual machine is very good... when necessary, I moved it with the virtual machine. But the huge hard disk occupation is also a headache

  3. Update your blog( ˃̶̤́ ˂̶̤̀ )

    #3rd floor
  4. I remember you are not blog.moe.xin

    #4th floor
  5. I don't use Linux very much. I use PentestBox for penetration. It integrates some basic Linux commands. The effect is ideal. I can use most scripts. But if you want to test the unity webplayer

    #5F
    1. @ Mu Ruoxi QAQ penetration?!? Fear!!!!

  6. Big guy's domain name is really powerful :lol:

    #6th floor
    1. @ Panda A 1、 .. Generally