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 [email protected]
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 linuxmint 初始化优化脚本 - 中科大源版
# 兼容 Ubuntu 22.04 / 24.04(含新 DEB822 源格式)
# 使用方法:
# sudo chmod +x ubuntu_init_setup.sh sudo bash init_ubuntu.sh
set -e
echo "=== 🧩 Ubuntu、Linux Mint初始化脚本开始执行 ==="
if [ "$EUID" -ne 0 ]; then
echo "请使用 sudo 运行此脚本"
exit 1
fi
# === 1️⃣ 替换为中科大源 ===
echo ">>> 检查系统版本..."
if [ -f /etc/linuxmint/info ]; then
echo ">>> 🟢 检测到 Linux Mint,正在应用中科大镜像..."
MINT_SOURCE="/etc/apt/sources.list.d/official-package-repositories.list"
sed -i '[email protected]@mirrors.ustc.edu.cn/linuxmint@g' "$MINT_SOURCE"
sed -i 's@//.*archive.ubuntu.com@//mirrors.ustc.edu.cn@g' "$MINT_SOURCE"
sed -i 's/security.ubuntu.com/mirrors.ustc.edu.cn/g' "$MINT_SOURCE"
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
sed -i 's/security.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list.d/ubuntu.sources
else
echo ">>> 传统源格式 => 替换为中科大源"
sed -i 's@//.*archive.ubuntu.com@//mirrors.ustc.edu.cn@g' /etc/apt/sources.list
sed -i 's/security.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
fi
fi
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
gpg --dearmor -o /usr/share/keyrings/google-chrome.gpg /tmp/google-linux-key.pub
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/google-chrome.gpg] https://dl.google.com/linux/chrome/deb/ stable main" | tee "$CHROME_LIST"
else
echo " 已存在,跳过"
fi
echo ">>> 🟢 配置 Microsoft VS Code 源..."
MS_LIST_DIR="/etc/apt/sources.list.d"
MS_SOURCES="$MS_LIST_DIR/vscode.sources"
# 导入 key
if [ ! -f /usr/share/keyrings/microsoft.gpg ]; then
wget -q https://packages.microsoft.com/keys/microsoft.asc -O /tmp/microsoft.asc
gpg --dearmor /tmp/microsoft.asc -o /usr/share/keyrings/microsoft.gpg
fi
# 判断是否已存在
if [ ! -f "$MS_SOURCES" ]; then
cat <<EOF | tee "$MS_SOURCES"
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 " 已存在,跳过"
fi
echo ">>> 🔄 正在更新 APT 缓存..."
apt update
# === 2️⃣ 检查并创建 gedit 、python链接 ===
if ! command -v gedit &>/dev/null; then
if command -v xed &>/dev/null; then
echo "未检测到 gedit,已检测到 xed,创建软链接..."
ln -sf "$(command -v xed)" /usr/bin/gedit
else
echo "未检测到 gedit 或 xed,跳过..."
fi
else
echo "gedit 已安装,跳过软链接创建。"
fi
ln -s /usr/bin/python3 /usr/bin/python
# === 3️⃣ 安装 python3-pip 并配置清华源、自动检测 Python 3 的主版本号移除、备份EXTERNALLY-MANAGED ===
echo ">>> 安装 python3-pip 并配置清华源、自动检测 Python 3 的主版本号移除、备份EXTERNALLY-MANAGED"
apt install -y python3-pip
su - $USER -c "pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple"
su - $USER -c "pip config set global.timeout 60"
# 自动检测 Python 3 的主版本号(例如 3.12)
PYTHON_VER=$(python3 -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")')
# 构建文件路径
TARGET_FILE="/usr/lib/python${PYTHON_VER}/EXTERNALLY-MANAGED"
BACKUP_FILE="${TARGET_FILE}.bk"
# 检查文件是否存在再执行
if [ -f "$TARGET_FILE" ]; then
echo "检测到 $TARGET_FILE,正在备份..."
sudo mv "$TARGET_FILE" "$BACKUP_FILE"
echo "备份完成: $BACKUP_FILE"
else
echo "未找到 $TARGET_FILE,跳过操作"
fi
# === 4️⃣ 安装常用软件、QT支持 ===
echo ">>> 安装 git、vim、gimp、QT支持..."
apt install -y git vim gimp vlc mpv
# === 5️⃣ 安装语言支持 ===
echo ">>> 安装语言支持..."
apt install -y language-selector-common
apt install -y $(check-language-support)
# === 6️⃣ 禁用或卸载 snap ===
echo ">>> 处理 snap..."
if command -v snap &>/dev/null; then
echo "检测到 snap,正在删除 snap 应用..."
snap list | awk 'NR>1 {print $1}' | xargs -I{} snap remove --purge "{}" || true
systemctl stop snapd.socket snapd.service || true
systemctl disable snapd.socket snapd.service || true
apt purge -y snapd || true
rm -rf ~/snap /snap /var/snap /var/lib/snapd /var/cache/snapd
else
echo "snap 未安装,跳过。"
fi
# === 7️⃣ 卸载 LibreOffice 与 Thunderbird ===
echo ">>> 卸载 LibreOffice 与 Thunderbird..."
apt purge -y libreoffice* thunderbird* ibus* fcitx* || true
apt autoremove -y
apt clean
apt install -y libqt5qml5 libqt5quick5 libqt5quickwidgets5 qml-module-qtquick2
apt install -y libgsettings-qt1
# === 8️⃣ 设置 GRUB 启动等待时间 ===
echo ">>> 设置 GRUB 启动等待时间为 2 秒..."
GRUB_FILE="/etc/default/grub"
if grep -q "^GRUB_TIMEOUT=" "$GRUB_FILE"; then
sed -i 's/^GRUB_TIMEOUT=.*/GRUB_TIMEOUT=2/' "$GRUB_FILE"
else
echo "GRUB_TIMEOUT=2" >> "$GRUB_FILE"
fi
if command -v update-grub &>/dev/null; then
update-grub
elif command -v grub2-mkconfig &>/dev/null; then
grub2-mkconfig -o /boot/grub2/grub.cfg
fi
echo "✅ GRUB 超时设置完成。"
mkdir /opt/mysoft
chmod 777 /opt/mysoft
su - $USER -c "chmod 700 ~/.ssh"
# === 9️⃣ 安装常用 Python 库 ===
echo ">>> 安装常用 Python 库..."
su - $USER -c "pip 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 ">>> 🔟 正在更新缓存、系统..."
apt update
apt upgrade
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