跳至主要內容

常见问题

程序员李某某大约 3 分钟

常见问题

开发问题

端口占用

# 查进程号
netstat -ano | findstr 8080
# 杀死进程
taskkill /pid 1234 /f

WSL

参考文章open in new window

## 查看已安装
wsl --list --verbose
## 查看可安装
wsl --list --online
## 安装
wsl --install
## 安装指定版本
wsl --install -d Ubuntu-20.04
## 设置默认版本
wsl --set-default <DistributionName>
## 启动
wsl -d <DistributionName>
## 指定用户启动
wsl -d <DistributionName> -u <UserName>
## 设置默认发行版
wsl --set-default <Distribution Name>
## 改发行版系统名

## 停止
wsl --shutdown
## 卸载
wsl --unregister <DistributionName>

进入后改root密码

sudo passwd root

离线安装

确保开启了虚拟化 --- 在任务管理器 - 性能 - CPU - 查看虚拟化 管理员身份运行powershell

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
## 确保开启 虚拟机平台
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

重启电脑 最后检查 -- 在开始菜单中输入 启用或关闭 Windows 功能,在弹出的窗口中,【适用于Linux的Windows子系统】和【虚拟机平台】应该已经被勾选

安装wsl ---- 去GitHub下载 https://github.com/Microsoft/WSL/releasesopen in new window 下载Linux发行版 --- 见[离线安装Microsoft Store中的应用](#离线安装Microsoft Store中的应用) 安装到任意位置

  • AppxBundle安装包改名为zip文件,解压,
  • 找到文件名包含x64的.appx文件,再次改名为.zip文件,解压到喜欢的目录,如D:\Ubuntu
  • 点击ubuntu.exe安装,磁盘也会安装到这个目录下

磁盘

  • 迁移
#### 方式一
## 导出
wsl --export <DistributionName> <FileName> # wsl --export Ubuntu D:\WSL\Ubuntu.tar
## 卸载
wsl --unregister <DistributionName> # wsl --unregister Ubuntu
## 导入
wsl --import <DistributionName> <targetPath> <FileName> # wsl --import Ubuntu D:\WSL\Ubuntu D:\WSL\Ubuntu.tar

#### 方式二
## 复制ext4.vhdx文件到指定路径
cp "...\ext4.vhdx" <targetPath> # cp "C:\Ubuntu-20.04\ext4.vhdx" D:\WSL\Ubuntu
## 卸载
wsl --unregister <DistributionName>  # wsl --unregister Ubuntu
## 添加
wsl --import-in-place Ubuntu-20.04 <targetPath> # wsl --import-in-place Ubuntu-24.04.2 D:\Documents\wsl\Ubuntu\ext4.vhdx
  • 清理空间 WSL 不会自动收缩vhdx文件的大小, 我们需要手动压缩
# 关闭WSL
wsl --shutdown
# 打开Diskpart窗口
diskpart
select vdisk file="path to ext4.vhdx" # select vdisk file="D:\Documents\wsl\Ubuntu\ext4.vhdx"
attach vdisk readonly
compact vdisk
detach vdisk
# 退出
exit

配置ssh远程访问

sudo apt update
sudo apt install openssh-server
vim /etc/ssh/sshd_config # 配置文件
systemctl restart ssh
systemctl status ssh

配置文件

PasswordAuthentication yes
PermitRootLogin yes

##### 解决连上马上断开的问题
ClientAliveInterval 30
ClientAliveCountMax 60

报错

wsl: WSL 安装似乎已损坏 (错误代码: Wsl/CallMsi/Install/REGDB_E_CLASSNOTREG)。
按任意键修复 WSL,或 CTRL-C 取消。
此提示将在 60 秒后超时。
没有注册类 
错误代码: Wsl/CallMsi/Install/REGDB_E_CLASSNOTREG

解决方式: 管理员模式打开powershell (经过测试,直接在Github下载安装好使)

# 卸载 WSL 可选组件
dism.exe /online /disable-feature /featurename:Microsoft-Windows-Subsystem-Linux /norestart
## 安装 WSL 可选组件
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
## 重启

## 尝试使用用系统文件检查器(SFC)和部署映像服务和管理工具(DISM)来检查和修复系统文件:
sfc /scannow
## DISM
dism.exe /online /cleanup-image /restorehealth
## 重启

还是不行,就去GitHub下载最新可用包 https://github.com/Microsoft/WSL/releasesopen in new window

离线安装Microsoft Store中的应用

上次编辑于:
贡献者: 李元昊