WSL学习笔记
资料
- 手动下载适用于 Linux 的 Windows 子系统发行版包
- wsl2-backup-and-restore-images-using-import-and-export
- 解决删除文件后 WSL2 磁盘空间不释放的问题
- https://github.com/JetBrains/clion-wsl
- 使用WSL配置mmdetection环境
SSH
1 |
|
也可以使用Jetbrains的 https://github.com/JetBrains/clion-wsl
1 |
|
32位支持
1 |
|
以下是wsl1,不是wsl2
Exec format error 32-bit executable Windows Subsystem for Linux?
Install qemu and binfmt config:
1 |
|
You’ll need to reactivate binfmt support every time you start WSL:
1 |
|
Enable i386 architecture packages:
1 |
|
Try it out:
1 |
|
And to prove it really was working, disable i386 support and try again:
1 |
|
windows terminal
备份
1 |
|
问题
Failed to install linux distro with error 0x8007023e #5508
https://github.com/microsoft/WSL/issues/5508
https://github.com/microsoft/WSL/issues/5508#issuecomment-743733155
I was investigating why this failed and messed up with my note taking as I fixed it without having to do all of this, but this does seem to work.
Try this. It’s more in-depth …
- Make sure Virtualisation is enabled in BIOS.
- Make sure the Windows Image and the OS are healthy. Follow these instructions for Windows 10: https://docs.microsoft.com/en-us/troubleshoot/windows-server/deployment/fix-windows-update-errors
- Make a note/backup of ALL Hyper-V settings!
- Remove all Virtual machine features. This being: Hyper-V, containers, Virtual Machine Platform, Windows Hypervisor Platform, Windows Sandbox and Windows Subsystem for Linux.
- Reboot the computer!
- Follow the manual WSL installation instructions provided by Microsoft as shown here: http://aka.ms/wslinstall
- Reboot the computer!
- Make sure that your Linux Distro converts to WSL2 if you want your Distro to operate under a full Linux Kernel.
- There is no harm in invoking Windows Update at this point. I recommend you do.
- Install the Windows Hypervisor Platform. (The likes of VMware and Virtual Box need it.)
- No harm in rebooting the computer at this point.
- No harm in invoking Windows Update at this point.
- If you use it, install the Windows Sandbox feature and test it.
- Finally install Hyper-V and put back all your required settings.
At this point everything, for me, started working.
I have noticed that on the completion of installing any of the virtualisation features, when invoking Windows Update then KB4592438 gets reapplied. If you wish, and maybe recommended, invoke Windows Update when you install a Windows Feature. That’s what I did. Installed a feature, rebooted and invoked Window Update. (I think the only one where I didn’t invoke Windows Update is when I installed the Windows Hypervisor Platform.)
语言环境
1 |
|
修改/etc/default/locale
1 |
|
修改/etc/locale.gen
找到 *zh_CN.UTF-8 UTF-8* 并取消注释,然后保存并退出
1 |
|
缩放
1 |
|
修改GPU渲染
更改wsl默认登陆用户名
1 |
|
UI界面字体模糊
Blurry fonts on using Windows default scaling with WSL GUI applications (HiDPI)
GUI programs are blurry pixelated in WSL2
Fixing blurry fonts on WSL with X-server
Set dpi of wsl2 windows independently of screen resolution
~/.bashrc
添加
1 |
|
Linux
常用包
1 |
|
WSL内核升级
资料
-
官方内核**WSL2-Linux-Kernel**
-
Install the build dependencies:
$ sudo apt install build-essential flex bison dwarves libssl-dev libelf-dev
-
Build the kernel using the WSL2 kernel configuration:
$ make KCONFIG_CONFIG=Microsoft/config-wsl
-
-
如何在 Windows Subsystem for Linux version 2 (WSL2) 上使用 Microsoft Linux 内核 v6
-
最省事的方法**WSL2-Linux-Kernel-Rolling**
进入https://github.com/Nevuly/WSL2-Linux-Kernel-Rolling/releases下载编译好的内核,按下面的步骤配置.wslconfig文件即可
步骤(推荐)
- 按**WSL2-Linux-Kernel-Rolling**这个仓库编译或者使用已经编译好的镜像,按步骤(老方法)的第8条修改配置文件即可。
步骤(老方法)
- 使用
neofetch
查看当前系统如下
{% asset_img "image-20240130132455544.png" "image-20240130132455544" %}
- 在 The Linux Kernel Archives 下载内核
1
2
3
4
5
6
7
mkdir ./Downloads
cd ~/Downloads
#curl -LO https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.7.2.tar.xz
wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.7.2.tar.xz
#wget https://mirrors.edge.kernel.org//pub/linux/kernel/v6.x/linux-6.1.9.tar.gz
tar -zxvf ./linux-6.7.2.tar.gz
cd ./linux-6.7.2
- 安装编译依赖组件包
1
2
sudo apt install build-essential flex bison dwarves libssl-dev libelf-dev bc pkg-config libncurses-dev
# Go https://github.com/microsoft/WSL2-Linux-Kernel#build-instructions to see the latest build dependencies
- 使用 WSL2-Linux-Kernel 配置文件
这个 `.config` 文件针对 `wsl2` 做出了调整与优化。尽管直到我安装时,它的分支仍然是 `linux-msft-wsl-5.15.y`,也就是针对 `5.15` 内核的编译选项,但是仍然适用于我所安装的 `6.1.9` 版本内核。
1
wget https://raw.githubusercontent.com/microsoft/WSL2-Linux-Kernel/linux-msft-wsl-5.15.y/Microsoft/config-wsl >> .config
- 编译 在这里,请按照你自己的配置修改 jobs 的数量,有20线程的话就是
-j20
或者写-j$(nproc)
。
1 |
|
-
在编译前,它会有很多配置项(即在
.config
内没有指定的新内核的配置项)要你指定,没有特殊需求的话一路回车即可。耐心等待安装完成后,可以在标准输出内找到类似字段。Kernel:
后的路径即为内核路径。 -
将编译后其复制到你想要的位置,注意这个位置应该存在于你的主硬盘而不是 wsl 中
1
2cp arch/x86/boot/bzImage /mnt/e/wsl2/kernel/linux-6.7.2
#cp arch/x86/boot/bzImage /mnt/e/wsl2/kernel/linux-6.1.9 -
打开你的用户目录,修改
.wslconfig
文件,在[wsl2]
标签中添加kernel
字段,它的值为带有转义反斜杠的 Windows 路径。注意现在window已经支持wsl.conf
为每个linux虚拟机提供单独配置。注意需要提前关闭虚拟机wsl --shutdown
> 可以为已安装的 Linux 发行版配置设置,使它们在你每次启动 WSL 时自动应用,有两种方法:
>
> - **[.wslconfig](https://learn.microsoft.com/zh-cn/windows/wsl/wsl-config#wslconfig)** 用于在 WSL 2 上运行的所有已安装发行版中配置**全局设置**。
> - **[wsl.conf](https://learn.microsoft.com/zh-cn/windows/wsl/wsl-config#wslconf)** 用于为在 WSL 1 或 WSL 2 上运行的每个 Linux 发行版按各个发行版配置**本地设置**。
具体参阅[WSL 中的高级设置配置](https://learn.microsoft.com/zh-cn/windows/wsl/wsl-config)
例如,在我的案例中, `.wslconfig` 文件长这个样子。
1
2
[wsl2]
kernel=E:\\wsl2\\kernel\\linux-6.7.2
- 再次使用
neofetch
查看当前系统
{% asset_img "image-20240130154703109.png" "image-20240130154703109" %}