Upgrade Ubuntu Server From 16.04 to 18.04.1

I have received several notifications from my Ubuntu server running in Azure for asking me to upgrade the server to Ubuntu 18.04.1. When Ubuntu 18.04 was first released, I didn’t upgrade the server. I was afraid there could be compatibility issues and I don’t want to break the server. With the release of 18.04.1, it seems the version is stable enough for an upgrade. So I decided to upgrade the server. 

Here is what I did.

First of all, I updated the server with apt update && apt upgrade, and then I backed up my server with Azure VM backup. In case upgrade failed, I can restore the VM back.

Then I ran do-release-upgrade to upgrade the server. The os kernel seemed to upgrade successfully, but the software package upgrade failed with the following output. 

authenticate 'bionic.tar.gz' against 'bionic.tar.gz.gpg' 
extracting 'bionic.tar.gz'

 libpython3.6-stdlib:amd64
 python3.6
 python3-apt
 python3
 python3-cffi-backend
 apt-xapian-index
 python3-xapian
 python3-gi
 mailutils
 python3-markupsafe
 python3-systemd
 python3-gdbm:amd64
 python3-lib2to3
 python-apt
 dh-python
 python3-distutils
 libpython3-stdlib:amd64
 python3-yaml
 python3-pycurl
 python3-dbus

Upgrade complete

The upgrade has completed but there were errors during the upgrade
process.

To continue please press [ENTER]

I did some search on the internet. It seems a common issue. To solve this issue, I ran the command sudo mv /usr/share/dbus-1/system-services/org.freedesktop.systemd1.service /usr/share/dbus-1/system-services/org.freedesktop.systemd1.service.bak as it is mentioned here

After the issue was fixed, I just ran sudo apt-get dist-upgrade to upgrade all packages, and I chose to keep all local copies of configurations. After that, the upgrade completed successfully with all software and services running normally.  

Ubuntu 16.04

前两天收到通知,说是我host在Azure上的这台VM,可以升级到Ubuntu 16.04了。趁着有空,就将它升了上去。

说起来,这台VM也经历好几次版本升级了。最初的时候,OS是Ubuntu 13.04。后来升级到13.10,再后来是14.04。每次升级都或多或少会遇到一些问题,要花些时间troubleshooting。因为怕麻烦,升到14.04之后就没继续折腾15.10,呆在14.04有两年多了。

因为之前升级的时候遇到过问题,我在今天升级之前还专门搜了搜,果然还是有不少人在升级16.04的时候遇到问题。为了以防万一,我觉着还是先做个备份比较保险。这时候就显出用Azure的好处了。Azure里有一个VMBackup服务,大大简化了云端虚拟机的备份和恢复操作,这个服务也支持Hybrid模式,可以将本地VM备份到云端。考虑到云存储非常便宜,这确实是个不错的功能。我之前就建了一个备份策略来保护这台VM,所以只要跑一下已经定义好的Job,备份就完成了。万一升级出了问题,恢复的话也是一个按钮的事。

备份好之后,我就开始跑升级。没想到还挺顺利的,除了mysql升级失败之外,没有遇到什么会导致升级失败的错误。查log之后发现,mysql之所以失败,是因为apparmor保护了一些路径。因为升级的过程中,我选择保留所有的旧的配置文件,这导致mysql需要访问的一些新的文件路径是被apparmor保护的。改了apparmor的设置,问题就解决了。fail2ban也遇到一样的问题,我在旧版里修改的jail rule有一个bug,但旧版忽略了,新版就出错无法启动。修了这个bug之后就好了。其他的服务都没有遇到问题,升级之后就立即可用了。

总之这次升级还蛮顺利的,一个上午就搞定了,我本来还打算搞一天的。

Upgrade to Ubuntu 13.10

晚上花了一点时间,将server的OS从Ubuntu 13.04升级到了13.10。不得不再说一遍,Windows Azure对Linux的支持真是好啊。我升级之前还担心万一失败了,系统起不来怎么办。所以给OS和数据分区的vhd都做了快照,以防万一。没想到,直接用Ubuntu的升级程序 do-release-upgrade,就完成了系统升级,相当顺利。

只是在重起Apache服务的时候遇到了点问题。一开始服务起不来,显示如下错误:

Invalid command ‘LockFile’, perhaps misspelled or defined by a module not included in the server configuration

一通搜索,原来,Ubuntu 13.10的Apache已经升级到了2.4,LockFile这个关键字已经不再用了,2.4中改用Mutext来处理锁定。升级的时候,我选择保留原来的Apache2.conf,这样这个LockFile参数就还保留着。注释掉这一行之后,Apache就可以顺利启动了。有空我再研究,看看2.4的Apache2.conf和2.2的到底有什么不同。现在Apache服务启动正常,只是在读一个网站配置时,有如下错误:

AH00548: NameVirtualHost has no effect and will be removed in the next release /etc/apache2/sites-enabled/default-site:2

另外,升级完成之后,php的mcrypt模块也有问题。在Stackoverflow上找到了下面的解决方法。

sudo ln -s /etc/php5/conf.d/mcrypt.ini /etc/php5/mods-available
sudo php5enmod mcrypt
sudo service apache2 restart