这是本节的多页打印视图。 点击此处打印.

返回本页常规视图.

Ubuntu 配置

    制作启动盘

    balenaEtcher,支持 Windows、macOS 和 Linux 的跨平台启动盘制作工具,界面简洁,使用方便,支持多种镜像格式,如 ISO、IMG 等。

    brew install balenaetcher

    下载好镜像后,使用 balenaEtcher 将其写入到 U 盘中,制作完成后就可以使用这个 U 盘来安装 Ubuntu 了。

    安装完成后,配置清华源:

    安装必要的软件包:

    sudo apt update
    sudo apt install -y build-essential curl git vim tmux fd-find ripgrep

    修改 =hostname=,设置一个好记的名字:

    sudo hostnamectl set-hostname devbox

    bashrc 配置

    wget -O ~/.bash_aliases https://api.liujiacai.net/bashrc

    配置 bash tab 补全时大小写不敏感

    # 永久生效
    echo "set completion-ignore-case on" >> ~/.inputrc
    # 不退出当前 shell 立即生效
    bind -f ~/.inputrc
    
    # 临时生效
    bind "set completion-ignore-case on"

    安装 ssh

    sudo apt install -y openssh-server

    之后拷贝自己的公钥到服务器上,保证免密登录:

    ssh-copy-id -i ~/.ssh/id_ed25519.pub dev
    ssh-copy-id -i ~/.ssh/id_ecdsa.pub dev

    关闭 GUI 登录

    # 永久关闭 GUI
    sudo systemctl set-default multi-user.target
    # 恢复开机启动 GUI
    sudo systemctl set-default graphical.target

    要让 Ubuntu 在不连接显示器时保持开机且不自动休眠,关键是配置电源管理以忽略显示器状态。

    sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target

    禁用 WiFi/网卡的电源管理 (最常见原因)

    如果你的网卡开启了省电模式,空闲时会自动切断连接。 排查命令:

    iwconfig  # 如果是 WiFi,查看 Power Management 是否为 on

    解决方法(禁用网卡省电):

    sudo vim /etc/NetworkManager/conf.d/default-wifi-powersave-on.conf

    wifi.powersave = 3 改为 wifi.powersave = 2 (2 表示禁用)。如果是以太网(网线),执行:

    # 网卡名通过 ip addr 查看
    sudo ethtool -s [网卡名] wol d  # 禁用唤醒省电模式

    显卡驱动导致系统卡死

    根据 sudo journalctl -b -1 -n 100 命令查看上次死机前的日志,发现有如下信息:

    Feb 17 18:00:12 devbox kernel: audit: type=1400 audit(1771322412.494:160): apparmor="DENIED" operation="open" class="file" profile="snap.firmware-updater.firmware-notifier" name="/p>
    Feb 17 18:00:58 devbox kernel: workqueue: i915_hpd_poll_init_work [i915] hogged CPU for >10000us 1027 times, consider switching to WQ_UNBOUND

    可以看出,最后一行日志显示 i915 驱动占用 CPU 过高,导致系统卡死。解决方法是禁用 i915 驱动:

    # 1. 创建黑名单文件
    sudo bash -c 'cat > /etc/modprobe.d/blacklist-i915.conf << EOF
    blacklist i915
    blacklist intel_agp
    EOF'
    
    # 2. 更新 initramfs
    sudo update-initramfs -u -k all
    
    # 3. 重启
    sudo reboot
    
    # 4. i915 驱动(如果需要恢复显卡功能)
    sudo rm /etc/modprobe.d/blacklist-i915.conf
    sudo update-initramfs -u -k all

    常用命令

    # 安装 uv 包管理器
    # https://docs.astral.sh/uv/getting-started/installation/
    curl -LsSf https://astral.sh/uv/install.sh | sh
    
    # https://supervisord.org/installing.html
    uv tool install supervisor