最近,CentOS 7即將在6/30正式EOL了 😲 剛好碰到朋友求幫忙將CentOS 7升級,但他自己用VMware、VirtualBox,分別嘗試了一下都卡在升級到CentOS 8的過程中,我自己也出錯好幾次,刪軟體套件刪到出怪手,開機直接進入『error: symbol ‘grub_real_boot_time’ not found. Entering rescue mode…』的錯誤 😱 但是好家在我還是嘗試出來了無痛的解決辦法,在三台不同廠商的VPS主機都可以成功從CentOS 7升級到Rocky Linux 8,RHEL9要改網路端名稱會很麻煩先不考慮,反正用Rocky Linux或是AlmaLinux都可以撐到2029年了,青菜蘿蔔自己選唄~ 😎
### CentOS 7升級到CentOS 8
# 步驟1、安裝常用軟體 🤖
1 2 3 4 5 6 7 8 9 10 11 12 |
# 使用2022年1月起的保管儲存庫 sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-* sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-* sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-Linux-* sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.epel.cloud|g' /etc/yum.repos.d/CentOS-Linux-* # grep -R "baseurl" /etc/yum.repos.d/CentOS-* # grep -R "mirrorlist" /etc/yum.repos.d/CentOS-* # cat /etc/yum.repos.d/CentOS-Base.repo | grep baseurl # cat /etc/yum.repos.d/CentOS-Base.repo | grep mirrorlist yum install -y epel-release sudo sudo yum upgrade -y epel-release sudo yum sudo yum install -y screen rpmconf yum-utils htop ncdu perl tar unzip gzip bzip2 ftp mtr traceroute mutt crontabs mlocate wget curl net-tools bind-utils lsof |
# 步驟2、更新系統到最新 🤖
1 2 3 4 |
sudo rm -rf /var/cache/yum/* sudo yum clean all sudo yum makecache sudo yum update -y |
# 步驟3、重新啟動 🤖
sudo systemctl reboot
# 步驟4、重新啟動後再次檢查安裝的OS版本,此時是CentOS 7.9.2009 (9.2009.2.el7.centos) 🤖
1 2 3 |
clear cat /etc/*-release yum info centos-release |
# 步驟5、建立名稱為CentOSUpgrade的視窗,斷線後重新連接時可以用-r的參數代替-S來恢復操作 🤖
screen -S CentOSUpgrade
# 步驟6、重新識別和解決設定檔衝突(無腦按ENTER就好) 🤖
sudo rpmconf -a
# 步驟7、雜七雜八 🤖
↓↓↓↓↓複製下方全部指令直接貼上↓↓↓↓↓
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# 清除已不再被依賴的套件 package-cleanup --leaves package-cleanup --orphans #安裝dnf套件管理器 sudo yum install -y dnf dnf-plugins-core # 移除yum套件管理器 sudo dnf remove -y yum yum-metadata-parser sudo rm -rf /var/cache/yum/* # 使用dnf套件管理器執行系統更新 sudo dnf update -y --best --allowerasing # 安裝CcentOS 8的repo sudo dnf install -y https://vault.centos.org/centos/8/BaseOS/x86_64/os/Packages/{centos-linux-repos-8-3.el8.noarch.rpm,centos-linux-release-8.5-1.2111.el8.noarch.rpm,centos-gpg-keys-8-3.el8.noarch.rpm} # 安裝epel-release 8 sudo dnf upgrade -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm # ls -lh /etc/yum.repos.d clear # 驗證儲存庫 dnf repolist |
# ↑↑↑↑↑複製上方全部指令直接貼上↑↑↑↑↑
# 步驟8、修改Python編碼預設為UTF8 🤖
1 2 3 4 5 6 7 8 9 |
cat <<"EOF" > /usr/lib/python2.7/site-packages/sitecustomize.py # encoding=utf8 import sys reload(sys) sys.setdefaultencoding('utf8') EOF clear cat /usr/lib/python2.7/site-packages/sitecustomize.py |
# 步驟9、刪除CentOS 7舊內核 🤖
1 2 3 |
# rpm -qa | grep kernel # dnf info kernel sudo rpm -e `rpm -q kernel` |
# 步驟10、檢查是否有可能造成潛在衝突的套件並嘗試重建 🤖
1 2 3 |
rm -rf /var/lib/rpm/__db.* sudo rpm -Va --nofiles --nodigest sudo rpm --rebuilddb |
# 步驟11、移除衝突的軟體套件 🤖
※這是最重要的一個步驟※
除了sysvinit-tools之外,因為CentOS 7的某些軟體套件升級到CentOS 8會因為「名字不同」導致了檔案衝突。例如:和rpm相關到的依賴軟體套件不能直接刪除,否則會導致rpm無法正常工作,所以改成刪除訊息「–justdb」但是「不實際刪除檔案」來避免升級失敗 🤒 除了下列的軟體套件之外,不建議也不推薦刪除更多軟體套件。請多注意這個步驟,最好能把訊息記錄下來方便debug 🤠
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# > https://vault.centos.org/centos/8/BaseOS/x86_64/os/Packages/ # > https://vault.centos.org/centos/8/AppStream/x86_64/os/Packages/ # dnf info dracut-network # rpm -qa | grep dracut-network sudo rpm -e --nodeps --justdb dracut-network-033-572.el7.x86_64 sudo rpm -ivh --nodeps --force https://vault.centos.org/centos/8/BaseOS/x86_64/os/Packages/dracut-network-049-191.git20210920.el8.x86_64.rpm # dnf info iprutils # rpm -qa | grep iprutils sudo rpm -e --nodeps --justdb iprutils-2.4.17.1-3.el7_7.x86_64 sudo rpm -ivh --nodeps --force https://vault.centos.org/centos/8/BaseOS/x86_64/os/Packages/iprutils-2.4.19-1.el8.x86_64.rpm # sudo rpm -ivh --nodeps --force https://yum.oracle.com/repo/OracleLinux/OL8/baseos/latest/x86_64/getPackage/iprutils-2.4.19-1.el8.x86_64.rpm # dnf info initscripts # rpm -qa | grep initscripts sudo rpm -e --nodeps --justdb initscripts-9.49.53-1.el7_9.1.x86_64 sudo rpm -ivh --nodeps --force https://vault.centos.org/centos/8/BaseOS/x86_64/os/Packages/initscripts-10.00.15-1.el8.x86_64.rpm # sudo rpm -ivh --nodeps --force https://yum.oracle.com/repo/OracleLinux/OL8/baseos/latest/x86_64/getPackage/initscripts-10.00.18-1.el8.x86_64.rpm # dnf info python3-setuptools # rpm -qa | grep python3-setuptools sudo rpm -e --nodeps --justdb python3-setuptools-39.2.0-10.el7.noarch sudo rpm -ivh --nodeps --force https://vault.centos.org/centos/8/BaseOS/x86_64/os/Packages/python3-setuptools-39.2.0-6.el8.noarch.rpm # sudo rpm -ivh --nodeps --force https://yum.oracle.com/repo/OracleLinux/OL8/baseos/latest/x86_64/getPackage/python3-setuptools-39.2.0-7.el8.noarch.rpm # dnf info python3-pip # rpm -qa | grep python3-pip sudo rpm -e --nodeps --justdb python3-pip-9.0.3-8.el7.noarch sudo rpm -ivh --nodeps --force https://vault.centos.org/centos/8/AppStream/x86_64/os/Packages/python3-pip-9.0.3-20.el8.noarch.rpm # sudo rpm -ivh --nodeps --force https://yum.oracle.com/repo/OracleLinux/OL8/appstream/x86_64/getPackage/python3-pip-9.0.3-24.el8.noarch.rpm # dnf info python36-rpmconf # rpm -qa | grep python36-rpmconf # dnf info python3-rpmconf # rpm -qa | grep python3-rpmconf sudo rpm -e --nodeps --justdb python36-rpmconf-1.1.7-1.el7.1.noarch sudo rpm -ivh --nodeps --force https://kojipkgs.fedoraproject.org/packages/rpmconf/1.1.7/2.el8.1/noarch/python3-rpmconf-1.1.7-2.el8.1.noarch.rpm |
—
## 如果是用osboxes.org提供的VirtualBox檔案在測試,那還可能需要重裝flatpak
1 2 3 4 |
# dnf info flatpak # rpm -qa | grep flatpak sudo rpm -e --nodeps --justdb flatpak-1.0.9-13.el7_9.x86_64 sudo rpm -ivh --nodeps --force https://vault.centos.org/centos/8/AppStream/x86_64/os/Packages/flatpak-1.8.5-5.el8_5.x86_64.rpm |
## 如果出現GCC需要更新的提示,可能需要重裝GCC
1 2 3 4 |
# dnf info gcc # rpm -qa | grep gcc sudo rpm -e --nodeps --justdb gcc-4.8.5-44.el7.x86_64 sudo rpm -ivh --nodeps --force https://vault.centos.org/centos/8/AppStream/x86_64/os/Packages/gcc-8.5.0-4.el8_5.x86_64.rpm |
# 步驟12、執行分發同步以使您的系統與CentOS 8完全一致 🤖
1 2 3 |
sudo dnf clean all sudo dnf makecache sudo dnf distro-sync -y --allowerasing --setopt=deltarpm=false --releasever=8 |
※出錯則跳到步驟10去debug
# 步驟13、到這邊就已經升級成功了,在CentOS 8中安裝新的內核 🤖
1 2 3 |
# rpm -qa | grep kernel # dnf info kernel-core sudo dnf install -y kernel-core |
# 步驟14、執行CentOS 8最小化安裝 🤖
sudo dnf -y groupupdate "Core" "Minimal Install"
# 步驟15、在CentOS 8中確認有安裝常用軟體 🤖
1 2 3 4 5 6 |
sudo dnf install -y grubby grub2 grub2-tools-extra grub2-common grub2-pc \ grub2-tools-efi grub2-tools-minimal grub2-efi grub2-pc-modules grub2-tools \ NetworkManager network-scripts shim screen rpmconf yum-utils \ htop ncdu perl tar unzip gzip bzip2 \ ftp mtr traceroute mutt wget curl \ net-tools bind-utils lsof mlocate crontabs |
# 步驟16、檢查安裝的OS版本,此時已經是CentOS Linux release 8.5.2111 🤖
1 2 |
clear cat /etc/*-release |
# 步驟17、檢查系統的預設啟動選項是不是CentOS 8 🤖
1 2 3 |
# 檢查系統的預設啟動選項 sudo grubby --info DEFAULT | grep CentOS # title="CentOS Linux (4.18.0-348.7.1.el8_5.x86_64) 8" |
# 步驟18、重新啟動 🤖
sudo systemctl reboot
# 步驟19、重新連線之後,首先確保有CentOS 8的最新更新 🤖
1 2 3 |
sudo dnf clean all sudo dnf makecache sudo dnf upgrade -y --refresh |
# 步驟20、再次建立名稱為CentOSUpgrade的視窗 🤖
screen -S CentOSUpgrade
# 步驟21、下載Rocky Linux或是AlmaLinux遷移腳本,並開始執行 🤖
※此步驟開始將系統遷移※
如果一切正常遷移腳本執行的階段就會顯示綠色字,依照系統性能的不同大約更新時間在5~10分鐘左右 🐱🏍 遷移成功後會提示要重開機,我也有附上紀錄檔(migrate2rocky.log | 2024-06-30)可供參考。
1 2 3 4 |
cd /opt wget https://raw.githubusercontent.com/rocky-linux/rocky-tools/main/migrate2rocky/migrate2rocky.sh chmod +x migrate2rocky.sh sudo bash migrate2rocky.sh -r |
1 2 3 4 |
cd /opt wget https://raw.githubusercontent.com/AlmaLinux/almalinux-deploy/master/almalinux-deploy.sh chmod +x almalinux-deploy.sh sudo bash almalinux-deploy.sh |
※出錯則跳到步驟24去debug
# 步驟22、遷移完成後檢查安裝的OS版本,此時已經是Rocky Linux 8.10 (Cerulean Leopard) 🤖
1 2 |
clear cat /etc/*-release |
# 步驟23、檢查系統的預設啟動選項是不是Rocky Linux或是AlmaLinux 🤖
1 2 3 4 5 6 |
# 檢查系統的預設啟動選項 sudo grubby --info DEFAULT | grep Rocky # title="Rocky Linux (4.18.0-553.5.1.el8_10.x86_64) 8.10 (Green Obsidian)" # title="AlmaLinux (4.18.0-553.5.1.el8_10.x86_64) 8.10 (Cerulean Leopard)" # 重新啟動 sudo systemctl reboot |
# 步驟24、檢查是否有可能造成潛在衝突的套件並嘗試重建 🤖
1 2 3 4 |
# 檢查是否有可能造成潛在衝突的套件並嘗試重建 rm -rf /var/lib/rpm/__db.* sudo rpm -Va --nofiles --nodigest sudo rpm --rebuilddb |
# 步驟25、移除CentOS儲存庫(如果仍然存在) 🤖
1 2 3 |
# 移除CentOS儲存庫(如果仍然存在) # ls -lh /etc/yum.repos.d sudo rm -f /etc/yum.repos.d/CentOS-* |
# 步驟26、確保有Rocky Linux的最新更新 🤖
1 2 3 |
# 確保有Rocky Linux的最新更新 sudo dnf makecache sudo dnf upgrade -y --refresh |
以上,打完收工啦~ 🚀🚄🏎🏍🚆
ref.