安装 # 默认安装ubuntu,安装完成后需要重启 wsl --install
无法解析服务器端名称或地址:
经过排查后发现是 raw.githubusercontent.com 这个域名无法访问,上代理
配置DNS
重启后弹出安装界面,等待安装完成后,输入用户名和密码,完成安装!
**列出所有可用发行版 **
列出已安装发行版
查看WSL状态
关闭 wsl --shutdown #立即终止所有正在运行的发行版和 WSL 2 轻量级实用工具虚拟机。
注销并卸载 WSL 发行版
wsl --unregister <DistributionName>
基础配置 换源 # 换阿里源 sudo sed -i 's/http:\/\/archive.ubuntu.com/http:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list sudo sed -i 's/https:\/\/archive.ubuntu.com/http:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list
更新 wsl --update wsl --set-default-version 2
安装Ubuntu-24.04 # 安装 wsl --install -d Ubuntu-24.04# 默认启动 wsl --setdefault Ubuntu-24.04
配置 换源 echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-updates main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-security main restricted universe multiverse" | sudo tee /etc/apt/sources.list sudo apt update && sudo apt upgrade
root密码重置
0h-my-zsh 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 sudo apt install zsh -y chsh -s $(which zsh) sh -c "$(wget -O- https://gitee.com/mirrors/oh-my-zsh/raw/master/tools/install.sh) " git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom} /plugins/zsh-syntax-highlighting git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom} /plugins/zsh-autosuggestions sudo apt install autojump -y plugins=(git zsh-syntax-highlighting zsh-autosuggestions autojump) git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME /.oh-my-zsh/custom} /themes/powerlevel10k vim ./zshrcexport MAKEFLAGS="-j$(nproc) "
WSL启用和禁用 # 禁用 Hyper-V 和虚拟机平台 dism /online /disable-feature /featurename:Microsoft-Hyper-V /norestart dism /online /disable-feature /featurename:VirtualMachinePlatform /norestart# 清理残留驱动 bcdedit /set hypervisorlaunchtype off shutdown /r /t 0# 重启后重新启用 dism /online /enable-feature /featurename:Microsoft-Hyper-V /all /norestart dism /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart bcdedit /set hypervisorlaunchtype auto shutdown /r /t 0
内核编译 -ubuntu GitHub - microsoft/WSL2-Linux-Kernel: The source for the Linux kernel used in Windows Subsystem for Linux 2 (WSL2)
官方教程:
sudo apt install build-essential flex bison dwarves libssl-dev libelf-dev cpio qemu-utils debhelper build-essential make menuconfig KCONFIG_CONFIG=Microsoft/config-wsl make -j$(nproc ) KCONFIG_CONFIG=Microsoft/config-wsl && make -j$(nproc ) INSTALL_MOD_PATH="$PWD /modules" modules_install make -j16 KCONFIG_CONFIG=Microsoft/config-wsl bindeb-pkgcp arch /x86/boot/bzImage /mnt/c/Users/sevenx/Documents/02-devTool [wsl2] kernel=C:\\Users\\sevenx\\Documents\\02-devTool\\bzImage
自己定义:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 cd ~ git clone --depth 1 https://github.com/microsoft/WSL2-Linux-Kernelcd WSL2-Linux-Kernelcp ./Microsoft/config-wsl .config make menuconfig grep CONFIG_DEBUG_INFO .config grep CONFIG_KPROBES .config grep CONFIG_DEBUG_FS .config grep CONFIG_RELAY .config grep CONFIG_DEBUG_INFO_DWARF4 .config sed -i 's/# CONFIG_DEBUG_INFO_DWARF4 is not set/CONFIG_DEBUG_INFO_DWARF4=y/' .config sudo apt install build-essential flex bison dwarves libssl-dev libelf-dev cpio qemu-utils yay -S dpkg debhelper fakeroot bc rsync git binutils make gcc flex bison openssl libelf make -j$(nproc ) deb-pkg
systemtap 推荐自编译安装,防止遇到其他问题
wget https://sourceware.org/systemtap/ftp/releases/systemtap-5.2.tar.gz tar -xzvf systemtap-5.2.tar.gz cd systemtap-5.2 ./configure --prefix=/usr/local make sudo make install
报错 configure: error: missing elfutils development headers/libraries (install elfutils-devel, libebl-dev, libdw-dev and/or libebl-devel)
答:缺失elfutils,手动编译安装
wget https://sourceware.org/elfutils/ftp/0.192/elfutils-0.192.tar.bz2 tar -xf elfutils-0.192.tar.bz2cd elfutils-0.192 make && sudo make install
stap命令报错如下:
答:卸载apt包管理安装的后,自编译安装重新执行命令成功