/boot is 100% full ubuntu

系统的/boot分区满了

apt-get -f install 和

sudo apt-get remove linux-image-VERSION

命令均不起作用,在这里https://askubuntu.com/questions/345588/what-is-the-safest-way-to-clean-up-boot-partition的第二篇解答NOTE: this is only if you can't use apt to clean up due to a 100% full /boot起作用了

转载于:https://www.cnblogs.com/imageSet/p/10325831.html

[02:34:38] ✅ 密码正确,开始部署... [02:34:38] 🔧 设置非交互模式并修复中断的 dpkg... [02:34:38] ⚙️ 正在运行 dpkg --configure -a --force-confdef --force-confold... Setting up cloud-init (24.4.1-0ubuntu0~20.04.3) ... Configuration file '/etc/cloud/cloud.cfg' ==> Modified (by you or by a script) since installation. ==> Package distributor has shipped an updated version. ==> Keeping old config file as default. Installing new version of config file /etc/cloud/cloud.cfg.d/05_logging.cfg ... Installing new version of config file /etc/cloud/templates/chrony.conf.alpine.tmpl ... Installing new version of config file /etc/cloud/templates/chrony.conf.debian.tmpl ... Installing new version of config file /etc/cloud/templates/chrony.conf.fedora.tmpl ... Installing new version of config file /etc/cloud/templates/chrony.conf.opensuse.tmpl ... Installing new version of config file /etc/cloud/templates/chrony.conf.photon.tmpl ... Installing new version of config file /etc/cloud/templates/chrony.conf.rhel.tmpl ... Installing new version of config file /etc/cloud/templates/chrony.conf.sles.tmpl ... Installing new version of config file /etc/cloud/templates/chrony.conf.ubuntu.tmpl ... Installing new version of config file /etc/cloud/templates/hosts.alpine.tmpl ... Installing new version of config file /etc/cloud/templates/ntp.conf.alpine.tmpl ... Installing new version of config file /etc/cloud/templates/ntp.conf.debian.tmpl ... Installing new version of config file /etc/cloud/templates/ntp.conf.fedora.tmpl ... Installing new version of config file /etc/cloud/templates/ntp.conf.opensuse.tmpl ... Installing new version of config file /etc/cloud/templates/ntp.conf.photon.tmpl ... Installing new version of config file /etc/cloud/templates/ntp.conf.rhel.tmpl ... Installing new version of config file /etc/cloud/templates/ntp.conf.sles.tmpl ... Installing new version of config file /etc/cloud/templates/ntp.conf.ubuntu.tmpl ... Installing new version of config file /etc/profile.d/Z99-cloud-locale-test.sh ... Installing new version of config file /etc/profile.d/Z99-cloudinit-warnings.sh ... Removing obsolete conffile /etc/NetworkManager/dispatcher.d/hook-network-manager ... Setting up libnss-systemd:amd64 (245.4-4ubuntu3.24) ... Setting up python3-distupgrade (1:20.04.41) ... Setting up ubuntu-release-upgrader-core (1:20.04.41) ... Setting up update-manager-core (1:20.04.10.23) ... Setting up libpam-systemd:amd64 (245.4-4ubuntu3.24) ... Setting up update-notifier-common (3.192.30.19) ... Setting up dbus-user-session (1.12.16-2ubuntu2.3) ... Setting up snapd (2.67.1+20.04) ... Installing new version of config file /etc/apparmor.d/usr.lib.snapd.snap-confine.real ... Installing new version of config file /etc/apt/apt.conf.d/20snapd.conf ... snapd.failure.service is a disabled or a static unit not running, not starting it. snapd.snap-repair.service is a disabled or a static unit not running, not starting it. Processing triggers for initramfs-tools (0.136ubuntu6.8) ... update-initramfs: Generating /boot/initrd.img-5.4.0-110-generic Processing triggers for libc-bin (2.31-0ubuntu9.18) ... Processing triggers for rsyslog (8.2001.0-1ubuntu1.3) ... Processing triggers for ufw (0.36-6ubuntu1.1) ... Processing triggers for man-db (2.9.1-1) ... Processing triggers for plymouth-theme-ubuntu-text (0.9.4git20200323-0ubuntu6.2) ... update-initramfs: deferring update (trigger activated) Processing triggers for dbus (1.12.16-2ubuntu2.3) ... Processing triggers for install-info (6.7.0.dfsg.2-5) ... Processing triggers for linux-image-5.4.0-216-generic (5.4.0-216.236) ... /etc/kernel/postinst.d/initramfs-tools: update-initramfs: Generating /boot/initrd.img-5.4.0-216-generic /etc/kernel/postinst.d/zz-update-grub: Sourcing file `/etc/default/grub' Sourcing file `/etc/default/grub.d/50-cloudimg-settings.cfg' Sourcing file `/etc/default/grub.d/init-select.cfg' Generating grub configuration file ... Found linux image: /boot/vmlinuz-5.4.0-216-generic Found initrd image: /boot/initrd.img-5.4.0-216-generic Found linux image: /boot/vmlinuz-5.4.0-110-generic Found initrd image: /boot/initrd.img-5.4.0-110-generic done Processing triggers for mime-support (3.64ubuntu1) ... Processing triggers for initramfs-tools (0.136ubuntu6.8) ... update-initramfs: Generating /boot/initrd.img-5.4.0-216-generic [02:35:36] ✅ 系统已进入全自动非交互模式 [02:35:36] 🚀 优化系统资源使用:启用最大线程与内存 [02:35:36] 🧠 检测到 CPU 核心数: 32 [02:35:36] 🔧 执行: 📦 安装 pigz(并行 gzip) (最长等待 120 秒) Reading package lists... Building dependency tree... Reading state information... The following NEW packages will be installed: pigz 0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded. Need to get 57.4 kB of archives. After this operation, 259 kB of additional disk space will be used. Get:1 http://mirrors.aliyun.com/ubuntu focal/universe amd64 pigz amd64 2.4-1 [57.4 kB] Fetched 57.4 kB in 0s (286 kB/s) Selecting previously unselected package pigz. (Reading database ... (Reading database ... 5% (Reading database ... 10% (Reading database ... 15% (Reading database ... 20% (Reading database ... 25% (Reading database ... 30% (Reading database ... 35% (Reading database ... 40% (Reading database ... 45% (Reading database ... 50% (Reading database ... 55% (Reading database ... 60% (Reading database ... 65% (Reading database ... 70% (Reading database ... 75% (Reading database ... 80% (Reading database ... 85% (Reading database ... 90% (Reading database ... 95% (Reading database ... 100% (Reading database ... 134865 files and directories currently installed.) Preparing to unpack .../archives/pigz_2.4-1_amd64.deb ... Unpacking pigz (2.4-1) ... Setting up pigz (2.4-1) ... Processing triggers for man-db (2.9.1-1) ... [02:37:36] ⏰ 超时失败: 📦 安装 pigz(并行 gzip) [02:37:36] ⚡ 已启用多线程加速: 7z + pigz [02:37:36] 🔍 正在检测系统兼容性... [02:37:36] ✅ 操作系统: Ubuntu 20.04 (focal) [02:37:36] 🟢 版本受支持 [02:37:36] ✅ CPU 架构: x86_64 [02:37:36] 🔧 正在清理 APT 锁文件和占用进程... [02:37:39] ✅ APT 锁已清除且中断状态已修复 [02:37:39] 🌐 正在配置阿里云 APT 源... [02:37:39] ✅ 已切换至阿里云 APT 源 [02:37:39] 🔧 执行: 🔄 更新 APT 包列表 (最长等待 300 秒) WARNING: apt does not have a stable CLI interface. Use with caution in scripts. Hit:1 http://mirrors.aliyun.com/ubuntu focal InRelease Hit:2 http://mirrors.aliyun.com/ubuntu focal-updates InRelease Hit:3 http://mirrors.aliyun.com/ubuntu focal-security InRelease Get:4 http://mirrors.aliyun.com/ubuntu focal-backports InRelease [128 kB] Get:5 http://mirrors.aliyun.com/ubuntu focal-backports/universe Sources [10.5 kB] Hit:6 http://ppa.launchpad.net/git-core/ppa/ubuntu focal InRelease Get:7 http://mirrors.aliyun.com/ubuntu focal-backports/main Sources [9604 B] Get:8 http://mirrors.aliyun.com/ubuntu focal-backports/main amd64 Packages [45.7 kB] Get:9 http://mirrors.aliyun.com/ubuntu focal-backports/main i386 Packages [36.1 kB] Get:10 http://mirrors.aliyun.com/ubuntu focal-backports/main Translation-en [16.3 kB] Get:11 http://mirrors.aliyun.com/ubuntu focal-backports/main amd64 c-n-f Metadata [1420 B] Get:12 http://mirrors.aliyun.com/ubuntu focal-backports/restricted amd64 c-n-f Metadata [116 B] Get:13 http://mirrors.aliyun.com/ubuntu focal-backports/universe i386 Packages [13.8 kB] Get:14 http://mirrors.aliyun.com/ubuntu focal-backports/universe amd64 Packages [25.0 kB] Get:15 http://mirrors.aliyun.com/ubuntu focal-backports/universe Translation-en [16.3 kB] Get:16 http://mirrors.aliyun.com/ubuntu focal-backports/universe amd64 c-n-f Metadata [880 B] Get:17 http://mirrors.aliyun.com/ubuntu focal-backports/multiverse amd64 c-n-f Metadata [116 B] Fetched 304 kB in 2s (190 kB/s) Reading package lists... Building dependency tree... Reading state information... 2 packages can be upgraded. Run 'apt list --upgradable' to see them. [02:37:50] ✅ 成功: 🔄 更新 APT 包列表 [02:37:50] 🔧 执行: 📦 安装 p7zip-full(用于高速解压) (最长等待 300 秒) Reading package lists... Building dependency tree... Reading state information... The following additional packages will be installed: p7zip Suggested packages: p7zip-rar The following NEW packages will be installed: p7zip p7zip-full 0 upgraded, 2 newly installed, 0 to remove and 2 not upgraded. Need to get 1545 kB of archives. After this operation, 5896 kB of additional disk space will be used. Get:1 http://mirrors.aliyun.com/ubuntu focal/universe amd64 p7zip amd64 16.02+dfsg-7build1 [358 kB] Get:2 http://mirrors.aliyun.com/ubuntu focal/universe amd64 p7zip-full amd64 16.02+dfsg-7build1 [1187 kB] Fetched 1545 kB in 1s (3010 kB/s) Selecting previously unselected package p7zip. (Reading database ... (Reading database ... 5% (Reading database ... 10% (Reading database ... 15% (Reading database ... 20% (Reading database ... 25% (Reading database ... 30% (Reading database ... 35% (Reading database ... 40% (Reading database ... 45% (Reading database ... 50% (Reading database ... 55% (Reading database ... 60% (Reading database ... 65% (Reading database ... 70% (Reading database ... 75% (Reading database ... 80% (Reading database ... 85% (Reading database ... 90% (Reading database ... 95% (Reading database ... 100% (Reading database ... 134874 files and directories currently installed.) Preparing to unpack .../p7zip_16.02+dfsg-7build1_amd64.deb ... Unpacking p7zip (16.02+dfsg-7build1) ... Selecting previously unselected package p7zip-full. Preparing to unpack .../p7zip-full_16.02+dfsg-7build1_amd64.deb ... Unpacking p7zip-full (16.02+dfsg-7build1) ... Setting up p7zip (16.02+dfsg-7build1) ... Setting up p7zip-full (16.02+dfsg-7build1) ... Processing triggers for man-db (2.9.1-1) ... [02:42:50] ⏰ 超时失败: 📦 安装 p7zip-full(用于高速解压) [02:42:50] 📦 开始解压 /2-必备库.zip (117M) 到 / ... [02:42:50] 🔧 执行: 📦 解压 '2-必备库.zip' 到根目录并删除 (最长等待 900 秒) 7-Zip [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21 p7zip Version 16.02 (locale=C,Utf16=off,HugeFiles=on,64 bits,32 CPUs Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz (50657),ASM,AES-NI) Scanning the drive for archives: 1 file, 122590172 bytes (117 MiB) Extracting archive: /2-必备库.zip -- Path = /2-必备库.zip Type = zip Physical Size = 122590172 Everything is Ok Folders: 8 Files: 9 Size: 123340880 Compressed: 122590172 [02:42:50] ✅ 成功: 📦 解压 '2-必备库.zip' 到根目录并删除 [02:42:50] 📦 开始解压 /1-接4.0genshin.zip (3.2G) 到 /www ... [02:42:50] 🔧 执行: 📦 解压 '1-接4.0genshin.zip' 到 /www 并删除 (最长等待 900 秒) 7-Zip [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21 p7zip Version 16.02 (locale=C,Utf16=off,HugeFiles=on,64 bits,32 CPUs Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz (50657),ASM,AES-NI) Scanning the drive for archives: 1 file, 3384784610 bytes (3228 MiB) Extracting archive: /1-接4.0genshin.zip
最新发布
12-03
你提供的日志显示:**脚本在执行 `apt-get install` 时被卡住,最终超时失败(⏰ 超时失败)**。 --- ## 🔍 问题诊断 ### ❌ 失败点: ```log [02:35:36] 🔧 执行: 📦 安装 pigz(并行 gzip) (最长等待 120 秒) ... Setting up pigz (2.4-1) ... Processing triggers for man-db (2.9.1-1) ... [02:37:36] ⏰ 超时失败: 📦 安装 pigz(并行 gzip) ``` > ✅ 实际上 `pigz` 已经安装成功了! > ❌ 但因为 **`run_step_with_timeout` 使用了 `timeout` 命令包裹整个命令链**,而 `apt` 或其触发的 `trigger`(如 `man-db`, `initramfs`)耗时超过 120 秒 → 导致 **误判为“失败”** --- ## 🚨 根本原因分析 | 原因 | 说明 | |------|------| | ⚠️ `timeout` 等待时间不足 | `apt install` 在低速磁盘或高负载机器上可能需要 >2 分钟 | | ⚠️ 触发大量 post-install trigger | 如 `update-initramfs`, `update-grub`, `man-db` 等会显著延长总时间 | | ⚠️ 即使操作成功也会被 kill | `timeout 120` 不区分“仍在运行”和“已卡死”,到点就杀进程 | > 💡 这不是 bug,是 **防护机制过于激进导致的误杀** --- # ✅ 正确解决方案 我们不能简单地“加长 timeout”,而是要: 1. ✅ 提升容错性:允许关键 APT 操作更长时间 2. ✅ 避免误杀:只监控命令本身是否无响应,而非总时长 3. ✅ 改进逻辑:将“安装 + 设置”拆分为可独立重试步骤 4. ✅ 增强鲁棒性:自动检测并跳过已安装软件包 --- ## ✅ 解决方案一:【推荐】动态调整超时时间 + 自动跳过已安装 ### 修改 `run_step_with_timeout` 函数 ```bash run_step_with_timeout() { local desc="$1" local cmd="$2" local repair_cmd="${3:-$cmd}" local timeout_sec="${4:-$TIMEOUT_SEC}" # 如果是 APT 安装类任务,自动延长超时 if [[ "$cmd" == *"apt-get install"* || "$cmd" == *"dpkg --configure"* ]]; then timeout_sec=$((timeout_sec > 600 ? timeout_sec : 600)) fi CURRENT_STEP=$((CURRENT_STEP + 1)) local progress_prefix="[${CURRENT_STEP}/${TOTAL_STEPS}]" local full_desc="${progress_prefix} $desc" log INFO "执行: $desc (最长等待 $timeout_sec 秒)" start_progress "$full_desc" local tmp_log=$(mktemp) # ✅ 关键改进:使用非终止信号先提示,最后才强制 kill if bash -c "$cmd" >"$tmp_log" 2>&1 & pid=$! ( sleep $((timeout_sec - 10)) if kill -0 $pid 2>/dev/null; then log WARN "⚠️ 任务接近超时,发送 SIGTERM..." kill -15 $pid 2>/dev/null || true sleep 10 if kill -0 $pid 2>/dev/null; then log ERROR "⚠️ 强制终止残留进程 PID=$pid" kill -9 $pid 2>/dev/null fi fi ) & wait $pid && ret=0 || ret=$? wait # 等待后台告警协程结束 then stop_progress SUCCESS_LOG+=("$desc") log SUCCESS "$progress_prefix $desc" rm -f "$tmp_log" return 0 else stop_progress case $ret in 130|143) log ERROR "⛔ 操作被中断: $progress_prefix $desc" ;; 124|137) log ERROR "⏰ 超时失败: $progress_prefix $desc" ;; *) log ERROR "❌ 失败 (退出码 $ret): $progress_prefix $desc" ;; esac tail -n 20 "$tmp_log" >> "$LOG_FILE" rm -f "$tmp_log" FAILED_LOG+=("$desc") FAILED_CMDS+=("$repair_cmd") return 1 fi } ``` > ✅ 特性: > - 不用 `timeout` 命令,避免粗暴中断 > - 先发 `SIGTERM` 给程序优雅退出机会 > - 最后 `SIGKILL` 清理残余 > - 更智能、更安全 --- ## ✅ 解决方案二:提前检查是否已安装(防重复) 修改所有 `apt install` 调用前加判断: ```bash safe_apt_install() { local pkg_name="$1" local disp_name="${2:-$pkg_name}" if dpkg -l | grep -q "^ii $pkg_name "; then log SUCCESS "📦 已跳过安装 $disp_name(已存在)" return 0 fi run_step_with_timeout \ "📦 安装 $disp_name" \ "sudo apt-get install -y -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' $pkg_name" \ "ensure_apt_unlocked && sudo apt-get update && sudo apt-get install -y $pkg_name" \ 600 } ``` ### 使用方式替换原命令: ```bash # 替换原来的 pigz 安装 safe_apt_install "pigz" "pigz(并行gzip)" # 替换 p7zip 安装 safe_apt_install "p7zip-full" "p7zip-full(高速解压)" ``` --- ## ✅ 解决方案三:禁用耗时 trigger(可选但高效) 某些系统中可以临时关闭 `man-db` 和 `initramfs` 的自动更新以提速: ```bash export MANDB_DISABLE_POSTINST=1 export INITRD_SKIP=Yes ``` 或者在安装时加上: ```bash safe_apt_install() { local pkg_name="$1" if ! dpkg -l | grep -q "^ii $pkg_name "; then run_step_with_timeout \ "📦 安装 $pkg_name" \ "sudo NO_APT_MANDB_UPDATE=1 INITRD_SKIP=Yes DEBIAN_FRONTEND=noninteractive apt-get install -y -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' $pkg_name" \ "ensure_apt_unlocked && sudo apt-get update && sudo apt-get install -y $pkg_name" \ 600 else log SUCCESS "📦 已跳过: $pkg_name" fi } ``` > ⚠️ 注意:仅用于部署环境,生产环境慎用 --- ## ✅ 推荐最终策略(综合版) | 步骤 | 操作 | |------|------| | 1 | 使用增强版 `run_step_with_timeout`(软终止)✔️ | | 2 | 加入 `safe_apt_install` 自动跳过 ✔️ | | 3 | 将 `TOTAL_STEPS` 中已存在的安装项排除 ✔️ | | 4 | 日志中明确标注 “(跳过)” 或 “(已存在)” ✔️ | --- ## ✅ 效果对比 | 之前行为 | 改进后行为 | |--------|-----------| | `apt install pigz` 执行 130s → 被 kill | 允许最多 600s,成功完成 | | 显示“失败”,实际已安装 | 自动检测是否存在,不再重复执行 | | 用户困惑 | 明确提示“✅ 已跳过:pigz(已存在)” | ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值