iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🛠

Setting Up My Preferred Development Environment on Windows 11

に公開

Purpose

I have set up something like a development environment on Windows 11 (specifically 22H2) while referring to various articles. Since it was quite a task, I'd like to summarize it here. This setup assumes a laptop environment and includes measures to limit the CPU/GPU performance slightly to prevent internal temperatures from rising too high.

Basic Setup

Control Panel

Go to the "Personalization" - "Themes" screen in the "Settings" app, click on "Desktop icon settings" under "Related settings," and check "Control Panel" in the displayed "Desktop Icon Settings" dialog.

Reference: Did the "Control Panel" disappear in Windows 11? No, it's still there.

CPU Limitation: Processor Performance Boost Mode

This is a setting item related to enabling/disabling Turbo Boost. You can toggle between "Aggressive" and "Disabled." You don't necessarily have to do this, but I did because the fans were loud. When set to "Disabled," it basically behaves as if it's running on E-cores. According to ChatGPT, P-cores are still used when necessary in this state, but I'm not entirely sure about the reality.

Change the Attributes (REG_DWORD) from 1 to 2 at HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\PowerSettings\54533251-82be-4824-96c1-47b60b740d00\be337238-0d82-4146-a960-4f3749d470c7.

Reference: Quickly turn turbo boost on or off in Windows

Duplicating Power Plans

You can retrieve the current power plans with powercfg /list and duplicate one using powercfg /duplicatescheme scheme_GUID. By setting the "Processor Performance Boost Mode" to "Disabled" in the duplicated plan, you should be able to easily toggle Turbo Boost on or off.

Reference: Powercfg command-line options

GPU Limitation

It seems you can also limit the GPU using MSI Afterburner.

Reference: Gaming PCs in summer are too hot! Use "MSI Afterburner" to make your video card power-efficient and low-heat

WSL2 Setup

Activation

Check "Windows Subsystem for Linux" and "Virtual Machine Platform" from Control Panel - Programs and Features - Turn Windows features on or off.

Windows 11 Home is fine if you just want to use Hyper-V. c.f. Relationship between WSL2 and Hyper-V

Reference:

Install Linux on Windows with WSL

Installing Ubuntu

wsl --install -d Ubuntu-20.04

The difference between Ubuntu and Ubuntu-20.04 is apparently whether it's the "latest" version or not. c.f. What is the difference between the three "Ubuntus" in the store? ~ How to upgrade "Ubuntu" in WSL

Installing the New Kernel Component

A message like the following may appear:

Installing, this may take a few minutes...
WslRegisterDistribution failed with error: 0x800701bc
Error: 0x800701bc WSL 2 ???????????? ??????????????????????? https://aka.ms/wsl2kernel ?????????

As indicated in the message, download and install the "WSL2 Linux kernel update package for x64 machines" from https://aka.ms/wsl2kernel or Step 4 - Download the Linux kernel update package. After installing this, I was able to proceed by launching "Ubuntu 20.04 on Windows" from the Start menu.

Reference: WslRegisterDistribution failed with error: 0x800701bc

Enabling Copy-Paste in the WSL Console

I haven't confirmed it thoroughly, but if necessary, performing this step might make things easier.

Reference: Linux/WSL console now supports copy-paste via shortcut keys ~ Windows 10 RS5

DNS Configuration

Modify /etc/wsl.conf and /etc/resolv.conf.

[/etc/wsl.conf]

[network]
generateResolvConf = false

[/etc/resolv.conf]

nameserver 8.8.8.8

Since /etc/resolv.conf is deleted when Windows restarts, take the following action:

sudo chattr +i /etc/resolv.conf

Reference:

ssh-agent Configuration

Add the following to ~/.bashrc:

[~/.bashrc]

eval `ssh-agent` > /dev/null
ssh-add  /home/xxx/.ssh/id_rsa >& /dev/null

Sharing .ssh with Windows

First, add the following to /etc/wsl.conf:

[automount]
options = "metadata,umask=077,fmask=11"

Then, share .ssh with the following:

ln -s /mnt/c/Users/xxx/.ssh ~/.ssh

With the above /etc/wsl.conf settings, permission settings such as chmod 600 id_rsa will be written to the WSL metadata even for the .ssh directory under DrvFS on NTFS.

Reference:

Disk Size

As a result of various tasks, the VHD containing the WSL2 image might have become bloated, so it might be a good idea to optimize it with the optimize-vhd command.

Reference: Reducing the disk size of WSL2

Addressing Heavy Memory Consumption

While it seems that some limits are now applied by default, you can take the following actions if necessary.

[%USERPROFILE%.wslconfig]

[wsl2]
memory=6GB
swap=0

It is reportedly supposed to be "50% of the PC's memory or 8GB, whichever is less," but in practice, it often isn't, and if no limit is set in .wslconfig, the upper limit seems to be "50% of the PC's memory." In other words, if you have 32GB of memory, there is a possibility that up to 16GB will be consumed. c.f. WSL2 using more than "50% of total memory on Windows or 8GB, whichever is less" (my machine has 24GB)

Reference: Interim measure to prevent host memory exhaustion by WSL2

Docker Setup

Basically, just follow the official procedures to Install using the repository.

The following is based on security awareness and personal preference:

sudo groupadd docker
sudo usermod -aG docker $USER

[/etc/sudoers]

xxx ALL=NOPASSWD: /usr/sbin/service docker start, /usr/sbin/service docker stop, /usr/sbin/service docker restart

c.f. How to avoid being asked for a sudo password

By ensuring sudo does not ask for a password, starting the Docker daemon becomes easier (since the systemd environment is tricky in WSL2, this method is reportedly more stable):

[~/.bashrc]

if service docker status 2>&1 | grep -q "is not running"; then
  sudo service docker start
fi

Reference:

CUDA Setup

To install CUDA 11.8 on WSL2, the following steps should work:

This uses the URL for Linux - x86_64 - WSL-Ubuntu when downloading from the CUDA Toolkit 11.8 Downloads archive.

wget https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/cuda-wsl-ubuntu.pin
sudo mv cuda-wsl-ubuntu.pin /etc/apt/preferences.d/cuda-repository-pin-600
wget https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda-repo-wsl-ubuntu-11-8-local_11.8.0-1_amd64.deb
sudo dpkg -i cuda-repo-wsl-ubuntu-11-8-local_11.8.0-1_amd64.deb
sudo cp /var/cuda-repo-wsl-ubuntu-11-8-local/cuda-*-keyring.gpg /usr/share/keyrings/
sudo apt-get update
sudo apt-get -y install cuda

After this, launching PowerShell with administrator privileges and running the following will also enable WSLg. c.f. Run Linux GUI apps on the Windows Subsystem for Linux

wsl --update
wsl --shutdown

When building CUDA-compatible apps, you will use it as follows:

export PATH="/usr/local/cuda/bin:$PATH"
export LD_LIBRARY_PATH="/usr/local/cuda/lib64:$LD_LIBRARY_PATH"

Reference:

Summary

I don't expect my Windows machine to suddenly break and require re-setup again, but since these are parts that are difficult to automate, I've summarized them here. Such information likely has a short shelf life, so it probably won't be very useful for long.

GitHubで編集を提案

Discussion