Ubuntu 16.10更新到17.10及18.04 LTS

最近Ubuntu 18.04 LTS开放了从17.10版本在线升级(16.04 LTS的在线升级还要再等到六月的18.04.1)。正好前几天一个linode从17.04通过update-manager-coredo-release-upgrade命令刚升级到17.10,今天很顺利又升级到了18.04 LTS。但是用update-manager-core升级另外一台16.10的linode的时候出现了问题,提示:

1
2
Can not upgrade
An upgrade from 'yakkety' to 'artful' is not supported with this tool.

而Ubuntu官方也表示,不支持用户跨版本升级,只能按照16.10->17.04->17.10->18.04逐个版本升级上去。

linode默认使用自己的镜像源,/etc/apt/sources.list是这个样子的:

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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# deb http://mirrors.linode.com/ubuntu/ yakkety main restricted
# deb http://mirrors.linode.com/ubuntu/ yakkety-updates main restricted
# deb http://security.ubuntu.com/ubuntu yakkety-security main restricted
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://mirrors.linode.com/ubuntu/ yakkety main restricted
# deb-src http://mirrors.linode.com/ubuntu/ yakkety main restricted
## Major bug fix updates produced after the final release of the
## distribution.
deb http://mirrors.linode.com/ubuntu/ yakkety-updates main restricted
# deb-src http://mirrors.linode.com/ubuntu/ yakkety-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://mirrors.linode.com/ubuntu/ yakkety universe
# deb-src http://mirrors.linode.com/ubuntu/ yakkety universe
deb http://mirrors.linode.com/ubuntu/ yakkety-updates universe
# deb-src http://mirrors.linode.com/ubuntu/ yakkety-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://mirrors.linode.com/ubuntu/ yakkety multiverse
# deb-src http://mirrors.linode.com/ubuntu/ yakkety multiverse
deb http://mirrors.linode.com/ubuntu/ yakkety-updates multiverse
# deb-src http://mirrors.linode.com/ubuntu/ yakkety-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://mirrors.linode.com/ubuntu/ yakkety-backports main restricted universe multiverse
# deb-src http://mirrors.linode.com/ubuntu/ yakkety-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 yakkety partner
# deb-src http://archive.canonical.com/ubuntu yakkety partner
deb http://security.ubuntu.com/ubuntu yakkety-security main restricted
# deb-src http://security.ubuntu.com/ubuntu yakkety-security main restricted
deb http://security.ubuntu.com/ubuntu yakkety-security universe
# deb-src http://security.ubuntu.com/ubuntu yakkety-security universe
deb http://security.ubuntu.com/ubuntu yakkety-security multiverse
# deb-src http://security.ubuntu.com/ubuntu yakkety-security multiverse

因为16.10停止支持很久了,所以在做apt-get update的时候这些镜像拿到的都是404,所以这时候其实包管理器的更新功能也相当于挂掉了。askubuntu上有一个回答,是把sources.list里所有yakkety都替换成artful然后更新,但是他自己也声称这种方法是一个hack,不保证会不会出问题。不推荐使用这种方法。

实际上,Ubuntu为旧的发行版( End of Life (EOL) release)都提供了升级支持,可以通过修改update-manager-core配置文件的方法完成升级。

首先 备份 已有的/etc/apt/sources.list文件(可能需要sudo权限,下略):

1
cp -a /etc/apt/sources.list /etc/apt/sources.list.bak

这份资料里提到可以使用:

1
sed -i -e 's/de.archive/old-releases/' /etc/apt/sources.list

也可以直接把文件替换为以下内容:

1
2
3
4
5
6
7
8
## EOL upgrade sources.list
# Required
deb http://old-releases.ubuntu.com/ubuntu/ yakkety main restricted universe multiverse
deb http://old-releases.ubuntu.com/ubuntu/ yakkety-updates main restricted universe multiverse
deb http://old-releases.ubuntu.com/ubuntu/ yakkety-security main restricted universe multiverse
# Optional
#deb http://old-releases.ubuntu.com/ubuntu/ yakkety-backports main restricted universe multiverse

之后执行apt-get update,如果 没有任何error 或者missing repositories,则说明这一步换源成功。

接下来修改update manager配置文件。常用的一个配置文件在/etc/update-manager/release-upgrades,用来控制升级到普通版(normal)还是长期支持版(lts);另外还有一个文件在/var/lib/update-manager/meta-release,用来记录各个版本的名称、日期、源和支持情况等。打开后一个文件。

1
vi /var/lib/update-manager/meta-release

找到其中16.10和17.04的部分,修改源地址和支持情况。文件初始状态可能如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Dist: yakkety
Name: Yakkety Yak
Version: 16.10
Date: Thu, 13 October 2016 16:10:00 UTC
Supported: 0
Description: This is the 16.10 release
Release-File: http://archive.ubuntu.com/ubuntu/dists/yakkety/Release
ReleaseNotes: http://changelogs.ubuntu.com/EOLReleaseAnnouncement
UpgradeTool: http://archive**.ubuntu.com/ubuntu/dists/yakkety-updates/main/dist-upgrader-all/current/yakkety.tar.gz
UpgradeToolSignature: http://archive.ubuntu.com/ubuntu/dists/yakkety-updates/main/dist-upgrader-all/current/yakkety.tar.gz.gpg
Dist: zesty
Name: Zesty Zapus
Version: 17.04
Date: Thu, 13 April 2017 17:04:00 UTC
Supported: 0
Description: This is the 17.04 release
Release-File: http://archive.ubuntu.com/ubuntu/dists/zesty/Release
ReleaseNotes: http://changelogs.ubuntu.com/EOLReleaseAnnouncement
UpgradeTool: http://archive.ubuntu.com/ubuntu/dists/zesty-updates/main/dist-upgrader-all/current/zesty.tar.gz
UpgradeToolSignature: http://archive.ubuntu.com/ubuntu/dists/zesty-updates/main/dist-upgrader-all/current/zesty.tar.gz.gpg

替换16.10和17.04的Supported为1,并把源换成EOLUpgrade的源,让update manager认为17.04还在支持,并从EOLUpgrade处获得更新信息:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Dist: yakkety
Name: Yakkety Yak
Version: 16.10
Date: Thu, 13 October 2016 16:10:00 UTC
Supported: 1
Description: This is the 16.10 release
Release-File: http://old-releases.ubuntu.com/ubuntu/dists/yakkety/Release
ReleaseNotes: http://changelogs.ubuntu.com/EOLReleaseAnnouncement
UpgradeTool: http://old-releases.ubuntu.com/ubuntu/dists/yakkety-updates/main/dist-upgrader-all/current/yakkety.tar.gz
UpgradeToolSignature: http://old-releases.ubuntu.com/ubuntu/dists/yakkety-updates/main/dist-upgrader-all/current/yakkety.tar.gz.gpg
Dist: zesty
Name: Zesty Zapus
Version: 17.04
Date: Thu, 13 April 2017 17:04:00 UTC
Supported: 1
Description: This is the 17.04 release
Release-File: http://old-releases.ubuntu.com/ubuntu/dists/zesty/Release
ReleaseNotes: http://changelogs.ubuntu.com/EOLReleaseAnnouncement
UpgradeTool: http://old-releases.ubuntu.com/ubuntu/dists/zesty-updates/main/dist-upgrader-all/current/zesty.tar.gz
UpgradeToolSignature: http://old-releases.ubuntu.com/ubuntu/dists/zesty-updates/main/dist-upgrader-all/current/zesty.tar.gz.gpg

然后再执行:

1
do-release-upgrade

update manager就会自动更新到17.04而不是17.10了。更新过程中按照屏幕提示安装新包、删掉弃用的包、并且重启。对于安装了amp的机器,会在几个彩色页面询问你是否需要修改grub、ssh配置、apache2配置和mysql配置,这里都按照默认选择keep原有配置。

最后由于17.04->17.10的过程中PHP升级到了PHP7(似乎17.10是PHP7.1而18.04则到了PHP7.2),而默认apache2没有把这个模块开启,因此更新完成后还需要:

1
2
a2enmod php7.2
systemctl restart apache2

之后lamp应该就完全恢复到更新前的样子了。

结论:还是lts好