如何將搬瓦工VPS服務器從 Ubuntu 20.04 升級到 Ubuntu 22.04?

前幾天介紹了搬瓦工后臺已經新增了 Ubuntu 22.04,那么如果我們目前使用的是 Ubuntu 20.04,也可以直接升級到 Ubuntu 22.04,但是一般不建議生產環境下直接這么升級,可能會出現問題。本文介紹 Ubuntu 22.04 升級教程,主要是從 Ubuntu 20.04 升級到 Ubuntu 22.04 的教程。如果是更老的 Ubuntu 版本,可能需要先升級到 Ubuntu 20.04 或者是建議備份一下建站環境和數據之后直接安裝 Ubuntu 22.04 吧。

重要提醒:

  1. 不建議直接在生產環境進行升級
  2. 升級前一定要做好數據備份

Ubuntu 22.04 升級前準備

除非你是物理服務器,以及沒有用過奇奇怪怪定制或修改的內核的 KVM 構架的 VPS 和云主機,否則升級大版本更新內核是有一定機率導致 Grub 加載失敗的,切記備份重要數據!

以下操作需要在 root 用戶下完成,請使用?sudo -i?或?su root 切換到 root 用戶進行操作。

首先升級系統到最新狀態:

apt update
apt upgrade -y
apt dist-upgrade -y
apt autoclean
apt autoremove -y

升級之后需要進行重啟,建議重啟讓最新的內核生效。

Ubuntu 22.04 升級方法一

第一種方法是使用 do-release-upgrade 命令,這個方法比較簡單,一般來說可以首選這個方法。

首先安裝?update-manager-core?軟件包:

apt install update-manager-core

然后運行?do-release-upgrade -d 即可更新。按照提示操作即可。

Ubuntu 22.04 升級方法二

還有一種就是手工修改?apt?源文件:

首先更新?apt?源,替換?focal?為?jammy:

sed -i 's/focal/jammy/g' /etc/apt/sources.list
sed -i 's/focal/jammy/g' /etc/apt/sources.list.d/*.list

默認的系統?apt?源文件?/etc/apt/sources.list?應該是類似這樣的:

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://archive.ubuntu.com/ubuntu/ jammy main restricted
# deb-src http://archive.ubuntu.com/ubuntu/ jammy main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://archive.ubuntu.com/ubuntu/ jammy-updates main restricted
# deb-src http://archive.ubuntu.com/ubuntu/ jammy-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://archive.ubuntu.com/ubuntu/ jammy universe
# deb-src http://archive.ubuntu.com/ubuntu/ jammy universe
deb http://archive.ubuntu.com/ubuntu/ jammy-updates universe
# deb-src http://archive.ubuntu.com/ubuntu/ jammy-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://archive.ubuntu.com/ubuntu/ jammy multiverse
# deb-src http://archive.ubuntu.com/ubuntu/ jammy multiverse
deb http://archive.ubuntu.com/ubuntu/ jammy-updates multiverse
# deb-src http://archive.ubuntu.com/ubuntu/ jammy-updates multiverse

## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://archive.ubuntu.com/ubuntu/ jammy-backports main restricted universe multiverse
# deb-src http://archive.ubuntu.com/ubuntu/ jammy-backports main restricted universe multiverse

## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu jammy partner
# deb-src http://archive.canonical.com/ubuntu jammy partner

deb http://archive.ubuntu.com/ubuntu jammy-security main restricted
# deb-src http://archive.ubuntu.com/ubuntu jammy-security main restricted
deb http://archive.ubuntu.com/ubuntu jammy-security universe
# deb-src http://archive.ubuntu.com/ubuntu jammy-security universe
deb http://archive.ubuntu.com/ubuntu jammy-security multiverse
# deb-src http://archive.ubuntu.com/ubuntu jammy-security multiverse

國內服務器可以替換?archive.ubuntu.com?為?mirrors.tuna.tsinghua.edu.cn

然后我們再次執行更新系統:

apt update
apt upgrade -y
apt dist-upgrade -y

更新過程種會提示一些軟件是否需要自動重啟,選 Yes 即可,以及一些軟件的配置文件是否需要更新,按照自己的情況選擇即可,默認回車即視為使用舊的配置文件,一般會出現在 OpenSSH 等軟件的更新上。

更新后刪除不必要的軟件和依賴:

apt autoclean
apt autoremove -y

然后使用 reboot?命令重啟系統,耐心等待后,查看最新的系統版本:

root@ubuntu ~ # lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04 LTS
Release:        22.04
Codename:       jammy
root@ubuntu ~ # uname -a
Linux ubuntu 5.15.0-25 #4-Ubuntu SMP Fri Apr 1 07:36:38 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

這時我們就已經更新到了最新的 Ubuntu 22.04 Jammy 和內核了。

參考:https://u.sb/ubuntu-upgrade/

Ubuntu 桌面版升級教程

在 2022 年 4 月 21 日當天或之后,直到 2022 年 07 月第一次修正版本發布,Ubuntu 都不會給予你任何可視化的升級提示,因為第一個修改版本被認為是初始錯誤被消除后最穩定的版本。

這意味著,你要么等到 7 月,你要么強制升級。如何強制升級?打開“軟件和更新 Software and Updates”,轉到“更新 Updates”標簽頁。更改“通知我有新的 Ubuntu 版本 Settings notify me of new ubuntu version” 為 “任意新的 Ubuntu 版本 any new version”。

在完成后,你應該會在桌面上看到一個升級提示。遵循屏幕上的指示,接著繼續升級過程。

這個提示也會計算升級系統所列軟件包所需的時間,因此,仔細的閱讀更新程序的輸出內容。在你準備好了以后,開始升級過程。

最后,在升級過程完成后,重新啟動系統,享受全新的 Ubuntu 22.04 LTS Jammy Jellyfish。

參考:https://os.51cto.com/article/706965.html

搬瓦工推薦方案

溫馨提醒 如果您有選擇困難癥,直接選中間的 CN2 GIA-E方案,季付 $49.99,多達 12 個機房任意切換
方案 內存 CPU 硬盤 流量/月 帶寬 機房 價格 購買
CN2
(最便宜)
1GB 1核 20GB 1TB 1Gbps DC3 CN2
DC8 ZNET
$49.99/年 直達
CN2 2GB 1核 40GB 2TB 1Gbps $52.99/半年
$99.99/年
直達
CN2 GIA-E
(最推薦)
1GB 2核 20GB 1TB 2.5Gbps DC6 CN2 GIA-E
DC9 CN2 GIA
日本軟銀 JPOS_1
荷蘭 EUNL_9
$49.99/季度
$169.99/年
直達
CN2 GIA-E 2GB 3核 40GB 2TB 2.5Gbps $89.99/季度
$299.99/年
直達
HK 2GB 2核 40GB 0.5TB 1Gbps 中國香港 CN2 GIA $89.99/月
$899.99/年
直達
HK 4GB 4核 80GB 1TB 1Gbps $155.99/月
$1559.99/年
直達
TOKYO 2GB 2核 40GB 0.5TB 1.2Gbps 日本東京 CN2 GIA $89.99/月
$899.99/年
直達
TOKYO 4GB 4核 80GB 1TB 1.2Gbps $155.99/月
$1559.99/年
直達
搬瓦工優惠碼:BWH3HYATVBJW 搬瓦工全方案實時庫存檢測
贊(0)
版權聲明:本文采用知識共享 署名4.0國際許可協議 [BY-NC-SA] 進行授權, 轉載請注明出處。
文章名稱:《如何將搬瓦工VPS服務器從 Ubuntu 20.04 升級到 Ubuntu 22.04?》
文章鏈接:http://www.lrracing.com/31032.html
【聲明】:國外主機測評僅分享信息,不參與任何交易,也非中介,所有內容僅代表個人觀點,均不作直接、間接、法定、約定的保證,讀者購買風險自擔。一旦您訪問國外主機測評,即表示您已經知曉并接受了此聲明通告。
【關于安全】:任何 IDC商家都有倒閉和跑路的可能,備份永遠是最佳選擇,服務器也是機器,不勤備份是對自己極不負責的表現,請保持良好的備份習慣。