banner
Nagi-ovo

Nagi-ovo

Breezing
github
x

Configure Ubuntu 20.04 on WSL2

Bought a new computer (3090ti) for alchemy, after much hesitation, I chose the latter in dual system and WSL.

The reasons are as follows:

  • I don't want to mess with the hard drive and network configuration of the dual system, while WSL can synchronize the host of the main system.
  • I want to try WSL2. I've known about this thing for a long time, but the previous one I used on my Lenovo laptop was very slow and I didn't use it for productivity.
  • Low sense of existence, the subsystem that can be opened in 2-3 seconds, can run tasks in the background, and satisfy my strange requirement of "not wanting to configure the environment in windows".
  • It is said online that the current WSL2 has good support for NVIDIA GPU, and many of the pitfalls mentioned in the posts are no longer important.

Configuration process#

Recall the configuration process:

Download WSL2#

Under Win11, you only need to run the following command in Windows Powershell to complete the entire system configuration without having to check anything like "virtual machine platform" and "enable HyperV":

wsl --install # The default is the LTS version. To download a specific version, you can enter wsl --list --online to view it first.

Migrate the hard drive#

I usually put things in other drives, but WSL is installed on the system drive by default. First determine the version:

wsl --list --verbose

Export the existing system:

wsl --export Ubuntu-20.04 D:\Ubuntu.tar # The version and naming here are like this for me.

Unmount:

wsl --unregister Ubuntu-20.04

Remount:

wsl --import Ubuntu-20.04 D:\wsl2\Ubuntu D:\Ubuntu.tar

wslconfig#

Press Win + r and enter %UserProfile%, then create a file named .wslconfig in that directory (remember to enable file extension display). The specific configuration still needs to be found online for professional content. WSL2 can only use half of the memory by default. I just want to open it all. The first two lines are for network host settings.

[wsl2]
networkingMode=mirrored
autoProxy=True
memory=32GB

Avoid pitfalls#

Here, it should be noted that after migrating the hard drive and remounting, the default user will be root instead of the Unix User who logged in at the beginning. For a better future, it is best not to use the root user to complete all operations.

vim /etc/wsl.conf

Then copy the following content. systemd should be default now:

[user]
default=the username you registered at the beginning

[boot]
systemd=true

In addition, do not try to delete the library in WSL, it may delete the entire disk. If you want to experience the effect, go to the virtual machine.

Shutdown#

When not in use and want to release resources, you can enter the following in Windows PowerShell:

wsl --shutdown

ZSH#

I'm used to using zsh as the default terminal. Just sudo apt install zsh, and then find a configuration post for oh-my-zsh to follow to get a usable terminal.

For example: https://dev.to/equiman/zsh-on-windows-with-wsl-1jck
However, the recommended font for adapting the terminal in this article doesn't look good. I personally prefer the JetBrains Nerd Font Mono font.

Other configurations#

My requirement is to configure the deep learning environment, there is nothing to talk about, it's the same as operating on a pure Linux server, miniconda+uv pip install is enough.

If pip prompts you that you are operating with the root account when downloading here, pay attention to what was mentioned earlier in this article.

Conclusion#

I feel that WSL2 does save a lot of effort, and it can also allocate resources conveniently while doing alchemy and fishing. This kind of Windows is the ideal operating system in my mind. I haven't used my MacBook Air for two days. I won't use it unless I go out.

As for the speed of alchemy, as long as it can run, it's fine. Don't think about the 20% loss mentioned online, the more you compare, the more troubles you have~

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.