迁移到 AlmaLinux
本文将指导你使用 AlmaLinux 官方迁移工具 almalinux-deploy,从 CentOS 7/8、CentOS Stream、RHEL 或其他 EL 兼容发行版迁移到 AlmaLinux。
在开始迁移之前,请确认以下事项:
- 操作系统版本:CentOS 7、CentOS 8、CentOS Stream 8/9、RHEL 7/8/9、Oracle Linux、Rocky Linux 等 EL 兼容系统
- 磁盘空间:
/var分区至少有 5 GB 可用空间(用于下载和缓存软件包) - 网络连接:服务器能够访问外网以下载 AlmaLinux 软件包
- root 权限:迁移过程需要 root 或 sudo 权限
- 完整备份:务必在迁移前完成系统快照或完整备份
重要提示: 迁移操作会替换系统核心软件包,存在一定风险。请务必在测试环境验证后再在生产环境执行。
记录当前系统状态
Section titled “记录当前系统状态”$ cat /etc/os-release$ rpm -qa --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' | sort > ~/packages-before-migration.txt$ systemctl list-units --type=service --state=running > ~/services-before-migration.txt$ cp -a /etc/yum.repos.d/ ~/yum.repos.d.bak/$ nmcli connection show > ~/network-before-migration.txt$ ip addr show > ~/ip-addr-before-migration.txt下载 almalinux-deploy 工具
Section titled “下载 almalinux-deploy 工具”almalinux-deploy 是 AlmaLinux 官方提供的迁移脚本,托管在 GitHub 上。
$ sudo dnf install -y curl$ curl -O https://raw.githubusercontent.com/AlmaLinux/almalinux-deploy/master/almalinux-deploy.sh$ ls -la almalinux-deploy.sh提示: 如果你的服务器无法直接访问 GitHub,可以在其他机器下载后通过 scp 传输到目标服务器。
基本迁移(CentOS 8 / CentOS Stream)
Section titled “基本迁移(CentOS 8 / CentOS Stream)”$ sudo bash almalinux-deploy.sh脚本会自动完成以下操作:
- 检测当前操作系统版本
- 下载 AlmaLinux 的 GPG 密钥和软件仓库配置
- 移除 CentOS 特有的软件包(如
centos-release、centos-logos等) - 安装 AlmaLinux 对应的软件包
- 使用
dnf distro-sync同步所有软件包到 AlmaLinux 版本
CentOS 7 的迁移
Section titled “CentOS 7 的迁移”CentOS 7 迁移需要先升级到 EL8,因为 almalinux-deploy 主要支持 EL8+ 的直接迁移。AlmaLinux 提供了 ELevate 项目来完成跨大版本升级。
$ sudo yum install -y http://repo.almalinux.org/elevate/elevate-release-latest-el7.noarch.rpm$ sudo yum install -y leapp-upgrade leapp-data-almalinux$ sudo leapp preupgrade注意:
leapp preupgrade会生成一份报告,列出所有需要手动处理的问题。请仔细阅读/var/log/leapp/leapp-report.txt并逐一解决。
$ sudo cat /var/log/leapp/leapp-report.txt$ sudo leapp upgrade升级完成后系统会自动重启,进入 AlmaLinux 8。
指定目标版本
Section titled “指定目标版本”如果你需要迁移到特定的 AlmaLinux 版本:
$ sudo bash almalinux-deploy.sh -t 9处理第三方仓库
Section titled “处理第三方仓库”迁移过程中,第三方仓库可能会导致软件包冲突。以下是常见的处理方法。
EPEL 仓库
Section titled “EPEL 仓库”EPEL 仓库通常可以自动适配,但建议迁移前临时禁用:
$ sudo dnf config-manager --set-disabled epel epel-modular 2>/dev/null$ sudo dnf install -y epel-release$ sudo dnf config-manager --set-enabled epelRemi / IUS / RPMFusion 等仓库
Section titled “Remi / IUS / RPMFusion 等仓库”$ dnf repolist --enabled | grep -v -E '^(baseos|appstream|extras|powertools|crb)'$ sudo dnf config-manager --set-disabled remi* ius* rpmfusion*迁移完成后,需要重新安装适配 AlmaLinux 的第三方仓库版本:
$ sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-8.rpm$ sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-9.rpm处理软件包冲突
Section titled “处理软件包冲突”如果迁移过程中出现包冲突:
$ rpm -qa --qf '%{NAME} %{VENDOR}\n' | grep -v "AlmaLinux" | sort$ sudo dnf distro-sync -y确认操作系统已切换
Section titled “确认操作系统已切换”$ cat /etc/os-release输出应显示 AlmaLinux 相关信息:
NAME="AlmaLinux"VERSION="8.9 (Midnight Oncilla)"ID="almalinux"$ rpm -qa | grep almalinux-release验证软件包完整性
Section titled “验证软件包完整性”$ rpm -qa | grep -i centos如果有残留包,可以手动移除或替换:
$ sudo dnf remove centos-logos centos-indexhtml 2>/dev/null$ sudo dnf distro-sync -y重建 GRUB 引导
Section titled “重建 GRUB 引导”$ sudo grub2-mkconfig -o /boot/grub2/grub.cfg对于 EFI 系统:
$ sudo grub2-mkconfig -o /boot/efi/EFI/almalinux/grub.cfg$ sudo reboot$ uname -r$ systemctl list-units --type=service --state=failed迁移脚本报错 “not supported”
Section titled “迁移脚本报错 “not supported””确认你的源系统版本在支持列表中。CentOS 6 及更早版本不被支持。
$ cat /etc/redhat-releaseGPG 密钥导入失败
Section titled “GPG 密钥导入失败”可能是网络问题导致无法下载密钥。
$ sudo rpm --import https://repo.almalinux.org/almalinux/RPM-GPG-KEY-AlmaLinux-8dnf distro-sync 失败
Section titled “dnf distro-sync 失败”通常是第三方仓库包冲突导致的。
$ sudo dnf distro-sync -y --exclude=<冲突包名>$ sudo dnf clean all$ sudo dnf distro-sync -y迁移后无法启动
Section titled “迁移后无法启动”如果重启后进入 GRUB rescue 或无法引导:
- 使用安装介质或救援模式启动
- 挂载根分区
- chroot 到系统中
- 重新安装内核和 GRUB
$ sudo mount /dev/sda2 /mnt$ sudo mount /dev/sda1 /mnt/boot$ sudo chroot /mnt$ dnf reinstall kernel-core grub2-efi-x64 shim-x64$ grub2-mkconfig -o /boot/efi/EFI/almalinux/grub.cfg$ exit$ sudo rebootSecure Boot 相关问题
Section titled “Secure Boot 相关问题”AlmaLinux 支持 Secure Boot,但迁移后可能需要重新注册:
$ mokutil --sb-state