WSL
This chapter mainly introduces the method of running Linux system under Windows system.
As of June 2020, most systems have not yet installed the Windows 10 May 2020 update (build 19041), this chapter only introduces WSL.
introduction
As we all know, most of the competition practice environments in schools now build XP and other Windows operating systems, but in the NOI series, NOI Linux, a castrated version of the Ubuntu operating system, has already been used.
NOI series of activities standard competition environment
Although NOI's official website has released the ISO image of NOI Linux, if you run the virtual machine, the configuration is also quite troublesome, including the steps of activating VMware, using VMware to install the system to open the virtual machine, and NOI Linux comes with a graphical interface by default, which cannot be guaranteed It runs smoothly on low-profile systems.
Windows 10 introduced the Linux Subsystem (WSL) during its first anniversary update, and upgraded to WSL 2 in the May 2020 update. As of June 1, 2020, WSL has supported the installation of mainstream Linux distributions such as Ubuntu, openSUSE Leap, Kali, Debian...etc. But WSL does not support Arbiter for NOI evaluation.
What is the Linux Subsystem (WSL)
The Windows Subsystem for Linux (English: Windows Subsystem for Linux, WSL for short) is a compatibility layer for natively running Linux binary executable files (ELF format) on Windows 10 and Windows Server 2019.
WSL allows developers to run the GNU/Linux environment as is-including most command-line tools, utilities, and applications-without incurring virtual machine overhead.
WSL is only available in 64-bit versions of Windows 10 after version 1607. It can also be used in Windows Server 2019.
WSL or WSL 2
See: Comparing WSL 2 and WSL 1
Enable WSL
To enable WSL 2, you need to run Windows 10.
- For x64 systems: version 1903 or higher, use build 18362 or higher.
- For ARM64 system: version 2004 or higher, use internal version 19041 or higher.
- Versions lower than 18362 do not support WSL 2. Use the Windows Update Assistant to update the Windows version.
Before installing any Linux distribution for WSL, you must choose one of the following two methods to ensure that the "Windows Subsystem for Linux" optional feature is enabled:
Use Powershell
-
Open PowerShell as an administrator and run:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
-
When prompted, restart the computer.
Use GUI
-
Open "Control Panel"
-
Access the "Programs and Features" sub-menu "Turn Windows features on or off"
-
Select "Windows Subsystem for Linux"
-
Click ok
-
Reboot
Install and use Ubuntu
This chapter takes the long-term update version of Ubuntu as an example.
installation
Enter the Microsoft Store, search for "Ubuntu", then select "Ubuntu", and click "Install" to install. You can also open the Ubuntu store page .
The LTS version of Ubuntu in the Microsoft Store is a stable long-term support version of Ubuntu, and you can also choose to install it.
Run Ubuntu
Open the "Start" menu, find and launch Ubuntu, or use the wsl
command from the Windows command line to start.
initialization
The first time you run Ubuntu, you need to complete the initialization.
Wait for a minute or two, the system will prompt to create a new user account and its password, please make sure to choose an easy-to-remember password.
Basic configuration
The system that is installed for the first time does not come with any C/C++ compiler, so you need to configure the environment manually.
Replace with domestic software source
Ubuntu's default software source is abroad. The software can be replaced with domestic sources to speed, as the software source of Tsinghua TUNA .
Look for systems with their own version to match the source (available in the page sudo lsb_release -a
view Ubuntu version).
Use the following command to update the software and software source:
sudo -i
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
sudo vim /etc/apt/sources.list
# 删除内容可以按【Ctrl + A】
# (按 i 之后将上文的源右键粘贴进去,编辑完后按 Esc,再输入 :wq 和回车)
sudo apt update
sudo apt upgrade -y
Install Chinese environment
sudo apt install language-pack-zh-han* -y
sudo locale-gen zh_CN.GB18030 && sudo locale-gen zh_CN.UTF-8
sudo apt install fontconfig -y
sudo apt install ttf-mscorefonts-installer -y
# 通过Tab键,同意 EULA
# 下面的再执行一遍以防万一
sudo apt install -y --force-yes --no-install-recommends fonts-wqy-microhei
sudo apt install -y --force-yes --no-install-recommends ttf-wqy-zenhei
sudo dpkg-reconfigure locales
Use sudo dpkg-reconfigure locales
to enter the menu, press the space bar to select with zh_CN
options (recommended zh_CN, UTF-8 UTF-8
), carriage return after the election,
The next menu, select zh_CN.UTF-8
Enter.
Then close Ubuntu and restart, the system will become Chinese.
Then in turn enter the following command, to man
be replaced Chinese help page. [^ref6]
sudo apt install manpages-zh
sudo sed -i 's|/usr/share/man|/usr/share/man/zh_CN|g' /etc/manpath.config
You can use man help
the test.
Install the compilation environment
sudo apt install -y build-essential vim ddd gdb fpc emacs gedit anjuta lazarus
The following is an example program:
vim text.cpp
g++ text.cpp -o text
./text
Executable files in Linux environment may not have extensions. See the command above for the implementation method.
Advanced operation
Install a graphical environment and use a remote desktop connection
It is recommended to use xfce4 for the graphics environment, which is not bloated.
sudo apt install xfce4 tightvncserver -y
# 或使用
sudo apt install xubuntu-desktop -y
# xubuntu 安装的软件多,基础环境可用第一种
The graphics environment file is large, and it takes a certain amount of time to download and unpack.
Configure xrdp:
sudo apt install xrdp -y
echo "xfce4-session" >~/.xsession
sudo service xrdp restart
In order to prevent conflicts with the original remote desktop of the computer, it is best to change the port.
sudo sed 's/port=[0-9]{1,5}/port=qwq/' /etc/xrdp/xrdp.ini
# 其中 `qwq` 为其他端口(如 `3390`)。
sudo nano /etc/xrdp/xrdp.ini
Press [Ctrl + X], enter Y, and press Enter (save and exit).
Run sudo service xrdp restart
, then go to the Start menu, search for remote desktop connection, use localhost: 配置的端口
to access.
Log in with the user you registered earlier.
carry out.
Interact with the original hard disk partition in Windows
Hard disk partition as a folder /mnt/
in the store, so you can interact directly, such as direct compiled binary files, or to transfer files in Ubuntu.