在 Windows 上运行 Linux:WSL2 完整指南(二)

news2024/9/22 7:07:52

系列文章目录

在 Windows 上运行 Linux:WSL2 完整指南(一)🚪
在 Windows 上运行 Linux:WSL2 完整指南(二)🚪


文章目录

  • 系列文章目录
  • 前言
  • 四、常见问题及解决方法
    • 问题二:0x800701bc
    • 问题三:0x80080005
  • 五、WSL 美化
    • 5.1 准备工作
    • 5.2 安装 oh-my-zsh 美化包
    • 5.3 安装 Powerline9k 主题
    • 5.4 安装字体
  • 六、oh-my-zsh插件
    • 6.1 安装插件
    • 6.2 添加天气和时钟显示
    • 6.3 启动动画
  • 总结


前言

在第一篇文章中,我们介绍了 WSL2 的特点和与传统虚拟机的比较,并讲解了如何在 Windows 上安装和配置 WSL2。在这篇文章中,我们将继续解决一些常见问题,并介绍如何对 WSL2 进行美化,使其使用体验更加友好。

在这里插入图片描述


四、常见问题及解决方法

问题二:0x800701bc

描述:在安装完 Linux 分发版之后可能会出现报错。

在这里插入图片描述

这个错误可能是因为电脑版本过低,需要下载安装适用于 x64 计算机的最新 WSL2 Linux 内核更新包。

解决方法:
下载链接:WSL2 Linux 内核更新包🚪。下载完更新包之后点击 next -> finish 即可解决问题。

问题三:0x80080005

描述:在输入用户名 huahua 的时候报错WslLaunchInteractive adduser --quiet --gecos '' huahua failed with error: 0x80080005

这个错误通常与COM(组件对象模型)服务有关,可能是由于WSL安装或配置的问题导致的

解决方法:

  1. 尝试重启 WSL 服务。在 PowerShell(以管理员身份运行)中执行以下命令:
net stop LxssManager
net start LxssManager
  1. 如果特定的Linux发行版出现问题,可以尝试重置该发行版。注意,这会清除该发行版中的所有数据。然后重新安装该发行版。
wsl --unregister <发行版名称>
  1. 确保已经启用了WSL和虚拟机平台功能。在PowerShell(以管理员身份运行)中执行以下命令:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
  1. 尝试重装WSL组件。在PowerShell(以管理员身份运行)中执行以下命令:
dism.exe /online /disable-feature /featurename:Microsoft-Windows-Subsystem-Linux
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

五、WSL 美化

5.1 准备工作

确保已经存在 WSL2,并在微软商店下载并安装 Windows Terminal。

5.2 安装 oh-my-zsh 美化包

  1. 安装 zsh:
sudo apt update
sudo apt install zsh -y

在这里插入图片描述

  1. 安装oh-my-zsh(代理工具🚪)
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

在这里插入图片描述

5.3 安装 Powerline9k 主题

  1. 安装主题
git clone https://github.com/bhilburn/powerlevel9k.git ~/.oh-my-zsh/custom/themes/powerlevel9k

在这里插入图片描述

  1. 启用主题:编辑 ~/.zshrc 配置文件,修改 ZSH_THEME 项的内容为:ZSH_THEME="powerlevel9k/powerlevel9k"
    在这里插入图片描述

5.4 安装字体

访问 nerd-fonts🚪 的 Github release 页,下载某种字体的压缩包(如 JetBrainsMono.zip),解压后在 Windows 系统上安装字体文件(有些时候可能需要使用管理员权限安装)

修改 Windows Terminal 的默认字体:
在这里插入图片描述


六、oh-my-zsh插件

6.1 安装插件

  1. 安装 zsh-autosuggestions(自动补全):
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
  1. 安装 zsh-syntax-highlighting(高亮显示):
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
  1. 启用插件(包含默认插件):修改 ~/.zshrc 配置文件的 plugins 项,内容如下(可按需添加或删减)
plugins=(
  cargo
  command-not-found
  docker
  git
  golang
  npm
  nvm
  rust
  sudo
  systemd
  web-search
  zsh-autosuggestions
  zsh-syntax-highlighting
)

6.2 添加天气和时钟显示

用一个shell脚本显示
root文件夹下新建一个weather-clock.sh文件,代码如下:

#!/bin/bash

# NAME: now
# PATH: $HOME/bin
# DESC: Display current weather, calendar and time
# CALL: Called from terminal or ~/.bashrc
# DATE: Apr 6, 2017. Modified: May 24, 2019.

# UPDT: 2019-05-24 If Weather unavailable nicely formatted error message.

# NOTE: To display all available toilet fonts use this one-liner:
#       for i in ${TOILET_FONT_PATH:=/usr/share/figlet}/*.{t,f}lf; do j=${i##*/}; toilet -d "${i%/*}" -f "$j" "${j%.*}"; done

# Setup for 92 character wide terminal
DateColumn=34 # Default is 27 for 80 character line, 34 for 92 character line
TimeColumn=61 # Default is 49 for   "   "   "   "    61 "   "   "   "

# Replace Edmonton with your city name, GPS, etc. See: curl wttr.in/:help
curl wttr.in/Shanghai?0 --silent --max-time 3 > /tmp/now-weather
# Timeout #. Increase for slow connection---^

readarray aWeather < /tmp/now-weather
rm -f /tmp/now-weather

# Was valid weather report found or an error message?
if [[ "${aWeather[0]}" == "Weather report:"* ]] ; then
    WeatherSuccess=true
    echo "${aWeather[@]}"
else
    WeatherSuccess=false
    echo "+============================+"
    echo "| Weather unavailable now!!! |"
    echo "| Check reason with command: |"
    echo "|                            |"
    echo "| curl wttr.in/Edmonton?0    |" # Replace Edmonton with your city
    echo "|   --silent --max-time 3    |"
    echo "+============================+"
    echo " "
fi
echo " "                # Pad blank lines for calendar & time to fit

#--------- DATE -------------------------------------------------------------

# calendar current month with today highlighted.
# colors 00=bright white, 31=red, 32=green, 33=yellow, 34=blue, 35=purple,
#        36=cyan, 37=white

tput sc                 # Save cursor position.
# Move up 9 lines
i=0
while [ $((++i)) -lt 10 ]; do tput cuu1; done

if [[ "$WeatherSuccess" == true ]] ; then
    # Depending on length of your city name and country name you will:
    #   1. Comment out next three lines of code. Uncomment fourth code line.
    #   2. Change subtraction value and set number of print spaces to match
    #      subtraction value. Then place comment on fourth code line.
    Column=$((DateColumn - 10))
    tput cuf $Column        # Move x column number
    # Blank out ", country" with x spaces
    printf "          "
else
    tput cuf $DateColumn    # Position to column 27 for date display
fi

# -h needed to turn off formating: https://askubuntu.com/questions/1013954/bash-substring-stringoffsetlength-error/1013960#1013960
cal > /tmp/terminal1
# -h not supported in Ubuntu 18.04. Use second answer: https://askubuntu.com/a/1028566/307523
tr -cd '\11\12\15\40\60-\136\140-\176' < /tmp/terminal1  > /tmp/terminal

CalLineCnt=1
Today=$(date +"%e")

printf "\033[32m"   # color green -- see list above.

while IFS= read -r Cal; do
    printf "%s" "$Cal"
    if [[ $CalLineCnt -gt 2 ]] ; then
        # See if today is on current line & invert background
        tput cub 22
        for (( j=0 ; j <= 18 ; j += 3 )) ; do
            Test=${Cal:$j:2}            # Current day on calendar line
            if [[ "$Test" == "$Today" ]] ; then
                printf "\033[7m"        # Reverse: [ 7 m
                printf "%s" "$Today"
                printf "\033[0m"        # Normal: [ 0 m
                printf "\033[32m"       # color green -- see list above.
                tput cuf 1
            else
                tput cuf 3
            fi
        done
    fi

    tput cud1               # Down one line
    tput cuf $DateColumn    # Move 27 columns right
    CalLineCnt=$((++CalLineCnt))
done < /tmp/terminal

printf "\033[00m"           # color -- bright white (default)
echo ""

tput rc                     # Restore saved cursor position.

#-------- TIME --------------------------------------------------------------

tput sc                 # Save cursor position.
# Move up 8 lines
i=0
while [ $((++i)) -lt 9 ]; do tput cuu1; done
tput cuf $TimeColumn    # Move 49 columns right

# Do we have the toilet package?
if hash toilet 2>/dev/null; then
    echo " $(date +"%I:%M %P") " | \
        toilet -f future --filter border > /tmp/terminal
# Do we have the figlet package?
elif hash figlet 2>/dev/null; then
#    echo $(date +"%I:%M %P") | figlet > /tmp/terminal
    date +"%I:%M %P" | figlet > /tmp/terminal
# else use standard font
else
#    echo $(date +"%I:%M %P") > /tmp/terminal
    date +"%I:%M %P" > /tmp/terminal
fi

while IFS= read -r Time; do
    printf "\033[01;36m"    # color cyan
    printf "%s" "$Time"
    tput cud1               # Up one line
    tput cuf $TimeColumn    # Move 49 columns right
done < /tmp/terminal

tput rc                     # Restore saved cursor position.

exit 0

输入 curl wttr.in 命令可以查看当前位置天气情况
在这里插入图片描述
如果要更换为自己所在城市的天气,在上面的代码19行处,可自行更换为自己所在城市。运行上面的代码还需要下载两个插件,一个是ncaltoilet,分别是日期和时钟

sudo apt install ncal toilet

最后编辑 ~/.zshrc 配置文件,在最后一行加上bash /root/weather-clock.sh代码,重新打开WSL即可看到
在这里插入图片描述

6.3 启动动画

运行git clone https://github.com/pipeseroni/pipes.sh.git命令,在~/.zshrc 配置文件天气的前一行加上bash /root/pipes.sh/pipes.sh -p 5即可
在这里插入图片描述
运行效果为如下图片,按下空格键可退出动画:
在这里插入图片描述


总结

通过上述步骤,我们可以有效解决在使用 WSL2 过程中可能遇到的常见问题,并对 WSL2 进行美化,使其使用体验更加友好。希望这篇文章能为您在 Windows 上运行 Linux 提供帮助。希望这篇博客对你有所帮助,如果有任何疑问或需要进一步的信息,欢迎随时讨论🌹

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1932981.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

本地部署,edge-tts文本转语音解决方案

目录 什么是 edge-tts&#xff1f; 主要特点 应用场景 优势 开始使用 edge-tts 命令行安装 edge-tts 库&#xff1a; docker安装 未来展望 总结 https://github.com/rany2/edge-ttshttps://github.com/rany2/edge-tts 随着科技的进步&#xff0c;文本转语音&#xff…

PyCharm查看文件或代码变更记录

背景&#xff1a; Mac笔记本上有一个截图的定时任务在运行&#xff0c;本地Python使用的是PyCharm IDE&#xff0c;负责的同事休假&#xff0c;然后定时任务运行的结果不符合预期&#xff0c;一下子不知道问题出现在哪里。 定位思路&#xff1a; 1、先确认网络、账号等基本的…

Flutter动画详解第二篇之显式动画(Explicit Animations)

目录 前言 一、定义 1.AnimationController 1.常用属性 1. value 2. status 3. duration 2.常用方法 1.forward 2.reverse 3.repeat 4.stop 5. reset 6. animateTo(double target, {Duration? duration, Curve curve Curves.linear}) 7.animateBack(double ta…

android R ext4 image打包脚本介绍

一、Android R打包指令使用介绍 &#xff08;1&#xff09;mkuserimg_mke2fs #./mkuserimg_mke2fs --help usage: mkuserimg_mke2fs [-h] [--android_sparse] [--journal_size JOURNAL_SIZE][--timestamp TIMESTAMP] [--fs_config FS_CONFIG][--product_out PRODUCT_OUT][--b…

Nginx、LNMP万字详解

目录 Nginx 特点 Nginx安装 添加Nginx服务 Nginx配置文件 全局配置 HTTP配置 状态统计页面 Nginx访问控制 授权用户 授权IP 虚拟主机 基于域名 测试 基于IP 测试 基于端口 测试 LNAMP 解析方式 LNMP转发php-fpm解析 Nginx代理LAMP解析 LNMP部署示例 实…

live555 rtsp服务器实战之doGetNextFrame

live555关于RTSP协议交互流程 live555的核心数据结构值之闭环双向链表 live555 rtsp服务器实战之createNewStreamSource live555 rtsp服务器实战之doGetNextFrame 注意&#xff1a;该篇文章可能有些绕&#xff0c;最好跟着文章追踪下源码&#xff0c;不了解源码可能就是天书…

message from server: “Too many connections“

theme: nico 你们好&#xff0c;我是金金金。 场景 启动服务时&#xff0c;报错如上&#xff1a;数据源拒绝建立连接&#xff0c;服务器发送消息&#xff1a;“连接过多” 排查 看报错信息提示的很明显了 查看MySQL 数据库中最大允许连接数的配置信息&#xff08;我mysql是部…

LabVIEW Communications LTE Application Framework 读书笔记

目录 硬件要求一台设备2台USRPUSRP-2974 示例项目的组件文件夹结构DL Host.gcompeNodeB Host.gcompUE Host.gcompBuildsCommonUSRP RIOLTE 操作模式DLeNodeBUE 项目组件单机双机UDP readUDP writeMAC TXMAC RXDL TX PHYDL RX PHYUL TX PHYUL RX PHYSINR calculationRate adapta…

python入门课程Pro(1)--数据结构及判断

数据结构及判断 第1课 复杂的多向选择1.if-elif-else2.if嵌套3.练习题&#xff08;1&#xff09;大招来了&#xff08;2&#xff09;奇数还是偶数&#xff08;3&#xff09;简洁代码 第2课 数据与判断小结1.变量2.格式化输出3.逻辑运算-或与非4.判断条件5.练习题&#xff08;1&…

基于 JAVA 的旅游网站设计与实现

点击下载源码 塞北村镇旅游网站设计 摘要 城市旅游产业的日新月异影响着村镇旅游产业的发展变化。网络、电子科技的迅猛前进同样牵动着旅游产业的快速成长。随着人们消费理念的不断发展变化&#xff0c;越来越多的人开始注意精神文明的追求&#xff0c;而不仅仅只是在意物质消…

[word] word如何编写公式? #微信#知识分享

word如何编写公式&#xff1f; word如何编写公式&#xff1f;Word中数学公式是经常会使用到的&#xff0c;若是要在文档中录入一些复杂的公式&#xff0c;要怎么做呢&#xff1f;接下来小编就来给大家讲一讲具体操作&#xff0c;一起看过来吧&#xff01; 方法一&#xff1a;…

RISC-V在线反汇编工具

RISC-V在线反汇编工具&#xff1a; https://luplab.gitlab.io/rvcodecjs/#q34179073&abifalse&isaAUTO 不过&#xff0c;似乎&#xff0c;只支持RV32I、RV64I、RV128I指令集&#xff1a;

Flutter热更新技术探索

一&#xff0c;需求背景&#xff1a; APP 发布到市场后&#xff0c;难免会遇到严重的 BUG 阻碍用户使用&#xff0c;因此有在不发布新版本 APP 的情况下使用热更新技术立即修复 BUG 需求。原生 APP&#xff08;例如&#xff1a;Android & IOS&#xff09;的热更新需求已经…

【精品资料】物业行业BI大数据解决方案(43页PPT)

引言&#xff1a;物业行业BI&#xff08;Business Intelligence&#xff0c;商业智能&#xff09;大数据解决方案是专为物业管理公司设计的一套综合性数据分析与决策支持系统。该解决方案旨在通过集成、处理、分析及可视化海量数据&#xff0c;帮助物业企业提升运营效率、优化资…

SCSA第七天

防火墙的可靠性 因为防火墙上不仅需要同步配置信息&#xff0c;还需要同步状态信息&#xff08;会话表等&#xff09;&#xff0c;所以&#xff0c;防火墙不能 像路由器那样单纯的靠动态协议来实现切换&#xff0c;需要用到双机热备技术。 1&#xff0c;双机 --- 目前双机热…

yearrecord——一个类似痕迹墙的React数据展示组件

介绍一下自己做的一个类似于力扣个人主页提交记录和GitHub主页贡献记录的React组件。 下图分别是力扣个人主页提交记录和GitHub个人主页的贡献记录&#xff0c;像这样类似痕迹墙的形式可以比较直观且高效得展示一段时间内得数据记录。 然而要从0实现这个功能还是有一些麻烦得…

构建gitlab远端服务器(check->build->test->deploy)

系列文章目录 提示:这里可以添加系列文章的所有文章的目录,目录需要自己手动添加 TODO:写完再整理 文章目录 系列文章目录前言构建gitlab远端服务器一、步骤一:搭建gitlab的运行服务器【运维】1. 第一步:硬件服务器准备工作(1)选择合适的硬件和操作系统linux(2)安装必…

QT-RTSP相机监控视频流

QT-RTSP相机监控视频流 一、演示效果二、关键程序三、下载链接 一、演示效果 二、关键程序 #include "mainwindow.h"#include <QDebug>MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), m_settings("outSmart", "LiveWatcher&…

算法题目整合

文章目录 121. 小红的区间翻转142. 两个字符串的最小 ASCII 删除总和143. 最长同值路径139.完美数140. 可爱串141. 好二叉树 121. 小红的区间翻转 小红拿到了两个长度为 n 的数组 a 和 b&#xff0c;她仅可以执行一次以下翻转操作&#xff1a;选择a数组中的一个区间[i, j]&…

Apache AGE的MATCH子句

MATCH子句允许您在数据库中指定查询将搜索的模式。这是检索数据以在查询中使用的主要方法。 通常在MATCH子句之后会跟随一个WHERE子句&#xff0c;以添加用户定义的限制条件到匹配的模式中&#xff0c;以操纵返回的数据集。谓词是模式描述的一部分&#xff0c;不应被视为仅在匹…