Wiki
Linux Installation Tutorial
Existing English translations were reused. 8 current source blocks remain in Simplified Chinese, without triggering paid translation.
1.Physical machine (dual system, most recommended)
1.1.Environment Preparation
-
Leave at least 160GB of hard disk space (it can be the same hard disk as Windows, or a separate hard disk)
-
A USB flash drive larger than 8GB with nothing stored on it (optional)
-
A smart brain

1.2.Disable Secure Boot
If it is not listed below, you can search on Bilibili for how to disable Secure Boot on your own brand of computer.
1.2.1.Lenovo Legion
1.2.2.Dell Inspiron Gaming Intel Edition
Shut down the computer, then at the instant you press the power button, keep pressing F12 repeatedly (press it rapidly over and over) until a white BIOS screen appears.
EnterBIOS SETUP, findBoot Configuration,then scroll down and find theEnable Secure Bootoption, and just turn it off.
Then click theApply Changesbutton below, and then click theEXITbutton in the lower right corner to restart.



1.2.3.HP OMEN
1.2.4.ASUS TUF Gaming
Press F2 repeatedly during startup to enter BIOS mode, then find and open Advanced Mode in the lower right corner

Disable Safe Mode

1.3.Enable integrated graphics
When installing Linux, it is recommended to keep the integrated GPU enabled to prevent issues with Linux graphical display.
You can check whether your integrated GPU is enabled by opening Task Manager. (Thin-and-light laptops don't need to worry about this; their integrated GPU is definitely enabled.)
① If you have an Intel CPU, then here GPU0 or GPU1 will display intel xxxxxx. This is correct.
② If you have an AMD CPU, then GPU0 or GPU1 here will display amd xxxxxx. This is correct.
③ If you find that your GPU0 starts with NVIDIA and there is no GPU1, it means you have disabled the integrated graphics. Please follow the steps below to disable discrete GPU direct connection and enable the integrated GPU. (If you have an AMD discrete GPU, it doesn't matter; whether discrete GPU direct connection is enabled or not makes no difference, so you don't need to worry about it. However, it is impossible for most people to have an AMD discrete GPU, so this option can basically be ruled out.)
For many gaming laptops, discrete GPU direct connection is supported, so the integrated GPU may already be disabled by default, allowing only the discrete GPU to operate. Therefore, in this case you need to disable discrete GPU direct connection and enable the integrated GPU (discrete GPU direct connection provides a significant improvement for gaming).
If you are sure that you have indeed enabled discrete GPU direct connection, please refer to the solutions for different computer brands below.
If it is not listed below, you can search on Bilibili for how to switch your brand of computer to hybrid output mode.
1.3.1.Lenovo Legion
Enter Lenovo PC Manager or Lenovo Vantage and switch the graphics output mode to hybrid output.
Then restart and check Task Manager to confirm whether the integrated graphics has been enabled.
1.3.2.Dell Inspiron Gaming Intel Edition
Shut down the computer, then at the instant you press the power button, keep pressing F12 repeatedly (press it rapidly over and over) until a white BIOS screen appears.
Enter BIOS settings, findDisplaythen scroll down and findEnable Hybird Graphicthis option, just enable it. Then clickApply Changesand exitEXIT.


After restarting again, open Task Manager to confirm whether the integrated GPU has been enabled.

1.3.3.Dell G Series AMD Edition
1.3.4.HP OMEN
1.3.5.ASUS TUF Gaming
Enter the advanced settings mode of BIOS
Advanced-Display Mode-Dynamic

Save and exit

1.4.Install ADK
https://learn.microsoft.com/zh-cn/windows-hardware/get-started/adk-install





Before downloading, you can turn off your VPN; this may route through a domestic network, which may speed up the download. (If your node is fast enough, downloading via the external network may be faster.)


Also download the following one





This completes the installation; you can reopen AOMEI.
1.5.Download DiskGenius
On a Windows system, open Baidu, search for DiskGenius, and download it.



Find a purely English directory to create a DiskGenius folder. It is recommended to create a new DiskGenius folder under the Program Files folder in any disk partition.

Extract all files from the archive just now into this DiskGenius folder.

Right-click and hold on it, drag it to the desktop, then let go.

Click here to create a shortcut.

Open this shortcut

This completes the installation successfully.

1.6.Download AOMEI Partition Assistant


After downloading, extract it to a location (the desktop is fine), then double-click to open it.

If you want to install to the C drive, simply click Install Now.
If you want to install to the D drive, just change the C at the beginning of the default path to D.

After the installation is complete, you can open the software.

Just delete that installer package .exe.

1.7.Download Ventoy


If you cannot access the interface below, please ensure your network environment (use something that can bypass the GFW, you know what I mean).

Find a directory with only English characters and create a Ventoy folder. It is recommended to create a new Ventoy folder under the Program Files folder in any disk partition.

Extract the contents of the archive you just downloaded to here.

Right-click and drag it to the desktop, then release. Then click Create Shortcut.

Double-click the shortcut to open it. This completes the installation.

1.8.Download image
Baidu Search bfsu mirror

1.8.1.X86_64(amd64)
- Ubuntu KDE 22.04 (Kubuntu) is more recommended







- Ubuntu Gnome 22.04




- Fedora KDE

Click the folders below in sequence; the 42 is the version number, just select the latest version.


1.9.Hard Drive Partition Installation Solution
Focus on the red text. You don't need to worry about the other content.
| Scenario classification | Scenario | Disk allocation | EFI partition source | Linux partition scheme | Notes |
|---|---|---|---|---|---|
| Partitioning on the same disk | ① Same disk, Windows is already installed at the beginning of the disk | Disk 1: the first half is Windows' C drive, D drive, etc.; create a new partition at the end for Linux | Reuse Windows' existing EFI partition (usually 100–300MB, FAT32, mounted at /boot/efi) | Create new / (ext4) + swap (optional) | When installing the Linux bootloader, select the existing EFI partition to avoid overwriting Windows boot files. |
| Mixed partitioning across different disks | ② Two disks, install Linux at the end of the second disk, with Windows data stored at the front, such as the E drive | Disk 1: Windows system + EFI; Disk 2: the front is the Windows data area, and the end is allocated to Linux | Reuse the EFI partition on Disk 1 | Create new / + swap on Disk 2 | The bootloader is still written to the EFI on Disk 1; during installation, be especially careful not to install EFI to Disk 2. |
| Independent partitioning across different disks | ③ Two disks, the second disk is completely empty | Disk 1: Windows system + EFI; Disk 2: entirely for Linux | Reuse the EFI partition on Disk 1 (recommended), or create a new EFI partition on Disk 2 (dual EFI coexistence is suitable for advanced users) | Create new / + swap on Disk 2 | If creating a new EFI, you need to manually adjust the boot order in /BIOS/UEFI; it is more flexible, but slightly more complicated. |
You need to confirm which case applies to you. In the tutorial below, I will use scenario one as an example; other cases are similar.
───────────────────────────────────────────────────
场景1:同硬盘分区(单硬盘)
磁盘布局:
[EFI(共享)] [Win C:] [空闲区域] [Linux Swap] [Linux /]
│ │ │ │
└──────┴───────────────┴─────────────┘
↑ 所有系统共用此EFI分区(挂载至/boot/efi)
───────────────────────────────────────────────────
场景2:异硬盘混合分区(双硬盘)
硬盘1: [EFI(共享)] [Win C:] [D: Win存储区]
│
硬盘2: [E: Win存储区 [Linux Swap] [Linux /]
↑
└─ Linux安装时挂载硬盘1的EFI至/boot/efi
───────────────────────────────────────────────────
场景3:异硬盘独立分区(双硬盘)
硬盘1: [EFI_Win] [Win C:]
│
硬盘2: [Linux Swap] [Linux /]
│ │
└──────────┘
↑ 非独立EFI分区(Linux安装时挂载硬盘1的EFI至/boot/efi)
───────────────────────────────────────────────────
场景3:异硬盘独立分区(双硬盘)
硬盘1: [EFI_Win] [Win C:]
│
硬盘2: [EFI_Linux] [Linux Swap] [Linux /]
│ │
└──────────┘
↑ 独立EFI分区(需手动配置UEFI启动顺序,适合老鸟)
───────────────────────────────────────────────────
1.10.Create installation media
1.10.1.Method 1: USB flash drive method
(If there is no USB drive, refer to the local method)
To be translated, almost not much different from the local law.
1.10.1.1.Create a Ventoy USB drive
Insert a USB flash drive larger than 8GB into the computer, then open Ventoy, select the USB drive, and click Install. (Note that this process may format the USB drive, so back up your data first, and after Ventoy installation is complete, simply move the data back.)

1.10.1.2.Install MicroPE and download the WinPE image

Click to download version 2.3

If you have money, you can donate; if you don't, you can refrain from donating for now, or pretend you donated by clicking "Donated."



After downloading, copy the downloaded exe to the drive where you want to store the software (e.g., C drive) under Program Files, and create a new WePE folder to store it.

Double-click to open the exe file

Select output location

Select desktop and save



Then go to the desktop, copy the image you just generated to the USB drive. Do not place it in any folder on the USB drive; just place it directly on the USB drive.
For example, my USB drive is drive H.

1.10.1.3.Copy the Linux image ISO
Then also copy the Linux installation image you downloaded above to the USB drive.

1.10.1.4.Set the Ventoy boot entry
Insert the USB drive into the computer, restart the computer, and then open DiskGenius.
Click the工具option in the navigation bar, then click设置UEFI BIOS启动项.
Find the USB flash drive. For example, my USB flash drive is aigo, so I should select aigo.
Then click to start from this boot entry next time, and restart.

Entering this interface indicates success.

1.10.1.5.Boot a Linux installation media image in Ventoy
Find the Linux image you want to install, such as kubuntu22.04, then press Enter to continue

Then press Enter again.

Entering the interface below indicates success.

1.10.2.Method 2: Local Method
1.10.2.1.Local method creation
This method creates a local partition for storing installation media (installation files), sets up booting for that partition, and thereby installs the Linux system.
The partition divided here is not the partition where Linux is placed. What is placed is the file for installing Linux. (similar to an installation package)
- Check how much space is left on the drive where you want to place the installation media (that is, the installation files, about 8 GB; it is recommended to use the C drive). For example, I still have 231 GB left.

- 然后打开傲梅分区助手,选中你想要放置8GB安装介质的磁盘分区(比如我选的是C盘),然后点击右边的调整/移动分区。

- Click the button to the right of the partition size


- Calculation
分区后的未分配空间
①If you do not plan to install Linux on this disk partition (for example, in my case, the C drive) (that is,硬盘分区安装方案的场景②and 3️⃣),
Then you only need to subtract 8 GB from the分区大小in the figure below, making分区后的未分配空间become 8 GB.
(If you plan to install Linux on a partition of this disk, that is硬盘分区安装方案的场景① then read on and use method ②)

② If you plan to install Linux on this disk partition, then you need to calculate exactly how much space to compress.
分区后的未分配的空间=8GB+打算给Linux的空间大小。
For example, if my remaining disk partition space is 231GB and I plan to allocate 100GB to Linux (this is just an example; in practice, don't give Linux such a small amount of space—at least 160GB), then I need分区后的未分配的空间\=8GB+100GB=108GB. Then I need to subtract 108GB from分区大小to make分区后的未分配的空间\=108GB.

- Then click OK to partition, and next click Submit in the upper left corner of the main interface.

- Then click Execute.

-
Because I am modifying drive C, I need to enter WinPE to perform the operation, If you are not operating on drive C, you may not need to do this step . (If you cannot select the Windows PE button, please check the tutorial above to see whether ADK was installed successfully.)


Waiting for PE creation to finish

It will automatically enter PE to perform partitioning operations.
Check Auto-fix errors in partitions and Check Automatically shut down after completing the operation, then wait for the progress bar to finish.


- Then, after booting up, you can see that the disk partition I compressed has become smaller; mine is the C drive, as shown in the figure below. You can see that an unallocated space has appeared after the C drive.

- Click this unallocated space, then click Partition

- Allocate an 8GB disk partition in FAT32 format to it. (Remember the drive letter, for example, mine is drive D.)



- Then find the Linux installation media .iso you downloaded and double-click to open it. (Or right-click on
装载mount).

- Then go to This PC and locate the mounted image, and click to open it.

- Then open this disk partition in FAT32 format.

- Copy all contents in the image to a FAT32 disk partition.

- Right-click mirror
弹出EjectVirtual mirror.

- Then open DiskGenius, click on the navigation bar's
工具option, and then click设置UEFI BIOS启动项.


- Click to add a startup item, and for the file path, select the FAT32 partition from earlier (for example, mine is drive D).


- Find in order /EFI/boot/bootx64.efi

- You can name it Linux Install, click Save, and select to use this boot entry as the first option on the next restart.

- After rebooting, you can see that the Linux installation interface has been entered below.

After restarting, it looks like this, which means it has entered the installation interface. (For scenario ① of the hard disk partition installation plan, installation can already begin at this point; for those who have not yet reserved installation space for Linux, please press the power button to shut down and restart back into Windows.)
If the installation failed and you still want to enter this installation interface, then in DiskGenius, as above, select the boot entry in the BIOS UEFI settings, check 下一次从该项启动, and then restart.

1.10.2.2.Delete the local installation media (delete it after installation is complete)
When you use the local method to install Linux, after completing the Linux installation, you need to delete this 8GB FAT32 space that was allocated.
Open AOMEI Partition Assistant.


Then find the C drive and click Adjust Partition.

Then return all the remaining free space to the C drive.



1.11.Reserved Linux installation space
1.11.1.Scenario ① of the hard disk partition installation scheme
───────────────────────────────────────────────────
场景1:同硬盘分区(单硬盘)
磁盘布局:
[EFI(共享)] [Win C:] [空闲区域] [Linux Swap] [Linux /]
│ │ │ │
└──────┴───────────────┴─────────────┘
↑ 所有系统共用此EFI分区(挂载至/boot/efi)
───────────────────────────────────────────────────
If you are using Local Method + Scenario 1, this place has already been created (as shown below), so skip this section.

But if you are using the USB drive method, continue reading below.
Scenario one is installing it on the same hard drive as Windows.
- Open AOMEI Partition Assistant. Locate the Windows hard drive where you want to install Linux. Click Move Partition.

分区后的未分配空间This is the space where you want to install Linux. You can change the partition size by setting the partition size or dragging the graphical button below.

- Then click OK to partition, and next click Submit in the upper left corner of the main interface.

- Then click Execute.

- Because I am modifying the C drive, I need to enter WinPE to perform the operation, If you are not operating on the C drive, you may not need to do this step . (If you cannot select the Windows PE button, please refer to the tutorial above to see whether ADK was installed successfully?)


Waiting for PE creation to finish

It will automatically enter PE to perform partitioning operations.
Check Auto-fix errors in partitions and Check Automatically shut down after completing the operation, then wait for the progress bar to finish.


- Then, after booting up, you can see that the disk partition I compressed has become smaller; mine is the C drive, as shown in the figure below. You can see that an unallocated space has appeared after the C drive.

1.11.2.Scenario ② of the hard disk partition installation scheme
───────────────────────────────────────────────────
场景2:异硬盘混合分区(双硬盘)
硬盘1: [EFI(共享)] [Win C:] [D: Win存储区]
│
硬盘2: [E: Win存储区 [Linux Swap] [Linux /]
↑
└─ Linux安装时挂载硬盘1的EFI至/boot/efi
───────────────────────────────────────────────────
As in scenario one, just compress and unmount the latter part of your second hard drive as in scenario one.
1.11.3.Scenario 3️⃣ of the hard disk partition installation scheme
───────────────────────────────────────────────────
场景3:异硬盘独立分区(双硬盘)
硬盘1: [EFI_Win] [Win C:]
│
硬盘2: [Linux Swap] [Linux /]
│ │
└──────────┘
↑ 非独立EFI分区(Linux安装时挂载硬盘1的EFI至/boot/efi)
───────────────────────────────────────────────────
场景3:异硬盘独立分区(双硬盘)
硬盘1: [EFI_Win] [Win C:]
│
硬盘2: [EFI_Linux] [Linux Swap] [Linux /]
│ │
└──────────┘
↑ 独立EFI分区(需手动配置UEFI启动顺序,适合老鸟)
───────────────────────────────────────────────────
Simply delete all partitions on the entire second hard drive and format it.
1.12.Install Linux
Take Kubuntu 22.04 (Ubuntu KDE 22.04) as an example; other distributions are actually pretty similar.
1.12.1.GRUB settings
Press E on the interface below.

Add after this line noauto toram
Thisnoautomust be written. ThattoramIf your computer's memory is greater than or equal to 16GB (be cautious if it is less than 8GB, as it may crash), then you can fill it in, and the installation speed will increase by 200+%, or even 300+%, or even without limit.

Then press crtl+X to start the system.
1.12.2.Basic Installation Options
Here it is definitely better to choose English as the language. (This way all folders under the /home partition will be in English, and no Chinese will appear.)
Then select Install Kubuntu.

Click continue

To connect to the network, first click "connect to this network", then find the WiFi name, enter the password, click "connect" on the right. After "connected" appears, click "continue".

Just choose the same as I did here.

1.12.3.Partition settings (Important!!!)
1.12.3.1.Use the same EFI partition as Windows
####### Initial Setup Select Manual here; we'll partition manually.


Find the disk area we previously reserved for Linux, for example mine is the area where 100GB was reserved, with an approximate size of 107452MB. Be sure not to select the wrong disk area. If yours here is not free space , then left-click to select it and click delete.

####### Creating a swap partition Select this area, then double-click or click the Add button.
use as optionswap area.
Partition the swap area. For this Size, please enter your内存大小(运存大小)+2GB(单位MB); for example, if my computer's memory is 32GB, then 32+2=34GB, then use34*1024=34816MB,so enter34816.
tips (optional to read): The reason for doing this is to enable the Linux hibernation feature. If your swap partition size is set incorrectly, the Linux hibernation feature may have problems.

####### 根目录/分区建立 再选中剩余的这块区域,双击或者点击Add按钮。

use as choose ext4
Then select the mount point/(that is, the root directory)
Just use the default for Size (the default is to allocate all remaining maximum capacity to根目录).

####### Unmount other irrelevant partitions As shown in the figure below, swap and / have been created successfully.

Change all other partitions in the above image exceptEFI and the two partitions just createdto "do not use the partition" by clicking Change.

####### Set the UEFI boot location Set the bottommostbootloadertoefithe disk number of the partition.

Click "Install Now" in the bottom right corner and check whether only the modified swap and ext4 partitions are shown below. If there are others, it means there are unrelated partitions that have not been unmounted.

1.12.3.2.Independent EFI partition (not recommended)
This applies when you have an empty hard drive (not an empty disk partition, but an entire hard drive that is completely empty), and then allocate the entire hard drive to Linux. (Of course, this situation also applies to the method above of sharing a single EFI partition with Windows.)
Suitable for veterans.
The advantage is that if it crashes, it directly formats the entire hard drive, very clean.
####### Initial Setup Select Manual here; we'll partition manually.


Locate the empty hard drive we reserved. (The entire drive is completely empty. I specifically found an empty 128GB drive to write the tutorial, as shown in the nvme0n1 in the image below.)

####### Creating an EFI partition (this method has one more EFI partition than the previous method) Double-click the free space under your hard disk,
Then set the size to 1024, and set use as to EFI partition.

####### Creating a swap partition Then click free space again.
Select this area, then double-click or click the Add button.
use as optionswap area.
Partition the swap area. For this Size, please enter your内存大小(运存大小)+2GB(单位MB); for example, if my computer's memory is 32GB, then 32+2=34GB, then use34*1024=34816MB,so enter34816.
tips (optional to read): The reason for doing this is to enable the Linux hibernation feature. If your swap partition size is set incorrectly, the Linux hibernation feature may have problems.

####### 根目录/分区建立 再选中剩余的这块区域,双击或者点击Add按钮。
use as choose ext4
Then select the mount point/(that is, the root directory)
Just use the default for Size (the default is to allocate all remaining maximum capacity to根目录).

####### Unmount other unrelated partitions For all partitions in the above image except the ones just createdefi, swap, root directory /, click Change and set them to do not use the partition.

####### 设置UEFI引导位置
把最下方那个bootloader设置为efi分区的磁盘号。比如我这里是nvme0n1p1。

Click Install Now in the bottom-right corner and check whether only the three partitions efi, swap, and ext4 are shown below as modified. If there are others, it means an unrelated partition has not been unmounted.

1.12.4.Final settings
时区选个东八区的就行。默认应该是中国上海🇨🇳时间,也可以选中国香港🇭🇰,中国台湾🇨🇳时间都可以。

Just set the username to start with English letters; here I am using tungchiahui.
Choose a simple password, purely numeric, because it will be entered frequently in the future, so make it as simple as possible.
The computer name can be anything, as long as it starts with an English letter.

Just wait, it's related to network speed and computer performance.

Restart.

If you are using the USB drive method, please unplug the USB drive (in most cases it is fine not to unplug it, as long as your boot priority is not the USB drive), then press Enter to restart

Power on!

1.13.Dual-system switching
After pressing the power button, it enters GRUB (the black screen).
If the Ubuntu option is displayed above, that means it enters Linux.
The Windows option shown above means entering Windows.
1.14.Completely remove Linux
1.14.1.Partition formatting
Open DiskGenius and locate the partition allocated to Linux.

Select each one in turn and click Delete Partition.

Click Save Changes.

1.14.2.Boot deletion
1.14.2.1.Share EFI with Windows
Open DiskGenius and double-click the Windows ESP partition.

Enter the EFI folder, find the ubuntu folder, right-click强制删除

Then, no matter what warnings are given afterward, keep clicking Delete, Confirm Deletion, and similar wording.

This completes the boot guide deletion.

1.14.2.2.Standalone EFI
Then simply format the entire hard drive.
Find your second drive.

Right-click to select the entire hard drive, click删除所有分区.


2.Regular virtual machine (not recommended)
(No need to teach me, just Baidu it and solve it yourself)
3.Windows Subsystem For Linux 2 (Windows的Linux子系统2) (a reluctant approach)
3.1.简介与优缺点
- Under what circumstances is it recommended?
Without an extra hard drive, there is no way to physically install Linux. In this case, the optimal choice is WSL2, not virtual machines such as VMware.
-
Pros and cons:
-
Pros:
-
WSL2 is the best Linux distribution; (just kidding)
-
Extremely low performance overhead. And compared to running deep learning on Windows, performance is much, much stronger; (as shown in the figure below, the lower the time value, the higher the performance)
-
It is very convenient to use USB devices, and USB passthrough is possible;
-
It is very convenient to use NVIDIA GPUs' CUDA and cuDNN;
-
It is very convenient for Windows and WSL2 to transfer files to each other and perform other collaborative operations;
-
In WSL2, you can even use Windows software in a Linux terminal;
-
It is very convenient to use VS Code remote development from Windows;
-
-
Cons:
- It cannot access the local camera, or rather, accessing the local camera is extremely troublesome. (Although it cannot access the local camera, a USB camera can be used)
-

3.2.Installation Tutorial
3.2.1.Enable the WSL2 subsystem and virtual platform
- Method 1 (Graphical Interface)
Input with Win+Rappwiz.cpl:

Click OK to enter the Programs and Features interface, and click Turn Windows features on or off.

Select Windows Subsystem for Linux and Virtual Machine Platform features:

- Method 2 (Command Line)
# 开启 Linux 子系统
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
# 开启虚拟机平台
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
3.2.2.Set WSL2 as the default version
Open PowerShell with administrator privileges

Upgrade WSL and set the default version to WSL2
# 更新 wsl
wsl --update
# 将 wsl 版本设置为 wsl2
wsl --set-default-version 2
3.2.3.Install a Linux distribution
- Method 1 (download from the app store, recommended, fast network speed, no VPN needed)
Simply open the Microsoft Store and search for the corresponding distribution to download (for example, Ubuntu 22.04 LTS).
If running ROS1, 20.04 LTS is recommended.
ROS2, it is more recommended to use 22.04 LTS. For beginners, having more tutorials is the best. ROS2 Humble and ROS2 Jazzy differ greatly in Gazebo. Learn the one with more tutorials first, and you can gradually switch to Jazzy later.

- Method 2 (command-line installation)
# 列出可安装的 Linux 版本
#(需要科学手段)
wsl --list --online

Select the corresponding distribution and install it
# Ubuntu安装完毕后(可以重启)
wsl --install -d Ubuntu-22.04
3.2.4.Check system status
# 查看 wsl
wsl -l
# 查看 wsl 运行版本或模式
wsl -l -v
# 设置发行版为使用 wsl 2 (如果版本为 2 则不需要)
wsl --set-version <distro> 2
# 选择要注销的版本 (如果想卸载再用此命令)
wsl --unregister <distro>
Output Version 2 means normal

3.2.5.Set username and password
Directly enter the wsl command in PowerShell to enter the subsystem
# 进入子系统
wsl
Enter a username (set it as you like; letters + numbers or letters only are recommended)
Input a password (digits fewer than 6 are recommended; while entering the password, the entered characters will not be displayed on the terminal, but the input has been entered normally).

3.2.6.Uninstall distribution
If a problem occurs, uninstall the WSL2 distribution that is causing the problem.
First, enter the following command in PowerShell to query distribution information.
wsl -l -v
Step 2: Uninstall Ubuntu from the Microsoft Store. (This step can generally be omitted.)
The third step is to enter the command below to log out:
wsl --unregister 发行版名称
The fourth step can be reinstalled starting from the step of installing the distribution.
3.3.Configure various environments
3.3.1.Switch source
(Same as bare-metal Linux; look below for the tutorial)
3.3.2.NVIDIA graphics card
3.3.2.1.Graphics card driver
No installation is required; as long as your Windows has the driver installed, your WSL2 already has the driver installed.


3.3.2.2.CUDA
https://developer.nvidia.com/cuda/wsl


On the website below, select the appropriate version.
https://developer.nvidia.com/cuda-toolkit-archive
(Same as a physical Linux machine; search below for the tutorial. The only difference from a physical machine is shown in the figure below.)

Type it out line by line.

After typing, enternvcc -VCheck whether the installation was successful. If the image below appears, it proves that the environment is not configured.

(Please refer to the tutorial below for theinstallationCUDAconfiguration environment to seehow to configure the environment)
3.3.2.3.cuDNN
(Same as bare-metal Linux; look below for the tutorial)

3.3.3.Configure network
WSL2 defaults to NAT mode, which means using Windows as the gateway, and WSL2 is a subordinate device of Windows. In this case, WSL2 and Windows are not on the same subnet. WSL2 can only communicate with Windows and the upstream devices of Windows, and cannot communicate with devices on the same subnet as Windows within the same LAN. To communicate with ROS and ROS2 devices on the same subnet, you can only either set up port forwarding or configure DDS, both of which are very troublesome.
WSL2还提供了好几种模式,有一个模式叫Mirrored模式 (Windows 10 22H2及以上才能开启) ,相当于Docker的--network host,这种方式是让WSL2和Windows使用相同的IP,这样的话,不论是WSL2还是Windows都可以访问同网段的局域网设备了。


Restart WSL2
wsl --shutdown
wsl
3.3.4.USB Passthrough
https://learn.microsoft.com/zh-cn/windows/wsl/connect-usb
Passthrough USB devices are only available to WSL2; Windows should not be able to use them. If you want to use them, please unbind them (disable passthrough).
首先现在电脑上安装usbipd,下面是github链接,进去点releases。
https://github.com/dorssel/usbipd-win
Click x64.msi to download and install.

After installation, then start your WSL2

Right-click the Start menu and select Terminal (Run as Administrator)

List Devices
usbipd list
The one in the figure below with busid 2-1 is my target.

Bind and link the device; this 2-1 needs to be replaced with your corresponding busid
usbipd bind --busid 2-1 --force
usbipd attach --wsl --busid 2-1

Then check the device in the terminal within WSL.
lsusb
ls /dev


If you unplug and replug the USB midway and WSL2 can no longer find it, please unbind the device.
usbipd unbind --busid 2-1
Then simply rebind it as described above.
3.3.5.VSCode Remote Development
(Be sure to develop the project in Linux, not on a Windows disk; otherwise, I/O efficiency will be very low.)
Install this plugin (WSL2 has its own remote development plugin, so there is no need to use SSH).

Connect to WSL2

Remote development successful.



3.3.6.Using Windows software in the Linux terminal

3.3.7.There is a problem with OpenGL
sudo apt update
sudo apt upgrade
sudo apt install mesa-utils
#然后重启wsl2即可