前言
2023 年 6 月 10 日,Debian 正式發布了其最新的穩定本12(代號 bookworm ),作為一名 Linux 的愛好者,怎能不第一時間升級它,
相對于 Debian 11,Debian 12 包含大量更新的軟體包(上一版本中超過 67% 的包),個人感徑訓是可以升級的,不過前期還是不要用在主力機上,
準備作業
除非你是物理服務器,以及沒有用過奇奇怪怪定制或修改的內核的 KVM 構架的 VPS 和云主機,否則升級大版本更新內核是有一定機率導致 Grub 加載失敗的,切記備份重要資料!
OpenVZ 6 和 LXC 構架的 VPS 是無法升級的,因為他們沒有自己獨立的內核,
再強調一遍,一定要備份重要資料!
查看自己是那個debian的版本的命令,
cat /etc/debian_version
# 或者
cat /etc/os-release
更新系統
在安裝前,請先更新系統,
apt update
apt upgrade -y
apt dist-upgrade -y
apt autoclean
apt autoremove -y
如果內核更新了,可以重啟讓最新的內核生效,也可以直接進行升級,
升級系統
手動升級
首先更新 apt 源,替換 bullseye 為 bookworm:
sed -i 's/bullseye/bookworm/g' /etc/apt/sources.list
sed -i 's/bullseye/bookworm/g' /etc/apt/sources.list.d/*.list
對于 Debian 12 以后的版本,所有 Debian 可以分發的打包的非自由韌體二進制檔案(non-free),比如某些驅動,都被轉移到 Debian Archive 中的一個新組件,稱為非自由韌體(non-free-firmware),如果您從舊版的 Debian 升級,并且需要這些韌體二進制檔案,您應該更新您系統上的 /etc/apt/sources.list,以使用這個新組件(來源):
sed -i 's/non-free/non-free non-free-firmware/g' /etc/apt/sources.list
默認的系統 apt 源檔案 /etc/apt/sources.list 應該是類似這樣的:
deb http://deb.debian.org/debian bookworm main contrib non-free non-free-firmware
deb-src http://deb.debian.org/debian bookworm main contrib non-free non-free-firmware
deb http://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware
deb-src http://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware
deb http://deb.debian.org/debian bookworm-updates main contrib non-free non-free-firmware
deb-src http://deb.debian.org/debian bookworm-updates main contrib non-free non-free-firmware
國內服務器可以替換 deb.debian.org 和 security.debian.org 為 mirrors.tuna.tsinghua.edu.cn
然后我們再次執行更新系統:
apt update
apt upgrade -y
apt dist-upgrade -y
更新程序種會提示一些軟體是否需要自動重啟,選 Yes 即可,以及一些軟體的組態檔是否需要更新,按照自己的情況選擇即可,默認回車即視為使用舊的組態檔,一般會出現在 OpenSSH 等軟體的更新上,
在 apt-listchanges: News 界面可以按 q 退出:

提示是否自動重啟服務:

提示是否更新 OpenSSH 組態檔:

注意某些軟體更新后可能會更新 systemd 服務配置,此時我們可以執行 systemctl daemon-reload 重新加載配置,
如果升級的時候遇到了如下錯誤:
Setting up dbus-daemon (1.14.6-1) ...
UUID file '/var/lib/dbus/machine-id' should contain a hex string of length 32, not length 0, with no other text
dpkg: error processing package dbus-daemon (--configure):
installed dbus-daemon package post-installation script subprocess returned error exit status 1
dpkg: dependency problems prevent configuration of dbus:
dbus depends on dbus-daemon (= 1.14.6-1); however:
Package dbus-daemon is not configured yet.
dpkg: error processing package dbus (--configure):
dependency problems - leaving unconfigured
Processing triggers for libc-bin (2.36-9) ...
Errors were encountered while processing:
dbus-daemon
dbus
E: Sub-process /usr/bin/dpkg returned an error code (1)
洗掉 /var/lib/dbus/machine-id 這個空檔案后重新執行命令即可,升級 dbus 時會自動生成這個檔案,
rm -rf /var/lib/dbus/machine-id
更新后洗掉不必要的軟體和依賴:
apt autoclean
apt autoremove -y
然后我們使用 reboot 命令重啟系統,耐心等待后,查看最新的系統版本:
root@debian ~ # cat /etc/debian_version
12.0
root@debian ~ # lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 12 (bookworm)
Release: 12
Codename: bookworm
root@debian ~ # uname -a
Linux debian 6.1.0-9-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.27-1 (2023-05-08) x86_64 GNU/Linux
這時我們就已經更新到了最新的 Debian 12 Bookworm 和內核了,
使用一鍵腳本自動升級
腳本地址:Github
腳本命令:
bash <(curl -sSL https://raw.githubusercontent.com/wikihost-opensource/linux-toolkit/main/system-upgrade/debian.sh)
如果你是 Debian 10 的系統,那么你需要執行兩次腳本,因為腳本每次執行只會升級一個版本,
Debian 9 升級到 Debian 10
Debian 10 升級到 Debian 11
Debian 11 升級到 Debian 12
更新程序種會提示一些軟體是否需要自動重啟,選 Yes 即可,以及一些軟體的組態檔是否需要更新,按照自己的情況選擇即可,默認回車即視為使用舊的組態檔,一般會出現在 OpenSSH 等軟體的更新上,具體請參考上文手動安裝,
最后
祝大家玩的開心,
感謝一下文章:
- https://ybfl.xyz/sites/258.html
- https://sysin.org/blog/debian-12/
- https://u.sb/debian-upgrade-12/
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/554973.html
標籤:其他
上一篇:源生創新 云享未來|GOTC全球開源技術峰會華為云云原生精彩時刻
下一篇:返回列表
