essay | tech | year-summary | about

返回上级菜单

WSL Tips


日期:2018-04-02T00:00:00Z

记录下自己使用时感觉实用的小知识吧!

1.什么是wsl?

wsl = Windows Subsystem Linux, 是只有win 10 有的功能。有了wsl,妈妈再也不担心用cygwin的卡顿,用powershell的奇怪语言(?)的困扰和,用MinGW的...(突然找不到可以黑的点)。
这个是很早就出名的一个,win10专为开发者开发的一样东西。
目前推荐的方式是使用microsoft store去下载。

2.wsl不仅仅只有ubuntu一家

在microsoft store搜索linux,可以找到ubuntu, debian, kari linux等等诸多版本。个人比较推荐debian(原因是我的linux是ubuntu入手,比较习惯于apt家族。顺便一提,新版本提倡使用apt,而不是apt-get)

3.为何博主在debian和ubuntu之间推荐debian?

在博主看来两者有以下的区别:

4.wsl不推荐使用自带terminal,推荐使用外部的terminal

我个人使用的是这一款:https://github.com/goreliu/wsl-terminal

自带的terminal会有如下问题。

you-get "https://www.youtube.com/watch?v=F2u3BhtMUTE"

(PS:博主版权的视频,并非非法下载,也欢迎大家下载,凭本文持有博主许可,另外需遵循youtube条则)
在debian的原生terminal会出现这样的感觉
debian-wrong
因为似乎错了一个字节,然后就开始错位了,没有办法正确出现下图的这种情况。
wsl-correct

5.切换默认的wsl

使用wslconfig。

wslconfig /l
wslconfig /l /a
wslconfig /setdefault

简单明了,应该不用解释了。
切换了之后,会发现比如我使用的那款terminal,会自动切换到默认的wsl。在powershell或者cmd里面,敲打bash或者wsl,也会开启默认的wsl。

Mount SMB(NAS) 2024 June

https://www.linode.com/docs/guides/linux-mount-smb-share/

sudo apt install cifs-utils psmisc
mount -t cifs
fuser

mkdir /mnt/smb_share
mount -t cifs //[server-ip]/[share-path] /[mount-point]
mount -t cifs

nano ~/.credentials
sudo chmod 600 <Credentials Filename>
sudo mount -t cifs -o credentials=<Credentials Filename> //<IP Address of Server>/<Share on Server> /<Mount Point>

umount -t cifs /<Mount Point>

File: .credentials

username=target_user_name
password=target_user_password
domain=domain

File: /etc/fstab

<file system>: //<IP Address of Server>/<Share on Server>
<mount point>: <Mount Point>
<type>: cifs
<options>: credentials=<Credentials Filename>
systemctl daemon-reload

wsl home path

https://superuser.com/questions/1791373/location-of-wsl-home-directory-in-windows

\\wsl.localhost\Ubuntu\home\{username}

wsl expand size

https://learn.microsoft.com/en-us/windows/wsl/disk-space
https://learn.microsoft.com/en-us/windows/wsl/disk-space#how-to-locate-the-vhdx-file-and-disk-path-for-your-linux-distribution

replacing with the actual distribution name

(Get-ChildItem -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss | Where-Object { $_.GetValue("DistributionName") -eq '<distribution-name>' }).GetValue("BasePath") + "\ext4.vhdx"
diskpart
Select vdisk file="<pathToVHD>"
detail vdisk
expand vdisk maximum=<sizeInMegaBytes>
compact vdisks
exit

参考资料: