最近工作原因需要使用Windows 11操作系统,但又离不开Linux一些工具,遂想到使用WSL2
安装方式如下:
重启后
以管理员身份运行PowerShell
>>> wsl --install
将会默认安装Ubuntu,当然也可以安装Debain
如果你安装有clash,则可以通过
>>> export http='http://10.30.49.213:7890'
>>> export https='http://10.30.49.213:7890'
>>> export all_proxy='socks5://10.30.49.213:7890'
>>> export ALL_PROXY='socks5://10.30.49.213:7890'
安装pip3
>>> sudo apt install python3-pip
更新pip3
>>> python3 -m pip install --upgrade pip
2023-03-22更新
直接通过vs code是无法打开wsl的目录,只能通过安装WSL插件完成,具体如下:
如果你想通过vs code在WSL内使用Git,那么,不建议在Windows上安装Git,这样会导致vs code使用Windows的Git拉取仓库,众所周知Windows和Unix换行符不同,所以这样会导致所有文件都出现变更,因而不安装就行。
如果WSL内的Git无法使用clash,则使用以下命令
# 重置
git config --global --unset https.https://github.com.proxy
git config --global --unset http.https://github.com.proxy
# 代理
git config --global http.https://github.com.proxy http://192.168.124.11:7890
git config --global https.https://github.com.proxy https://192.168.124.11:7890
参考:https://zhuanlan.zhihu.com/p/378894743
2023-03-27更新
如何开机自动启动WSL上的docker:
>>> vim /etc/wsl.conf
[boot]
command="service docker start"
...
参考:https://stackoverflow.com/a/65814529
2023-07-09更新
之前用ExtFS for Windows成功将EXT4格式的硬盘挂载到win10上了。
但今天又想试试使用wsl 挂载
使用管理员权限打开powershell
PS C:\WINDOWS\system32> GET-CimInstance -query "SELECT * from Win32_DiskDrive"
DeviceID Caption Partitions Size Model
-------- ------- ---------- ---- -----
\\.\PHYSICALDRIVE1 INTEL SSDPEKKW256G7 2 256052966400 INTEL SSDPEKKW256G7
\\.\PHYSICALDRIVE3 ST6000NM 019B-2TG103 SCSI Disk Device 1 6001172513280 ST6000NM 019B-2TG103 SCSI Disk Device
\\.\PHYSICALDRIVE2 INTEL SSDPEKKW256G7 4 256052966400 INTEL SSDPEKKW256G7
\\.\PHYSICALDRIVE0 ST2000DM001-1ER164 3 2000396321280 ST2000DM001-1ER164
PS C:\WINDOWS\system32> wsl --mount \\.\PHYSICALDRIVE3
磁盘已附加,但装载失败: Invalid argument。
要查看更多相关信息,请在 WSL2 中运行 'dmesg'。
若要分离磁盘,请运行 'wsl.exe --unmount \\.\PHYSICALDRIVE3'。
出现上面的报错不要慌
进去wsl
>>> dmesg
[ 2981.304349] sd 0:0:0:3: [sde] 11721045168 512-byte logical blocks: (6.00 TB/5.46 TiB)
[ 2981.304360] sd 0:0:0:3: [sde] 4096-byte physical blocks
[ 2981.305124] sd 0:0:0:3: [sde] Write Protect is off
[ 2981.305132] sd 0:0:0:3: [sde] Mode Sense: 0f 00 00 00
[ 2981.306427] sd 0:0:0:3: [sde] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[ 2981.306437] sd 0:0:0:3: [sde] Optimal transfer size 33553920 bytes not a multiple of physical block size (4096 bytes)
[ 2981.406686] sde: sde1 sde2
[ 2981.600933] sd 0:0:0:3: [sde] Attached SCSI disk
[ 2981.624718] WSL (17145): Detected (null) filesystem for device: /dev/sde
[ 2981.624762] WSL (17145) ERROR: UtilMount:1632: mount(/dev/sde, /mnt/wsl/PHYSICALDRIVE3, (null)
[ 2981.624764] , 0x0, ) failed 22
我们手动挂载
>>> sudo fdisk -l
Disk /dev/sde: 5.46 TiB, 6001175126016 bytes, 11721045168 sectors
Disk model: 019B-2TG103
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 38904FDA-0380-4125-B3D3-00A0D650CD2D
Device Start End Sectors Size Type
/dev/sde1 34 32767 32734 16M Microsoft reserved
/dev/sde2 32768 11721043967 11721011200 5.5T Linux filesystem
>>> mkdir /mnt/wsl/data
>>> sudo mount -t ext4 /dev/sde2 /mnt/wsl/data
注意:上面的sde可能会变,请根据fdisk -l结果进行替换
如果在mount的时候报错:
Structure needs cleaning
则使用如下命令进行修复
>>> fsck.ext4 /dev/sde2
2023-07-25更新
docker client使用p r o x y,加速docker pull
sudo vim /etc/default/docker
export HTTP_PROXY="http://10.30.16.234:7890"
export HTTPS_PROXY="http://10.30.16.234:7890"
重启wsl
>>> wsl --shutdown
>>> wsl
参考:https://blog.csdn.net/qq_41011920/article/details/109553697
参考:https://zhuanlan.zhihu.com/p/427589367