服務端升級 Ubuntu 20.04 LTS 記錄

服務端升級 Ubuntu 20.04 LTS 記錄

本文將介紹如何在當前時間點,將服務器版本的 Ubuntu 18.04 LTS 升級為最新的 Ubuntu 20.04 LTS,以及升級過程中的一些細節,希望能幫到躍躍欲試的 Ubuntu 同好。

將數據進行備份等操作需要自行處理,另外確保網絡穩定,建議都在服務器跳板機上進行操作,更為穩妥。

當前這篇內容已經運行在 Ubuntu 20.04 LTS 系統環境中,:)

準備工作

先使用 apt update 看看有哪些內容可以升級。

apt update


Hit:1 http://mirrors.aliyun.com/ubuntu bionic InRelease

Get:2 http://mirrors.aliyun.com/ubuntu bionic-updates InRelease [88.7 kB]

Get:3 http://mirrors.aliyun.com/ubuntu bionic-security InRelease [88.7 kB]

Get:4 http://mirrors.aliyun.com/ubuntu bionic-updates/universe Sources [281 kB]

Get:5 http://mirrors.aliyun.com/ubuntu bionic-updates/main Sources [315 kB]

Get:6 http://mirrors.aliyun.com/ubuntu bionic-updates/main amd64 Packages [915 kB]

Get:7 http://mirrors.aliyun.com/ubuntu bionic-updates/main i386 Packages [669 kB]

Get:8 http://mirrors.aliyun.com/ubuntu bionic-updates/main Translation-en [315 kB]

Get:9 http://mirrors.aliyun.com/ubuntu bionic-updates/universe i386 Packages [1,014 kB]

Get:10 http://mirrors.aliyun.com/ubuntu bionic-updates/universe amd64 Packages [1,065 kB]

Get:11 http://mirrors.aliyun.com/ubuntu bionic-updates/universe Translation-en [331 kB]

Hit:12 https://download.docker.com/linux/ubuntu bionic InRelease

Get:13 http://mirrors.aliyun.com/ubuntu bionic-security/universe Sources [168 kB]

Get:14 http://mirrors.aliyun.com/ubuntu bionic-security/main Sources [146 kB]

Get:15 http://mirrors.aliyun.com/ubuntu bionic-security/main amd64 Packages [692 kB]

Get:16 http://mirrors.aliyun.com/ubuntu bionic-security/main i386 Packages [459 kB]

Get:17 http://mirrors.aliyun.com/ubuntu bionic-security/universe amd64 Packages [657 kB]

Get:18 http://mirrors.aliyun.com/ubuntu bionic-security/universe i386 Packages [618 kB]

Fetched 7,823 kB in 3s (3,106 kB/s)

Reading package lists... Done

Building dependency tree

Reading state information... Done

19 packages can be upgraded. Run 'apt list --upgradable' to see them.

接著執行 apt upgrade -y 耐心等待軟件升級完畢即可。如果你最近已經更新過,則會得到類似下面的內容提示。

apt update


Reading package lists... Done

Building dependency tree

Reading state information... Done

All packages are up to date.

如果你覺得升級過程中軟件源比較慢,可以嘗試替換源,比如像下面這樣操作。

sed -i -e "s/mirrors.cloud.aliyuncs.com/mirrors.tuna.tsinghua.edu.cn/" /etc/apt/sources.list

升級過程的小麻煩們

當我們執行 do-release-upgrade 嘗試進行升級的時候,可能會出現三種情況告訴我們不能夠升級。

系統中還有未完全升級的軟件

當你執行完畢命令後,可能會得到"Please install all available updates for your release before upgrading"的提示,這說明你其實並未將所有軟件都完成升級。

do-release-upgrade


Checking for a new Ubuntu release

Please install all available updates for your release before upgrading.

你可能會好奇,我明明執行過 update 和 upgrade 了,為什麼還會出現這種情況呢?

這裡有一個很大的可能是,使用過 apt-mark 將部分軟件版本鎖定,需要先執行解鎖操作,比如:

apt-mark unhold docker-ce

至於如何看到需要升級或者解鎖的軟件呢?

可以使用 apt update && apt list --upgradable 命令進行查詢:

apt list --upgradable


...

Reading package lists... Done

Building dependency tree

Reading state information... Done

1 package can be upgraded. Run 'apt list --upgradable' to see it.


...


Listing... Done

docker-ce/bionic 5:19.03.8~3-0~ubuntu-bionic amd64 [upgradable from: 5:19.03.6~3-0~ubuntu-bionic]

N: There are 23 additional versions. Please use the '-a' switch to see them.

然後在再次執行 apt upgrade -y 即可完成所有軟件升級。

但是千萬別高興太早,因為你還可能遇到接下來的事情。

解除系統升級鎖定

當所有軟件都升級就緒後,繼續使用 do-release-upgrade 升級軟件,會看到類似下面的提示。

do-release-upgrade


Checking for a new Ubuntu release

There is no development version of an LTS available.

To upgrade to the latest non-LTS develoment release

set Prompt=normal in /etc/update-manager/release-upgrades.

這裡因為官網尚未正式打開版本推送,所以如果要想得到版本更新,需要對 do-release-upgrade 添加命令行參數 -d,來允許獲取最新的升級包。

Usage: do-release-upgrade [options]


Options:


-d, --devel-release If using the latest supported release, upgrade to the

development release

作出升級路線選擇

如果你是 Ubuntu 18.04 LTS 用戶的話,此刻我們需要做出一個決定,是一個版本一個版本升級,還是直接跨版本升級,而如果是 Ubuntu 19.10 的用戶則簡單的多,因為不涉及跨版本問題,逐版本升級後半部分內容即可。

我們詳細說說兩種升級方式。

Ubuntu 18.04 逐版本升級 Ubuntu 20.04

有一句流傳甚遠的話叫做"步子不能邁的太大",某些時候也可以用在軟件升級這件事上。

打開
/etc/update-manager/release-upgrades 文件,我們可以看到文件說明:

[DEFAULT]

# Default prompting behavior, valid options:

#

# never - Never check for, or allow upgrading to, a new release.

# normal - Check to see if a new release is available. If more than one new

# release is found, the release upgrader will attempt to upgrade to

# the supported release that immediately succeeds the

# currently-running release.

# lts - Check to see if a new LTS release is available. The upgrader

# will attempt to upgrade to the first LTS release available after

# the currently-running one. Note that if this option is used and

# the currently-running release is not itself an LTS release the

# upgrader will assume prompt was meant to be normal.

Prompt=lts

將 Prompt=lts 修改為 Prompt=normal ,然後執行 do-release-upgrade -d,會開始第一階段升級:

do-release-upgrade -d


Checking for a new Ubuntu release

Get:1 Upgrade tool signature [1,554 B]

Get:2 Upgrade tool [1,329 kB]

Fetched 1,331 kB in 0s (0 B/s)

authenticate 'eoan.tar.gz' against 'eoan.tar.gz.gpg'

extracting 'eoan.tar.gz'


Reading cache

...

根據實際情況,我們"一路 Next"之後,在即將完成升級時,會看到下面的提示內容:

。。。

System upgrade is complete.


Restart required


To finish the upgrade, a restart is required.

If you select 'y' the system will be restarted.

待系統重啟之後,登陸系統會看到系統已經成功升級為 Ubuntu 19.10:

Welcome to Ubuntu 19.10 (GNU/Linux 5.3.0-46-generic x86_64)


* Documentation: https://help.ubuntu.com

* Management: https://landscape.canonical.com

* Support: https://ubuntu.com/advantage


* Ubuntu 20.04 LTS is out, raising the bar on performance, security,

and optimisation for Intel, AMD, Nvidia, ARM64 and Z15 as well as

AWS, Azure and Google Cloud.


https://ubuntu.com/blog/ubuntu-20-04-lts-arrives

我們將
/etc/update-manager/release-upgrades 文件中數值修改為 Prompt=lts ,再次執行 do-release-upgrade -d 就可以開始第二階段的升級了,操作過程和上面沒有區別,一杯水的功夫,服務端再次重啟,Ubuntu 20.04 LTS 就升級完畢啦。

Welcome to Ubuntu 20.04 LTS (GNU/Linux 5.4.0-26-generic x86_64)


* Documentation: https://help.ubuntu.com

* Management: https://landscape.canonical.com

* Support: https://ubuntu.com/advantage


* Ubuntu 20.04 LTS is out, raising the bar on performance, security,

and optimisation for Intel, AMD, Nvidia, ARM64 and Z15 as well as

AWS, Azure and Google Cloud.


https://ubuntu.com/blog/ubuntu-20-04-lts-arrives

驗證完畢逐版本升級,我們試試一步到位的跨版本升級。

Ubuntu 18.04 跨版本升級 Ubuntu 20.04

跨版本升級相當於是逐版本升級的"偷懶版",偷懶當然要到極致,升級軟件包也可以使用 apt full-upgrade -y 這個命令來做。

和逐版本升級不同的是,我們不再需要修改 release-upgrades 配置文件,在升級前只需要確認


/etc/update-manager/release-upgrades 文件的數值是否設置為 lts 即可。

確認數值正確後,執行 do-release-upgrade -d ,根據自己需求進行升級配置選擇即可,"一路 Next" 之後,Ubuntu 20.04 就升級完畢啦。

最後

距離將所有機器升級到 18.04 , Ubuntu 20.04 LTS 的到來,算是一個驚喜。

一般情況下,我們使用 update, upgrade, do-release-upgrade 組合技應該就能順暢完成升級,但是在當前時間點,官網還未完全正式提供 release 升級方案,所以就有了這篇文章。

呃,促成這篇文章還有一個原因,回家後直接睡覺忘記喂貓,被毛孩子抗議叫醒...

--EOF

1


分享到:


相關文章: