仗剑只为她

仗剑只为她

升級Debian12不會?,那麼用這個腳本就對了

前言#

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 退出:

image

提示是否自動重啟服務:

是否重啟

提示是否更新 OpenSSH 配置文件:

是否更新 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 等軟體的更新上。具體請參考上文手動安裝。

最後#

祝大家玩的開心。

感謝一下文章:

  1. https://ybfl.xyz/sites/258.html
  2. https://sysin.org/blog/debian-12/
  3. https://u.sb/debian-upgrade-12/

湖上西風斜日,荷花落盡紅英

載入中......
此文章數據所有權由區塊鏈加密技術和智能合約保障僅歸創作者所有。