Win10 subsystem Ubuntu's WSL2 opening, graphical interface installation and CUDA configuration


1. Win10 opens the Linux subsystem

The specific process can be found in the Windows Subsystem for Linux Installation Guide (Windows 10)

Steps

1. Enable Windows Subsystem for Linux

Before you can install a Linux distribution on Windows, you need to enable the Windows Subsystem for Linux optional feature.
Open PowerShell as administrator and run:

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

2. Check the requirements to run WSL 2

For x64 systems: Version 1903 or later, with build 18362 or later.
For ARM64 systems: Version 2004 or later, with build 19041 or later.
Versions earlier than 18362 do not support WSL 2. Use the Windows Update Assistant to update your version of Windows.

3. Enable the virtual machine function

Before installing WSL 2, the "Virtual Machine Platform" optional feature must be enabled. A computer requires virtualization capabilities to use this feature.
Open PowerShell as administrator and run:

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

Restart your computer to complete the WSL installation and update to WSL 2.

4. Download the Linux kernel update package

  1. Download the latest package: WSL2 Linux Kernel Update Package for x64 Computers
  2. Run the update package downloaded in the previous step.

5. Set WSL 2 as the default version

Open PowerShell and run the following command to set WSL 2 as the default version when installing a new Linux distribution:

wsl --set-default-version 2

6. Install the Linux distribution of choice

Open the Microsoft Store and choose your preferred Linux distribution.

Problems encountered at this step

1. Error 0x80070003 or error 0x80370102 occurs

Possible reasons:
1. Virtualization is not enabled in the computer BIOS;
2. VMware conflicts with WSL.

Solution:
1. BIOS enables virtualization, and the specific process can be Baidu by yourself;
2. This is the problem I encountered, and I have not found a way to coexist, so I can only use one at a time.
To enable WSL, use:

bcdedit /set hypervisorlaunchtype auto

To enable VMware, use:

bcdedit /set hypervisorlaunchtype off

2. Migrate the subsystem to a non-system disk

Steps

This article uses LxRunOffline, which is migrated by modifying the registry path. Project address: https://github.com/DDoSolitary/LxRunOffline

  1. Install LxRunOffline and add its directory to the environment variable Path;
  2. To view the available subsystem names, enter in PowerShell:
LxRunOffline.exe list
  1. Migrate the subsystem to the target directory:
LxRunOffline move -n <子系统名称> -d <迁移路径>
  1. Query whether the migration is successful:
LxRunOffline get-dir -n <子系统名称>

If successful, the migration address will be displayed. You can also go to the migration address in the resource manager, and there will be a file named "ext4.vhdx".

Problems encountered at this step

1. Opening the subsystem after migration may report "Access Denied"

Reason for error: WSL is not enabled
Solution: Enter in PowerShell

wsl -d <子系统名称>

to turn on the subsystem.

3. Add a graphical interface to the subsystem

installation steps

This article uses a remote desktop connection to realize the visual interface of the subsystem, enter in the subsystem terminal:

sudo apt-get update 
# 安装 xorg 
sudo apt-get install xorg 
# 安装xfce4 
sudo apt-get install xfce4 
# 安装xrdp 
sudo apt-get install xrdp
# 配置xrdp 
sudo sed -i 's/port=3389/port=3390/g' /etc/xrdp/xrdp.ini 
# 上面是配置端口

# 向xsession中写入xfce4-session 
sudo echo xfce4-session >~/.xsession 
# 重启xrdp服务 
sudo service xrdp restart
# 如果有防火墙,允许就好了。

Then use the remote desktop connection in the Win10 system to connect to " localhost:3390 " to use the graphical interface.

Problems encountered at this step

1. Remote desktop connection black screen

Possible Causes:

  1. Turn off the Win10 subsystem terminal interface;
  2. There is no operation for a long time.

Solution:

  1. Keep the terminal open while using the GUI;
  2. Restart the xrdp service after disconnection, and enter in the subsystem terminal:
sudo service xrdp restart

Fourth, subsystem CUDA installation

The official website gives the docker method, the address: https://developer.nvidia.com/blog/announcing-cuda-on-windows-subsystem-for-linux-2/ , the above page gives detailed steps.
This article uses the separate installation of CUDA Toolkit.

Steps

1. Install a graphics card driver that supports WSL on Win10

Install the graphics card driver that supports WSL on Win10, address: https://developer.nvidia.com/cuda/wsl/download , there is no need to install the graphics card driver on the subsystem.

2. Switch mirror source

Switch to the Tsinghua source https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/ , select the corresponding version, and cancel the comment, including the pre-release software source.

#备份源文件
sudo cp /etc/apt/sources.list /etc/apt/sources.bak1
#更换上面的清华镜像源,删除原有内容,粘贴清华源
sudo gedit /etc/apt/sources.list
#更新源
sudo apt-get update
#更新软件
sudo apt-get upgrade

3. Install CUDA

Find the appropriate version of CUDA Toolkit on NVIDIA's official website. This article uses CUDA Toolkit 11.1 . (Note: To install the CUDA Toolkit required for the subsystem, you must choose the installer of the WSL-Ubuntu release version)
Follow the installation instructions given on the official website to install. The following is the installation instruction for CUDA Toolkit 11.1 runfile:

wget https://developer.download.nvidia.com/compute/cuda/11.1.0/local_installers/cuda_11.1.0_455.23.05_linux.run
sudo sh cuda_11.1.0_455.23.05_linux.run

In the installation options, uncheck Driver.

4. Configure environment variables

#打开.bashrc文件
sudo gedit ~/.bashrc

#将下列内容添加至文档末尾
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-11.1/lib64
export PATH=$PATH:/usr/local/cuda-11.1/bin
export CUDA_HOME=$CUDA_HOME:/usr/local/cuda-11.1

#更新
source ~/.bashrc
#检查是否配置成功,若成功会显示CUDA版本
nvcc -V

Problems encountered in this step

1. Cannot find gcc && missing dependencies but will not be installed

Possible reason: The software source does not support this version.

Solution: Replace the latest corresponding version of the Tsinghua source, and cancel all comments, including the pre-release software source.

2. After installing CUDA, it cannot be checked

Possible Causes:

  1. The environment variable is not configured correctly;
  2. The CUDA Toolkit version does not match.

Solution:

  1. Configure environment variables according to the correct operation steps;
  2. Go to the NVIDIA official website to select the correct version, and the subsystem needs to select the WSL-Ubuntu release version.

Guess you like

Origin blog.csdn.net/lucifer479/article/details/114588753