Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

拥抱 WSLg #47

Closed
ferstar opened this issue Nov 2, 2021 · 9 comments
Closed

拥抱 WSLg #47

ferstar opened this issue Nov 2, 2021 · 9 comments

Comments

@ferstar
Copy link
Owner

ferstar commented Nov 2, 2021

好了,我宣布WSLg就是个锤锤,投奔Linux怀抱


开个坑, 慢慢填

  1. 垃圾WSL IO巨慢

这里喷IO慢的仔细一看基本都是项目在Windows里, 然后 runtime 在 WSL, 这他喵跨着9p不卡才怪

解决方法也很简单, runtime IDE什么的一股脑统统丢 WSL 里不就完了, 啥? 嫌空间不够用? WSL挂载磁盘了解下? 直接就是原生磁盘IO的性能

  1. PyCharm 全局搜索框调不出来或者一闪而逝此坑已填: https://youtrack.jetbrains.com/issue/IDEA-265390

这个issue里找到了神仙解法: 狂按快捷键, 直到全局搜索框出来为止, 然后 pin 住, 就欧了...

  1. 中文输入法

方法是从CSDN淘的 , 装好fcitx后, 这段丢到bashrc 或 zshrc 或 profile 里, 然后启动GUI前运行fcitx-autostart即可, 只需要运行一次

export LANG=zh_CN.UTF-8
export INPUT_METHOD=fcitx # wayland输入法
export XMODIFIERS=@im=fcitx # x11输入法
export GTK_IM_MODULE=fcitx # gtk输入法
export QT_IM_MODULE=fcitx # qt输入法
  1. OpenGL 也就是显卡加速

老老实实按官方说明去装一下支持wslg的显卡驱动即可, 直观的感受是拖拽WSL的GUI应用窗口不会撕裂, 也明显不卡顿了, 纵享丝滑

后续的Windows更新可能会把装好的vGPU驱动替换成正常驱动, 从而导致WSLg GUI 应用丢掉 OpenGL 加速支持, 会显得比较卡, 暂时的解决办法是从组策略禁用Windows更新驱动程序

Win + R -> gpedit.msc -> 计算机配置 -> 管理模板 -> Windows组件 -> Windows更新 -> 管理从Windows更新提供的更新 -> Windows更新不包括驱动程序 -> 启用 -> 应用

  1. IP老变的问题

这个也就是一个小脚本解决的事情, 以我常用的 proxychains(wsl中使用host代理) 为例

new_host=$(grep 'nameserver' /etc/resolv.conf | head -n 1 | awk '{print $2}')
old_host=$(grep -E '^socks5' /etc/proxychains4.conf | awk '{print $2}')
sudo sed -i "s/$old_host/$new_host/g" /etc/proxychains4.conf
  1. Windows Terminal 进 Ubuntu 子系统默认目录不是~

设置 -> Ubuntu -> 常规 -> 命令行 -> wsl.exe -d Ubuntu-20.04 --cd ~

image

@ferstar
Copy link
Owner Author

ferstar commented Nov 25, 2021

  1. Nahimic 无法发布?

直接卸载就完事, 如果卸载不掉, 可以试试我从知乎淘来的一个脚本
RemoveNahimic_20210111.zip

@ferstar
Copy link
Owner Author

ferstar commented Dec 2, 2021

  1. JB全家桶里面中文输入法没法光标跟随?

参考我之前这里的说明, WSLg环境依然有效, 主要就是用魔改的jbr替换JB官方的jbr目录

image

@ferstar
Copy link
Owner Author

ferstar commented Dec 8, 2021

  1. 偶尔 WSLg GUI 没有响应, 一般发生在长时间睡眠的唤醒时, 不频繁

shutdown掉子系统, 卸载重装 WSLg 再开子系统即可

后来定位到其实是 AMD 核显驱动的问题, 换独显直通用 NVIDIA 独显就没事了

@ferstar
Copy link
Owner Author

ferstar commented Mar 9, 2022

  1. 某次更新后发现没法完全关闭Windows defender了?

用这个工具关闭: dControl.zip

或者随便选择装一个安全软件, 比如火绒即可

@ferstar
Copy link
Owner Author

ferstar commented Mar 24, 2022

@ferstar
Copy link
Owner Author

ferstar commented Mar 24, 2022

  1. 系统更新后 Scoop Apps 内应用图标丢失?

见: ScoopInstaller/Scoop#3941

scoop reset *

@ferstar
Copy link
Owner Author

ferstar commented Mar 24, 2022

  1. zsh 粘贴又卡又慢?

看这里: zsh-users/zsh-autosuggestions#238 (comment)

# 粘贴到.zshrc再source一下即可
# This speeds up pasting w/ autosuggest
# https://github.com/zsh-users/zsh-autosuggestions/issues/238
pasteinit() {
  OLD_SELF_INSERT=${${(s.:.)widgets[self-insert]}[2,3]}
  zle -N self-insert url-quote-magic # I wonder if you'd need `.url-quote-magic`?
}

pastefinish() {
  zle -N self-insert $OLD_SELF_INSERT
}
zstyle :bracketed-paste-magic paste-init pasteinit
zstyle :bracketed-paste-magic paste-finish pastefinish

@ferstar
Copy link
Owner Author

ferstar commented Mar 31, 2022

  1. 微软输入法选字框消失?

设置〉时间和语言〉语言和区域〉选项〉微软拼音〉常规〉兼容性〉使用以前版本的微软拼音输入法

@ferstar
Copy link
Owner Author

ferstar commented Apr 18, 2022

  1. 开启 SSH

从这抄的: http://dancingline.cn/%E8%BF%9C%E7%A8%8B%E8%BF%9E%E6%8E%A5WSL2/

为防 404, 摘抄一份

据说自带的OpenSSH有问题,需要先卸后装

sudo apt remove openssh-server
sudo apt install openssh-server

修改 sshd 配置文件

Port 2222   #设置ssh的端口号, 由于22在windows中有别的用处, 尽量不修改系统的端口号
PermitRootLogin yes   # 可以root远程登录
PasswordAuthentication yes     # 允许密码验证登录
AllowUsers dancingline # 远程登录时的用户名

重启服务

sudo service ssh --full-restart

Windows端口转发(保存为.ps1 后缀, 直接运行即可, 会自动申请管理员权限)

防火墙配置就不多说, 我是直接关掉

if (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))  
{  
  $arguments = "& '" +$myinvocation.mycommand.definition + "'"
  Start-Process powershell -Verb runAs -ArgumentList $arguments
  Break
}
# 找到WSL2的IP
$ip = bash.exe -c "ifconfig eth0 | grep 'inet '"
$found = $ip -match '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
if( $found ) {
$ip = $matches[0];
echo "Found IP $ip"
# 端口转发,listenport和listenaddress表示监听的端口和IP,connectport和connectaddress表示转发到的端口和IP
iex "netsh interface portproxy add v4tov4 listenport=2222 listenaddress=* connectport=2222 connectaddress=$ip";
# 展示已有的
iex "netsh interface portproxy show all;"
}
else { echo "The ip address of WSL2 cannot be found!"; }

完事以后就可以从局域网 or 外网直接 ssh 链接了

ssh root@x.x.x.x -p 2222

@ferstar ferstar closed this as completed Aug 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant