WSL安装到非C盘 内存限制
wsl --update wsl --set-default-version 2
Invoke-WebRequest -Uri https://aka.ms/wslubuntu2204 -OutFile Ubuntu2204-221101.AppxBundle -UseBasicParsing
或者使用curl
curl.exe -L -o Ubuntu2204-221101.AppxBundle https://aka.ms/wslubuntu2204
使用解压软件(可以使用7-Zip)打开AppxBundle文件,提取出当前平台的appx文件<Ubuntu_2204.1.7.0_x64.appx>
Rename-Item .\Ubuntu2204-221101.AppxBundle Ubuntu.zip Expand-Archive .\Ubuntu.zip -Verbose
获取到<Ubuntu_2204.1.7.0_x64.appx>
手动安装到任意位置
Rename-Item .\Ubuntu_2204.1.7.0_x64.appx Ubuntu-22.04.zip Expand-Archive .\Ubuntu-22.04.zip -Verbose cd .\Ubuntu-22.04 .\ubuntu.exe
安装完成后,在Windows Terminal中就会有Ubuntu启动项
https://learn.microsoft.com/zh-cn/windows/wsl/basic-commands
限制WSL的内存使用
https://learn.microsoft.com/en-us/windows/wsl/wsl-config#configuration-setting-for-wslconfig
https://learn.microsoft.com/en-us/windows/wsl/wsl-config#configure-global-options-with-wslconfig
简单来说就是创建一个%UserProfile%\.wslconfig
文件来限制wsl使用的内存总量。
比如说我在Windows中使用的用户是tiny,那么我就在C:\Users\tiny
中创建了一个.wslconfig
文件,在里面加入以下内容来限制wsl2的内存总大小:
[wsl2] processors=4 memory=4GB swap=8GB localhostForwarding=true
注意修改完成之后需要重启wsl2才能生效。更多详细的配置可以查看官方文档。
https://learn.microsoft.com/en-us/windows/wsl/wsl-config#configuration-settings-for-wslconf
Configuration settings for wsl.conf
The wsl.conf file configures settings on a per-distribution basis. (For global configuration of WSL 2 distributions see .wslconfig).
The wsl.conf file supports four sections: automount
, network
, interop
, and user
. (Modeled after .ini file conventions, keys are declared under a section, like .gitconfig files.) See wsl.conf for info on where to store the wsl.conf file.
systemd support
Many Linux distributions run "systemd" by default (including Ubuntu) and WSL has recently added support for this system/service manager so that WSL is even more similar to using your favorite Linux distributions on a bare metal machine. You will need version 0.67.6+ of WSL to enable systemd. Check your WSL version with command wsl --version
. If you need to update, you can grab the latest version of WSL in the Microsoft Store. Learn more in blog announcement.
To enable systemd, open your wsl.conf
file in a text editor using sudo
for admin permissions and add these lines to the /etc/wsl.conf
:
[boot]
systemd=true
You will then need to close your WSL distribution using wsl.exe --shutdown
from PowerShell to restart your WSL instances. Once your distribution restarts, systemd should be running. You can confirm using the command: systemctl list-unit-files --type=service
, which will show the status of your services.
当出现 chcon: can't apply partial context to unlabeled file 时,
sudo apt install selinux-utils
getenforce
https://github.com/DDoSolitary/LxRunOffline