LinuxMint和Ubuntu使用中的一些记录
LinuxMint和Ubuntu使用中的一些记录。
1、开机时间过长的分析和解决。
systemd-analyze命令可以查看启动时间:
Startup finished in 5.089s (firmware) + 9.247s (loader) + 4.299s (kernel) + 9.269s (userspace) = 27.906s
systemd-analyze blame命令可以查看各个服务的启动时间:
6.575s NetworkManager-wait-online.service
1.103s dev-sda4.device
804ms systemd-random-seed.service
785ms networkd-dispatcher.service
604ms udisks2.service
373ms cups.service
371ms accounts-daemon.service
289ms zfs-load-module.service
281ms ubuntu-system-adjustments.service
268ms systemd-udevd.service
267ms systemd-journal-flush.service
251ms apparmor.service
245ms avahi-daemon.service
243ms bluetooth.service
239ms NetworkManager.service
231ms dns-clean.service
227ms polkit.service
222ms ModemManager.service
221ms user@1000.service
188ms thermald.service
186ms systemd-logind.service
181ms wpa_supplicant.service
168ms gpu-manager.service
这时候就可以根据服务的功能决定是否可以禁用或者关闭开机自启:
sudo systemctl unmask NetworkManager-wait-online.service #屏蔽
sudo systemctl mask NetworkManager-wait-online.service
sudo systemctl disable NetworkManager-wait-online.service
sudo systemctl enable NetworkManager-wait-online.service
“systemctl mask"和"systemctl disable"的区别:
执行
systemctl disable xxx后,会禁用这个服务。它实现的方法是将服务对应的软连接从/etc/systemd/system中删除。执行
systemctl mask xxx会屏蔽这个服务。它和systemctl disable xxx的区别在于,前者只是删除了符号链接,后者会建立一个指向/dev/null的符号链接,这样,即使有其他服务要启动被mask的服务,仍然无法执行成功。 如果使用了mask,要想重新启动服务,必须先执行``unmask将服务取消屏蔽。mask和unmask`是一对操作,用来屏蔽和取消屏蔽服务。
2、搜狗拼音输入法的问题
搜狗拼音输入法官网最新版本:sogoupinyin_4.2.1.145_amd64.deb有问题,安装后打字不出字。可以安装sogoupinyin_4.0.1.2800_x86_64.deb,来源aur:fcitx-sogoupinyin。
3、wps安装后启动提示缺失字体的问题
下载安装字体就好了,收集的字体下载地址:
- 百度网盘字体包链接:
- https://pan.baidu.com/s/1qBhUgfbj-rcDMXX7Qva7aQ 提取码:
g608 - https://pan.baidu.com/s/1d2h2khml3wAu1phOLcmR-w 提取码:
n5m3 - GitHub字体包链接:
- https://github.com/BannedPatriot/ttf-wps-fonts
将下载的字体复制到/usr/share/fonts/wps-office 文件夹中。
github 项目的更简单:
git clone https://github.com/iamdh4/ttf-wps-fonts.git
cd ttf-wps-fonts
sudo bash install.sh
cd ..
rm -rf /tmp/ttf-wps-fonts
字体问题解决。
4、Grub-Customizer管理grub引导
Grub Customizer 是一款有用的GRUB2和BURG的图形化设置管理器。通过使用此工具,您不必理会繁琐复杂的配置文件,只需要直观的点击鼠标,就可以添加、删除和重新排列引导菜单条目。用于修改默认的 Grub 引导加载程序设置。您可以编辑内核参数并选择更改启动时的时间延迟,以便从默认条目启动。该软件还允许您进行外观配置,例如更改文本颜色和背景图像。ubuntu的仓库中默认没有包含Grub Customizer,需要添加源来安装:
sudo add-apt-repository ppa:danielrichter2007/grub-customizer
sudo apt update
sudo apt install grub-customizer
5、Cinnammon不显示托盘图标的解决办法
使用Ubuntu Cinnammon风味版时,Cinnammon不显示托盘图标。也许是个小bug,但是可以解决。
使用cinnamon --replace命令重启Cinnammon测试,如果没有问题,就添加为开机重启命令。
6、新系统设置的一个脚本
✅ 功能汇总
- 自动检测 Ubuntu 源文件格式(传统
sources.list或新 DEB822 格式)并替换为 中科大源(含 security)。 - 检查是否安装
gedit,若未安装且系统存在xed,则自动创建软链接/usr/bin/gedit -> /usr/bin/xed。 - 安装并配置 pip 使用 清华源。
- 安装 Python 依赖包(requests、flask 等)。
- 安装常用软件:git、vim、gimp。
- 安装语言支持组件。
- 禁用或卸载 snap、删除 snap 应用。
- 卸载 LibreOffice 与 Thunderbird。
- 设置 GRUB 启动等待时间为 2 秒。
🧩 ubuntu_init_setup.sh
#!/usr/bin/env bash
# Ubuntu & Linux Mint 初始化优化脚本 - 中科大源版
# 兼容 Ubuntu 22.04 / 24.04(含新 DEB822 源格式)
# ==========================================
# 🛑 核心容错机制设置
# ==========================================
# 关闭遇到错误自动退出的机制(Bash默认也是关闭的,这里显式声明)
set +e
# 设置非交互模式,防止 apt 安装时弹出对话框卡住脚本
export DEBIAN_FRONTEND=noninteractive
echo "=== 🧩 Ubuntu & Linux Mint 初始化脚本开始执行 ==="
# 确保使用 sudo 执行脚本
if [ "$EUID" -ne 0 ]; then
echo "❌ 错误:请使用 sudo 运行此脚本!例如:sudo bash $0"
exit 1
fi
# 🔑 获取真实的普通用户名(防止 sudo 环境下 $USER 变成 root)
ACTUAL_USER="${SUDO_USER:-$USER}"
echo ">>> 👤 当前真实执行用户为: $ACTUAL_USER"
# ==========================================
# 1️⃣ 替换为中科大源
# ==========================================
echo ">>> 🔄 检查并配置系统软件源..."
if [ -f /etc/linuxmint/info ]; then
echo " 🟢 检测到 Linux Mint,正在应用中科大镜像..."
MINT_SOURCE="/etc/apt/sources.list.d/official-package-repositories.list"[ -f "$MINT_SOURCE" ] && sed -i 's@packages.linuxmint.com@mirrors.ustc.edu.cn/linuxmint@g' "$MINT_SOURCE" || true[ -f "$MINT_SOURCE" ] && sed -i 's@//.*archive.ubuntu.com@//mirrors.ustc.edu.cn@g' "$MINT_SOURCE" || true[ -f "$MINT_SOURCE" ] && sed -i 's/security.ubuntu.com/mirrors.ustc.edu.cn/g' "$MINT_SOURCE" || true
else
echo " 🟢 检测到 Ubuntu 系统,检测源格式..."
if[ -f /etc/apt/sources.list.d/ubuntu.sources ]; then
echo " >>> DEB822 新源格式 => 替换为中科大源"
sed -i 's@//.*archive.ubuntu.com@//mirrors.ustc.edu.cn@g' /etc/apt/sources.list.d/ubuntu.sources || true
sed -i 's/security.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list.d/ubuntu.sources || true
elif[ -f /etc/apt/sources.list ]; then
echo " >>> 传统源格式 => 替换为中科大源"
sed -i 's@//.*archive.ubuntu.com@//mirrors.ustc.edu.cn@g' /etc/apt/sources.list || true
sed -i 's/security.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list || true
fi
fi
# ==========================================
# 配置 Google Chrome & VS Code 源
# ==========================================
echo ">>> 🟢 配置 Google Chrome 源..."
CHROME_LIST="/etc/apt/sources.list.d/google-chrome.list"
if[ ! -f "$CHROME_LIST" ]; then
wget -q -O /tmp/google-linux-key.pub https://dl.google.com/linux/linux_signing_key.pub || true
gpg --dearmor -o /usr/share/keyrings/google-chrome.gpg /tmp/google-linux-key.pub 2>/dev/null || true
echo "deb[arch=amd64 signed-by=/usr/share/keyrings/google-chrome.gpg] https://dl.google.com/linux/chrome/deb/ stable main" > "$CHROME_LIST" || true
else
echo " ✔️ Chrome源已存在,跳过"
fi
echo ">>> 🟢 配置 Microsoft VS Code 源..."
MS_SOURCES="/etc/apt/sources.list.d/vscode.sources"
if [ ! -f "$MS_SOURCES" ]; then
wget -q https://packages.microsoft.com/keys/microsoft.asc -O /tmp/microsoft.asc || true
gpg --dearmor /tmp/microsoft.asc -o /usr/share/keyrings/microsoft.gpg 2>/dev/null || true
cat <<EOF > "$MS_SOURCES" || true
Types: deb
URIs: https://packages.microsoft.com/repos/code
Suites: stable
Components: main
Architectures: amd64
Signed-By: /usr/share/keyrings/microsoft.gpg
EOF
else
echo " ✔️ VS Code源已存在,跳过"
fi
echo ">>> 🔄 正在更新 APT 缓存..."
apt-get update -y || echo "⚠️ APT 缓存更新存在部分失败,继续执行..."
# ==========================================
# 2️⃣ 检查并创建 gedit 与 python 软链接
# ==========================================
echo ">>> 🔗 配置基础命令软链接..."
if ! command -v gedit &>/dev/null; then
if command -v xed &>/dev/null; then
echo " 未检测到 gedit,创建 xed -> gedit 的软链接..."
ln -sf "$(command -v xed)" /usr/bin/gedit || true
fi
fi
# 强制链接 python3 到 python (添加 -f 覆盖已有错误链接)
ln -sf /usr/bin/python3 /usr/bin/python || true
# ==========================================
# 3️⃣ Python Pip 配置与 EXTERNALLY-MANAGED 移除
# ==========================================
echo ">>> 🐍 配置 Python 环境与 Pip 清华源..."
apt-get install -y python3-pip || true
# 注意:这里换成了 ACTUAL_USER,确保配置写入到普通用户目录下
su - "$ACTUAL_USER" -c "pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple" || true
su - "$ACTUAL_USER" -c "pip config set global.timeout 60" || true
# 自动寻找并备份 EXTERNALLY-MANAGED (兼容多版本Python)
EXT_FILES=$(ls /usr/lib/python3.*/EXTERNALLY-MANAGED 2>/dev/null) || true
for FILE in $EXT_FILES; do
echo " 检测到 $FILE,正在备份以解除 Pip 限制..."
mv "$FILE" "${FILE}.bk" || true
done
# ==========================================
# 4️⃣ & 5️⃣ 安装常用软件、QT支持、语言包
# ==========================================
echo ">>> 📦 安装常用软件、QT支持与语言包..."
apt-get install -y git vim gimp vlc mpv || true
apt-get install -y language-selector-common || true
# 语言包检测可能会空,用 || true 兜底
LANG_PKGS=$(check-language-support 2>/dev/null) || true
if [ -n "$LANG_PKGS" ]; then
apt-get install -y $LANG_PKGS || true
fi
# ==========================================
# 6️⃣ 禁用或卸载 snap
# ==========================================
echo ">>> 🧹 处理 Snap 守护进程与残留..."
if command -v snap &>/dev/null; then
echo " 检测到 snap,正在清理卸载..."
snap list 2>/dev/null | awk 'NR>1 {print $1}' | xargs -I{} snap remove --purge "{}" || true
systemctl stop snapd.socket snapd.service 2>/dev/null || true
systemctl disable snapd.socket snapd.service 2>/dev/null || true
apt-get purge -y snapd || true
rm -rf /home/*/.snap /root/snap /snap /var/snap /var/lib/snapd /var/cache/snapd || true
else
echo " ✔️ Snap 未安装,跳过。"
fi
# ==========================================
# 7️⃣ 卸载冗余软件并安装必要的 QT 依赖
# ==========================================
echo ">>> 🗑️ 卸载 LibreOffice、Thunderbird 与冲突输入法..."
apt-get purge -y libreoffice* thunderbird* ibus* fcitx* || true
apt-get autoremove -y || true
apt-get clean || true
echo ">>> 📦 安装 QT 开发运行库支持..."
apt-get install -y libqt5qml5 libqt5quick5 libqt5quickwidgets5 qml-module-qtquick2 libgsettings-qt1 || true
# ==========================================
# 8️⃣ 设置 GRUB 等待时间与权限目录
# ==========================================
echo ">>> ⏱️ 设置 GRUB 启动等待时间为 2 秒..."
GRUB_FILE="/etc/default/grub"
if[ -f "$GRUB_FILE" ]; then
if grep -q "^GRUB_TIMEOUT=" "$GRUB_FILE"; then
sed -i 's/^GRUB_TIMEOUT=.*/GRUB_TIMEOUT=2/' "$GRUB_FILE" || true
else
echo "GRUB_TIMEOUT=2" >> "$GRUB_FILE" || true
fi
if command -v update-grub &>/dev/null; then
update-grub || true
elif command -v grub2-mkconfig &>/dev/null; then
grub2-mkconfig -o /boot/grub2/grub.cfg || true
fi
fi
echo ">>> 📁 创建自定义软件目录与调整 SSH 权限..."
mkdir -p /opt/mysoft || true
chmod 777 /opt/mysoft || true
su - "$ACTUAL_USER" -c "mkdir -p ~/.ssh && chmod 700 ~/.ssh" || true
# ==========================================
# 9️⃣ 安装常用 Python 库 (安装给真实用户)
# ==========================================
echo ">>> 🐍 为用户 $ACTUAL_USER 安装常用 Python 库..."
# 如果某些库因为系统依赖报错,|| true 会确保脚本继续
su - "$ACTUAL_USER" -c "pip3 install -U requests lxml fake-useragent tenacity schedule pymysql playhouse flask flask-admin flask_babel peewee wtf-peewee cryptography ulid-py loguru gunicorn distro PySide6 m3u8 pyinstaller nuitka ffmpeg-python mpegdash PySide6-Fluent-Widgets" || echo "⚠️ 部分 Python 库安装失败,已跳过..."
# ==========================================
# 🔟 禁用无用开机服务并进行最终升级
# ==========================================
echo ">>> 🚀 禁用耗时的网络检查和固件更新服务以加快开机速度..."
systemctl disable NetworkManager-wait-online.service 2>/dev/null || true
systemctl disable ModemManager.service 2>/dev/null || true
systemctl disable fwupd-refresh.service 2>/dev/null || true
echo ">>> 🔄 正在执行系统最终升级与清理..."
apt-get upgrade -y || true
apt-get autoremove -y || true
echo "==============================================="
echo "=== 🎉 系统初始化完全结束!请重启以应用更改 ==="
echo "==============================================="
6、terminal 配色设置为Ubuntu默认配色
我喜欢Ubuntu默认的terminal配色,当安装linuxmint后,默认的terminal配色是mint的,所以,我决定将terminal配色设置为Ubuntu默认的配色。
- 创建一个文件,并保存为
clone-of-ubuntu.sh,内容如下:
#!/usr/bin/env bash
PROFILE_NAME="Ubuntu"
declare -a PALETTE=(
"#2E3436" "#CC0000" "#4E9A06" "#C4A000" "#3465A4" "#75507B" "#06989A" "#D3D7CF"
"#555753" "#EF2929" "#8AE234" "#FCE94F" "#729FCF" "#AD7FA8" "#34E2E2" "#EEEEEC"
)
BG="#300A24"
FG="#FFFFFF"
apply_gnome_terminal() {
local list_schema="org.gnome.Terminal.ProfilesList"
local profile_schema="org.gnome.Terminal.Legacy.Profile"
if ! gsettings list-schemas | grep -q "^$list_schema$"; then
return 1
fi
local new_uuid
new_uuid=$(uuidgen)
local current_list
current_list=$(gsettings get "$list_schema" list)
local new_list
if [[ "$current_list" == "@as []" || "$current_list" == "[]" ]]; then
new_list="['$new_uuid']"
else
current_list=${current_list#[}
current_list=${current_list%]}
new_list="[$current_list,'$new_uuid']"
fi
gsettings set "$list_schema" list "$new_list"
gsettings set "$list_schema" default "'$new_uuid'"
local path="/org/gnome/terminal/legacy/profiles:/:$new_uuid/"
gsettings set "$profile_schema:$path" visible-name "$PROFILE_NAME"
gsettings set "$profile_schema:$path" background-color "$BG"
gsettings set "$profile_schema:$path" foreground-color "$FG"
gsettings set "$profile_schema:$path" use-system-font false
gsettings set "$profile_schema:$path" font "Ubuntu Sans Mono 16"
gsettings set "$profile_schema:$path" use-theme-colors false
# Safe palette construction
local palette_str="["
for i in "${!PALETTE[@]}"; do
if [[ $i -gt 0 ]]; then
palette_str+=","
fi
palette_str+="'${PALETTE[i]}'"
done
palette_str+="]"
gsettings set "$profile_schema:$path" palette "$palette_str"
echo "✔ GNOME Terminal: 已创建并设为默认 profile \"$PROFILE_NAME\" (字体: Ubuntu Sans Mono 16)"
}
apply_xfce() {
local rc="$HOME/.config/xfce4/terminal/terminalrc"
mkdir -p "$(dirname "$rc")"
{
echo "[Configuration]"
echo "ColorPalette=$(IFS=';'; echo "${PALETTE[*]}")"
echo "BackgroundColor=$BG"
echo "ForegroundColor=$FG"
echo "ColorBackground=$BG"
echo "ColorForeground=$FG"
echo "CursorColor=$FG"
echo "FontName=Ubuntu Sans Mono 16"
} > "$rc"
echo "✔ XFCE Terminal theme applied (字体: Ubuntu Sans Mono 16)"
}
apply_tilix() {
mkdir -p ~/.config/tilix/schemes
local json="$HOME/.config/tilix/schemes/$PROFILE_NAME.json"
local palette_json=""
for color in "${PALETTE[@]}"; do
if [[ -z "$palette_json" ]]; then
palette_json="\"$color\""
else
palette_json="$palette_json,\"$color\""
fi
done
cat > "$json" <<EOF
{
"name": "$PROFILE_NAME",
"background-color": "$BG",
"foreground-color": "$FG",
"palette": [$palette_json],
"use-system-font": false,
"font": "Ubuntu Sans Mono 16"
}
EOF
echo "✔ Tilix theme applied (字体: Ubuntu Sans Mono 16)"
}
ran=0
if command -v gsettings >/dev/null 2>&1; then
apply_gnome_terminal && ran=1
fi
if command -v xfce4-terminal >/dev/null 2>&1; then
apply_xfce && ran=1
fi
if command -v tilix >/dev/null 2>&1; then
apply_tilix && ran=1
fi
if [[ $ran -eq 0 ]]; then
echo "⚠ 未检测到受支持终端(GNOME / XFCE / Tilix)" >&2
exit 1
fi
echo
echo "🎨 Ubuntu 配色方案已应用!"
echo "如未生效,请重启终端。"
- 运行脚本:
chmod +x clone-of-ubuntu.sh
./clone-of-ubuntu.sh