seaworld008/centos7-lighthouse / skills/centos7-almalinux-upgrade
centos7-almalinux-upgrade
Flagged把老旧 CentOS 7 / CentOS 8(及 RHEL7/8 系)服务器原地升级到最新 AlmaLinux 10(经 ELevate/Leapp 7→8→9→10,CentOS 8 先用 almalinux-deploy 转换),并保证业务、容器、nginx、kubectl 等升级后照常工作。凡是用户提到 CentOS 7 / CentOS 停服 / EOL / 老系统升级 / 迁移到 AlmaLinux / Rocky / CentOS 继任者 / ELevate / leapp / 系统漏洞要升级系统、批量升级阿里云/华为云/AWS 上的 CentOS 服务器,都要使用本技能——即使用户没说"升级"而只说"系统太老了""换个新系统但业务不能停"。In-place upgrade CentOS 7 to AlmaLinux 10 safely, single server or whole fleet.
references/recovery.md
View on GitHub# 救援手册
## A. 重启后 SSH 一直不回来
1. 先确认是不是**访问路径**断了而不是机器挂了:本机 VPN 客户端(如 `netbird status -d`)看路由节点状态;云控制台看实例"运行中"、CPU 是否在动(升级进行中 CPU 会高)。
2. leapp 升级阶段(initramfs 里装包)正常需要 15~40 分钟,期间 SSH 不通是正常的。打开控制台 VNC/串口看进度。
3. 看到登录提示符 = 已进入新系统,只是网络/sshd/VPN 没起来:
- 需要密码登录时请用户自己在控制台登录。
- VPN 容器没起来:`docker start <vpn容器>`;sshd 没起来:`systemctl status sshd`、`sshd -t`。
## B. ★ 卡在 initramfs 紧急模式("Entering emergency mode",`upgrade.service failed`)
这个 shell 是 root,无需密码。工具很少(没有 head/tail/cut/clear),用 `grep -m N -o` 代替。
```sh
systemctl --failed --no-pager
journalctl -u upgrade.service -n 38 --no-pager -o cat # 看 leapp 汇总
mount -o ro /dev/vda1 /sysroot # 系统盘设备名按实际(vda1/nvme0n1p1/sda1)
cat /sysroot/etc/redhat-release # 已经是新版本 → 事务大部分已执行
grep -cE 'install failed|erase failed|scriptlet failed' /sysroot/var/log/leapp/leapp-upgrade.log
grep -E 'install failed|erase failed|scriptlet failed|Verifying.*/' /sysroot/var/log/leapp/leapp-upgrade.log | grep -m 12 -o 'transaction: .\{0,140\}'
grep -E 'dnf_upgrade_transaction: (Error|error|warning)' /sysroot/var/log/leapp/leapp-upgrade.log | grep -m 25 -o 'transaction: .\{0,160\}'
ls /sysroot/boot | grep -E 'vmlinuz|initramfs'; grep saved_entry /sysroot/boot/grub2/grubenv
```
判断:
- **只有少数包失败、Verifying 到 N/N、默认启动项是新内核且 initramfs 存在** → 可以直接启动进新系统,再手工补完 leapp 没跑的收尾(下面 C)。
- **大量失败 / 新内核或 initramfs 缺失 / redhat-release 还是旧版** → 不要硬启动,回滚快照是最稳的;或在救援环境里排查。
启动前顺手修好会导致失联的东西(`mount -o remount,rw /sysroot`):
- 容器被手动停过的:`sed -i 's/"HasBeenManuallyStopped":true/"HasBeenManuallyStopped":false/' /sysroot/var/lib/docker/containers/*/config.v2.json`
- 检查 PAM 是否还引用已删模块:`grep -l pkcs11 /sysroot/etc/pam.d/*`(只在 smartcard-auth 里无影响)
然后:`sync; umount /sysroot; systemctl reboot`
### B2. 紧急模式出现得很早(几秒内,leapp 还没开始)、VNC 里敲命令没反应
真实踩坑(阿里云 K8s master,8→9,2026-11):内核启动约 5 秒就 `Entering emergency mode`,VNC 里打字没有任何回显。
- **原因 1:shell 在串口上**。阿里云内核参数是 `console=tty0 console=ttyS0,115200n8`,最后一个 console 是 ttyS0,emergency shell 开在串口;VNC 只能看到 tty0 的输出,**输入进不去**。
- **看真正的报错**:ECS 控制台 → 实例 → 全部操作 → 运维和诊断 → **获取实例系统日志**(就是串口输出),翻到 `Entering emergency mode` 之前的 `Dependency failed` / `See 'systemctl status xxx.mount'`。
- **原因 2(这次的根因)**:fstab 里有 bind 到 `/sys` 的挂载(`/home/admin/eth0-speed.mock /sys/class/net/eth0/speed none bind,nofail`,阿里云 OceanBase 镜像脚本 `set_ecs_special.sh` 写入)。**leapp 在 `leapp upgrade` 时把 fstab 固化成升级 initramfs 里的 mount unit**,这一项在升级环境里挂不上,`nofail` 也挡不住。**事后改 fstab 无效**,必须回到旧系统改完再重新 `hop.sh up`。现在 `hop.sh up` 会自动注释这类条目(`#osup-bind#`),EL10 的 `post` 恢复;`survey.sh` 报 BLOCKER。
**回到旧内核的方法**(GRUB 超时只有 1 秒,ECS 重启会断开 VNC,手动按键基本赶不上):在 VNC 页面里执行 JS,直接调 noVNC 对象,用页面里的定时器按键:
```js
// 浏览器开发者工具(或 agent 的 JS 工具)里,在 ecs.console.aliyun.com/vnc/... 页面执行
rfb.sendCtrlAltDel(); // 来宾机内重启:VNC 不断开(emergency 里通常有效;不行就用控制台"强制重启")
window.__k = setInterval(() => { try { rfb.sendKey(0xff52); } catch (e) {} }, 100); // 每 100ms 按一次 ↑,GRUB 一出现就停住倒计时
// 控制台强制重启会断开 VNC:再加一个定时器,看到"服务器断开连接/不支持此操作"就点"连接远程连接"自动重连
// 停在 GRUB 菜单、选中旧内核后:
clearInterval(window.__k); rfb.sendKey(0xff0d); // 回车
```
进入旧系统后:注释掉问题 fstab 条目 → `bash hop.sh pre && bash hop.sh up && bash hop.sh reboot`(重新生成升级 initramfs)。
## C. "半升级"状态的收尾(leapp 后续阶段没跑)
进入新系统后:
1. 失败的那个包:先挪走冲突文件(通常是 pip 装的目录),再 `dnf install <包>`;用不上的(如 py2 包)直接忽略。
2. `hop.sh post <MIRROR>` 会因为失败标记 `/root/tmp_leapp_py3/.leapp_upgrade_failed` 停下:确认第 1 步处理完后删除该标记再执行。它会删旧内核/leapp/残留源、修 repo、dnf upgrade。
3. leapp 收尾里需要手工补的:`dnf -y upgrade --nobest`;cloud-init(禁用或重装);SELinux 若是 enforcing 需要 `touch /.autorelabel` 再重启(disabled 则无需)。
4. `verify.sh <BACKUP_DIR>` 对比基线。
5. 进入下一跳前一定重新 `hop.sh prep`(会再跑 pipfix)。
## D. 换 openssh 后连不上
- swap-openssh.sh 失败会自动用旧 sshd 兜底;检查 `/root/os-upgrade-kit/ossh-swap/swap.log`。
- 控制台登录后:`/usr/sbin/sshd -t` 看配置错误;`systemctl status sshd`;必要时 `/root/os-upgrade-kit/ossh-swap/old-bin/sshd -f /etc/ssh/sshd_config`(9.x 旧版本需加 `-o SshdSessionPath=/root/os-upgrade-kit/ossh-swap/old-bin/sshd-session`)。
## F. ★ 卡在升级 initramfs、抢不到 GRUB 菜单:换盘改默认启动项
适用:重启进 leapp 升级环境后挂死(如华为云 c9 上 EL10 内核早期加载驱动挂死),**还没开始装包**,系统盘内容没变;但 leapp 把升级项设成了持久默认(grubenv 的 `saved_entry`),强制重启还会进去,而 VNC 在强制重启后要几秒才重连,抢不到 5 秒的 GRUB 菜单(实测多次失败;Ctrl+Alt+Del 也会因为卡死的进程关不了机)。
1. 强制关机(华为云开了"操作保护"时需要用户输入短信验证码,请用户操作)。
2. 云硬盘控制台:卸载故障机的系统盘。
3. 同一可用区找一台救援机:已有机器(只热挂一块盘,不影响它)或新建一台按需计费的小规格机器。新建时把 `scripts/rescue-grubenv.sh` 作为"实例自定义数据(user data)",登录方式选"创建后设置"——不需要任何密码。
4. 把故障机的系统盘以**数据盘**挂到救援机。有 user data 的救援机会自动找到带 `*-upgrade.*.conf` 的分区,把 `saved_entry` 改成上一个大版本的内核,备份原 grubenv,卸载,并在 VNC 控制台打印 `OSUP: DONE ... saved_entry=...` 和 `SAFE TO DETACH`;已有机器上手工执行 `bash rescue-grubenv.sh`。xfs 克隆盘 UUID 相同时脚本会用 `nouuid` 挂载。
5. 从救援机卸载,**以系统盘挂回**故障机(华为云 EVS 列表页挂 SCSI 系统盘可能一直报"未挂载系统盘",换到 ECS 详情页 → 磁盘 → 挂载磁盘,磁盘属性选"系统盘"),开机。
6. 回到旧系统后:恢复业务(NFS 主机先 `k8s.sh nfs-on`);`grubby --remove-kernel=/boot/vmlinuz-upgrade.x86_64` 删掉升级启动项,防止以后误入;删除救援机。
7. 清理这次没做完的升级留下的残留(真实踩坑:退回 9.8 的机器一直带着 ELevate 源和 leapp 包):确认 `grubby --info=ALL | grep -c upgrade` 为 0 后,`rm -f /boot/vmlinuz-upgrade.x86_64 /boot/initramfs-upgrade.x86_64.img`;`rpm -qa | grep -iE 'leapp|elevate'` 列出的包 `rpm -e`;`rm -rf /var/lib/leapp /etc/yum.repos.d/ELevate.repo`。最后跑 `post-audit.sh`,leapp 残留一项应消失。
## E. 回滚
快照回滚是唯一完整的回滚。回滚前告诉用户:快照之后产生的业务数据(数据库写入、上传文件)会丢失,数据盘是否一起回滚由用户决定。
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deployment | Stars: 323k | Updated | Claude CodeCodex | Verified | Install |
| xlsxanthropics/skillsUse this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like "the xlsx in my downloads") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| shipping-and-launchaddyosmani/agent-skillsPrepares production launches. Use when preparing to deploy to production, or when asking what needs to be in place before shipping. Use when you need a pre-launch checklist, when setting up monitoring, when planning a staged rollout, or when you need a rollback strategy. | Stars: 119k | Updated | Claude CodeCodex | Verified | Install |
| childhoodthedotmack/claude-memBabysit a shipped release after merge, publication, or deployment. Verify published packages, production behavior, installed plugins, and late CI or user reports until the observation window is clean; use babysit for PR readiness before release. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |