Skip to content

Linux 日用

为什么

在 Linux 安装完成后,往往还需要一系列的配置、软件安装、软硬件问题处理后,才能更完美地日用。

如何解决日用问题

本文将囊括以下内容(以 Arch/Debian 为例):

  • 安装中的一系列配置
  • 安装后的一系列配置
  • 日用中每一次的问题
  • 使用经验

安装中的一系列配置

○ 蜂鸣器禁用

sh
rmmod pcspkr

○ 镜像源优化

sh
# 优化一次,然后禁用自动更新
reflector -c China --sort score --save /etc/pacman.d/mirrorlist
systemctl stop reflector.service
systemctl status reflector.service

# 优化下载过程,颜色高亮 + 并行下载
# 删除 Misc options 下的 Color 和 ParallelDownloads 前面的注释
vim /etc/pacman.conf

○ btrfs 子卷划分

划分好子卷,便于创建快照时不包含缓存文件夹,减少无用信息快照,加快快照速度。

  • /@:根目录子卷,需快照
  • /@home:家目录子卷,需快照
  • /@snapshots:快照目录子卷,存放快照
  • /@tmp:/tmp 目录子卷
  • /@log:/var/log 目录子卷
  • /@cache:/var/cache 目录子卷

子卷创建参考:安装 Arch - 分区

○ 用户创建与 sudo 无需密码提权

sh
user add -m -G wheel -s /bin/bash ${user}
passwd ${user}

visudo
%wheel ALL=(ALL:ALL) NOPASSWD: ALL

○ KDE 精简安装

sh
# 参考包合集中的子包合集: https://archlinux.org/packages/extra/any/kde-applications-meta/
# 参考 KDE 推荐包:https://community.kde.org/Distributions/Packaging_Recommendations
sudo pacman -S plasma sddm kde-utilities-meta kde-system-meta
sudo pacman -S gwenview kdegraphics-thumbnailers koko spectacle
systemctl enable sddm

安装后一系列配置

○ 网络代理

参考 mihomo

○ dotfiles 管理

sh
# 以 chezmoi 为例
paru -S chezmoi

# 在 ~/.local/share/chezmoie 创建 git 仓库,存储源文件状态(备份)
chezmoi init

# 添加 dotfile
chezmoi add ~/.bashrc
chezmoi edit ~/.bashrc

○ 字体优化

sh
# 先下载 nerd fonts:https://www.nerdfonts.com/font-downloads,如 JetBrainsMono Nerd Font

# 安装字体,并获取字体 family 名(如:JetBrainsMonoNL NF)
mkdir -p ~/.local/share/fonts
mv ~/Downloads/JetBrainsMono/* ~/.local/share/fonts/
fc-cache -fv
fc-list | grep ${font_name}

# 安装其他字体
paru -S noto-fonts inter-font noto-fonts-cjk noto-fonts-emoji ttf-sarasa-gothic

# 下载字体配置,按需修改内容,https://github.com/szclsya/dotfiles/blob/master/fontconfig/fonts.conf
# 修改 monospace 的 family 为 JetBrainsMonoNL NF

# 替换字体配置,重新登录生效
mkdir -p ~/.config/fontconfig
cp ./fonts.conf ~/.config/fontconfig/

○ 中文输入(Wayland)

参考 rime

sh
# 安装输入法
paru -S fcitx5-im fcitx5-rime

# 下载并解压薄荷输入法:https://github.com/Mintimate/oh-my-rime
# 修改输入方案和自定义短语

# 安装薄荷输入法
cp -r ./oh-my-rime-main/* ~/.local/share/fcitx5/rime/

# 启用输入法
# 设置 -> 虚拟键盘 -> fcitx5 wayland
# 设置 -> 输入法 -> 添加 rime

# 更新 rime 配置后需重新部署,或重启

# chromium/electron 应用需添加启动参数,以支持输入
# 应用桌面图标可配置启动参数
--enable-features=UseOzonePlatform --ozone-platform=wayland --enable-wayland-ime

○ 应用快捷方式

全局应用,路径:/usr/share/applications/xxx.desktop 用户应用,路径:~/.local/share/applications/xxx.desktop

ini
[Desktop Entry]
Name=VSCode
Comment=Visual Studio Code
Exec=/opt/vscode/code --enable-features=UseOzonePlatform --ozone-platform=wayland --enable-wayland-ime
Icon=/opt/vscode/resources/app/resources/linux/code.png
Type=Application

○ CPU 能效优化

sh
# arch wiki 无效,参考:https://github.com/AdnanHodzic/auto-cpufreq
# 安装
git clone https://github.com/AdnanHodzic/auto-cpufreq.git
cd auto-cpufreq
sudo ./auto-cpufreq-installer
# 启动
sudo auto-cpufreq --install

# 查看当前 cpu 能效值,0-15,越小性能越好,越大越省电
cat /sys/devices/system/cpu/cpu<N>/power/energy_perf_bias

# 使用节能模式
sudo auto-cpufreq --force powersave
sudo auto-cpufreq --force performance
auto-cpufreq --stats

○ btrfs 快照创建与恢复

sh
# 创建快照,参数需用路径而不是子卷名
sudo btrfs subvolume snapshot -r / /.snapshots/root-250101-001
sudo btrfs subvolume snapshot -r /home /.snapshots/home-250101-001
# 查看快照,子卷和快照都会列出
sudo btrfs subvolume list /
# 删除快照
sudo btrfs subvolume delete /.snapshots/home-250101-001

# 恢复快照,先通过 livecd 进入 arch-chroot
sudo mv /mnt/@ /mnt/@.broken
sudo btrfs subvolume snapshot /mnt/@snapshots/root-250101-001 /mnt/@
# 恢复后,删除废弃子卷
sudo btrfs subvolume delete /mnt/@.broken

○ 终端跳转记忆

使用:https://github.com/ajeetdsouza/zoxide

sh
# 第一次完整跳转
z /path/to/abc

# 第二次精简跳转,有冲突时按 space+tab 选择目的
z abc

○ 终端文件管理

使用:https://github.com/sxyazi/yazi,已包含 zoxide

用法:https://yazi-rs.github.io/docs/quick-start

○ 按键映射

sh
# keyd
paru -S keyd
sudo systemctl enable keyd --now
# 参考 wiki 中的推荐配置,oneshot 自动拼接下一个按键,overload 按住时映射,值为 none 表示禁用
vim /etc/keyd/default.conf
sudo keyd reload
sudo keyd monitor

○ 截图并粘贴到 VSCode

  • vscode 中安装 dendron.dendron-paste-image 插件
  • vscode 配置中添加 "pasteImage.path": "${currentFileDir}/img"
  • 系统安装 paru -S wl-clipboard flameshot
  • vscode md 文件中,按 ctrl+alt+v 粘贴

○ Starship

sh
paru -S starship
echo 'eval "$(starship init bash)"' >> ~/.bashrc
source ~/.bashrc

:::info

○ Git

sh
paru -S git
# git log 等依赖 less 命令
paru -S less
git config --global user.name ${name}
git config --global user.emial ${email}

# 编辑器改为 vscode
git config --global core.editor "code --enable-features=UseOzonePlatform --ozone-platform=wayland --enable-wayland-ime --wait"
# 全局存储凭证
git config --global credential.helper store
# ⌛ssh、默认分支 master 等

# github https push 时,用户密码需为 access token
# setting -> developer setting -> token classic

○ Node.js

sh
paru -S aur/nvm-git
echo 'source /usr/share/nvm/init-nvm.sh' >> ~/.bashrc
source ~/.bashrc
nvm install --lts
nvm use --lts

# 安装 pnpm:<https://pnpm.io/installation>
curl -fsSL https://get.pnpm.io/install.sh | sh -
source ~/.bashrc

○ Rust/Cargo

sh
# 参考:https://www.rust-lang.org/tools/install
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

○ 游戏包

sh
paru -S --needed arch-gaming-meta

日用问题

○ 花屏

sh
# 参考:https://formerlunchbox.com/2024/05/13/%E6%9C%BA%E6%A2%B0%E9%9D%A9%E5%91%BD14x-%E5%AE%89%E8%A3%85-arch-linux-kde-plasma-6/#%E5%85%B3%E4%BA%8E%E7%94%BB%E9%9D%A2%E6%92%95%E8%A3%82%E9%97%AE%E9%A2%98
kate /etc/default/grub
# amd,联想 yoga 上有效,... 为占位省略
GRUB_CMDLINE_LINUX_DEFAULT="... amdgpu.dcdebugmask=0x10"
# intel 可能需要加
GRUB_CMDLINE_LINUX_DEFAULT="... i915.enable_psr=0"

# 替换 grub 配置并生效
sudo grub-mkconfig -o /boot/grub/grub.cfg
reboot

○ 蓝牙无法开启,无法搜索配对

sh
systemctl enable --now bluetooth

# 蓝牙,或需要通过 rfkill list 来检查软硬件锁
# 无法开启则需要安装
paru -S bluez bluez-utils blueman

○ 使用锁屏熄屏,不睡眠不休眠

睡眠后,唤醒容易出现一堆问题:掉 wifi,掉蓝牙,掉 btrfs 子卷挂载......往往需要以来重启来解决。

为了避免这些问题,尝试不使用睡眠、休眠,而使用锁屏熄屏。

解决方案参考:

○ Python 安装依赖并构建

sh
# 安装 pip 依赖时,可能报错 error: externally-managed-environment
# 需要通过 python 创建一个虚拟环境,激活虚拟环境后再安装依赖。通过 pipx 简化这个过程
paru -Ss pipx

# 安装依赖:克隆 python 项目后,进入目录,通过 pipx 从 requirements.txt 中逐行读取安装
while read requirement; do
    pipx install "$requirement"
done < requirements.txt

# 安装程序
pipx install .
sh
# 使用 uv
uv pip install -r requirements.txt
python main.py

使用经验

○ KDE

通用:

  • 启动应用:alt+space
  • 启动终端:ctrl+alt+t
  • 最近任务:win+w

Spectacle 截图:

  • 当前窗口:win+prtsc
  • 选择窗口:win+ctrl+prtsc
  • 全屏:shift+prtsc
  • 框选:win+shift+prtsc

○ 局域网文件共享

go-file,局域网分享,带启动器一键启用,扫码下载,同时可分享文件夹和视频

访问量 PV:Blocked用户数 UV:Blocked