Archive of

Notes for upgrading Debian 7 to Debian 10 on an old cheap VPS

前言

好几年前 123systems.net 打折的时候买了这个vps,年付只要 $3.8。不过配置还说得过去,256M 内存,10G ssd硬盘,每个月有512G流量,而且是 KVM的。那时候我还不知道啥是docker,买这台vps的目标很单纯,就是翻墙。然而当时 123systems.net 的服务非常烂,网络差,北京连过去经常丢包不说,而且还常down机,你提个ticket也要过上好几天才有人搭理。便宜没好货....看在乞丐价的份上,所以大爷我也忍了。不就3块8么,全当喂狗了。(所以后面不久我又从另一家买了一台配置高点的)。后来听说 123systems 被另一家 vps 提供商(对,就是chicago vps)收购了,我想那服务是不是会好点,就又连上去试了下。别说,网络真的稳定多了!也几乎不down机了,于是它就作为我的一个备用翻墙节点用起来了。这也才有了后面的年年续费。

在这台机器上我用了好几年 Ubuntu 14.04,但这台 vps 能够安装的操作系统模板,这么多年就一直没更新过。Ubuntu 最高是14.04, Centos是 6.5, Debian是7.3,Fedora 是 20。后来我玩 Docker 的时候想到这台机器是 kvm 啊,可以装docker的。于是就在上面装了Docker。后来随着 Docker 的一直升级,渐渐地新版 Docker 就不再支持 Ubuntu 14.04了。虽然用旧版也不是不行,但是我动了升级操作系统的念头。虽然模板中只有 14.04, 我总可以自己升级装好的系统嘛。然而升级并不顺利,我曾经磕磕绊绊升到 16.04 用了几天,发现不稳定(经常无故自动关机)就又回到了 14.04。后来经过一个不眠之夜,我装上了 Debian 7 又费了好大劲升级到 Debian 8 jessie。这个还比较稳定,就一直用着,直到昨天晚上。

昨天晚上闲逛的时候,我发现有一个人写了个一键自动重灌vps操作系统的脚本,支持 Debian 和 Centos, 支持指定版本号。 我的心又活络起来了。虽然那篇文间是2018年的,已经挺老了,但我还是打定主意打算试试,万一支持 Debian 10 呢。于是该备份的备份,然后开始尝试。不过作者说了不保证谁都能用,也不保证不丢数据。悲伤的是 他说对了

Debian装上启动不了,Centos 看文章下面的评论最高只能升级到 6.10 而我的目标是 7.7。罢了罢了!此路不通!看看天色已晚,已过夜里12点。我打算再最后试一次, 装个 Fedora 20 看看能不能一路升到最新。然而也不顺利。都1点了,去他的,睡觉了。

心里有事,睡得也不踏实,于是今天早上早早就起来了。不想再用Ubuntu了,于是重新装上 Deiban 7, 我想这次,就升级到 Deiban 8 和过去一样算了,回到原点凑付用吧。一台年付才3.8的破机器,不值当我花这么多时间折腾。然而 Debian 7 的源已经都死掉了,所以 Deiban 7 的系统也没法更新了,直接升 8 就好了。然而升 8 也不顺利,上次升级的时候并没有记笔记,所以好多问题东西要重新搜索,重新找(所以我今天在写笔记!)。就在到处找的过程中,我看到一个人在某个问题下评论说,他从 Debian 7 一直升级到了 Debian10,虽然花了很多时间,但感觉 amazing! 那我也试试唄。

现在是中午12点,开心的是我也搞定了那个升级,并且正在趁热乎把中间找资料的坎坷记录下来。那么口水到此结束,下面干货开始:

正文

  1. Debian 7 更新 /etc/apt/sources.list 为
deb http://deb.debian.org/debian/ jessie main contrib non-free
deb-src http://deb.debian.org/debian/ jessie main contrib non-free

deb http://security.debian.org/ jessie/updates main contrib non-free
deb-src http://security.debian.org/ jessie/updates main contrib non-free

deb http://deb.debian.org/debian/ jessie-updates main contrib non-free
deb-src http://deb.debian.org/debian/ jessie-updates main contrib non-free
  1. 用 root
apt-get -y update
apt-get -y install apt -t jessie
apt -y upgrade
apt-get -y dist-upgrade 
reboot

当然升级之路不会这么顺利,你肯定会遇到 no public key available for the following key IDs: xxxxx 和什么源已过期无法验证之类的报错。对于前者, 使用 apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 1397BC53640DB551(请一定记着把key换成你那里看到的key);至于后者,可以用加参数大法apt-get -y -o Acquire::Check-Valid-Until=false update 解决。总起来说这一步还是蛮顺利的,升级完重新启动能直接进系统,网络什么都是好的。

  1. Jessie to Stretch,继续用root身份哦
sed -i 's/jessie/stretch/g' /etc/apt/sources.list
apt-get update
apt-get upgrade
apt-get dist-upgrade

应该说这个升级也蛮顺利的,除了升级完重启后....我就再也连接不上vps之外。还好有 Vnc 可以用,虽然网页上提供的 html5 vnc cient不能使,但我用本机的 vncviewer 能够连接上。 连上之后,发现除了网卡参数全丢了,其他都是正常的。那...网卡参数怎么设置?原来的参数都是啥?我不知道哇。于是又一通搜索,各种尝试,还是不行。最后想起 vps 控制台有 Reconfigure Networking 的功能,那就死马当活马医,试试吧。一试,好了!那么.....从7升到9已经是挺了不起的成就了,还升10么?升!

  1. Stretch to Buster,继续用 root 身份
sed -i 's/stretch/buster/g' /etc/apt/sources.list
apt-get update
apt-get upgrade
apt-get full-upgrade

这个升级也蛮顺利的,然而升级完重启后就连接不上vps的问题再一次发生了。根据刚才的经验用了 vps 控制台的 Reconfigure Networking 的功能,但这次没有那么走运,网还是不通。经过一番排查之后,发现这次系统注入参数时使用的网卡名字是 eth0,而我记得以前网卡的名字是 ens3。于是修改 /etc/network/interfaces 文件,把 eth0 改为 ens3 然后 systemctl start networking.service。成功!

每一次折腾,都能学到点什么,技术就是这么一点点折腾来的。但是如果不记录下来,下次再找又要花很多时间。所以...我又花了40分钟写这篇blog。不过还是很开心啊!把看似不可能事情最终搞成了,就是那样的开心!

参考资料: debian-wheezy-update-repository
参考资料: how-to-upgrade-debian-7-wheezy-to-10-buster-safely
参考资料: how-to-upgrade-debian-8-jessie-to-debian-9-stretch

Everything is hard before it is easy.

by Johann Wolfgang von Goethe

x-www-form-urlencoded vs JSON, which one is better?

This old blog has given a strong answer.

How to get coloured terminal over ssh?

I haven't used my old MBP 13 for nearly a month. This evening I picked it up and opened the iTerm2 then connected to my home server through ssh. I noticed I get a white-black colored terminal. What's wrong? I remembered it was colorful when I logged into this machine last time using iTerm2 on my MBP 15.

Firstly, I checked the version of iTerm2, it was a bit old, so I updated it first. Unfortunately, it doesn't help. I noticed I was using bash instead of zsh on this machine. So I ran chsh and changed the shell from bash to ssh. It also doesn't help. Then I find this answer from stackoverflow.com. A comment in this answer reminded me: I should check and compare the terminal configuration in iTerm2. So I found the secret!

Command + , open the preference, then click the profiles tab, then change the Report terminal type from xterm to xterm-256 color, that's it!

Set done a simple automatically backup system for this site

I didn't forget I haven't set up a backup system for this blog site. So I got it done today.

Two things need to backup, they are

  1. the MySQL database
  2. the uploads directory that contains the pictures, files you've uploaded to this site

Since local backup is not safe, finally I chose the Yandex.Disk as my cloud storage. Just register an account in 5 minutes and you will get 10G cloud storage with Linux friendly sync feature. Yandex.Disk also supports symbol links, that's quite good.

run crontab -e and fill in below lines, the setting was done!

 15 3 * * * mysqldump --databases blog | gzip > /home/zhongwei/Yandex.Disk/backups/mysql/blog_`date '+\%Y\%m\%d-\%H\%M\%S'`.sql.gz
 20 3 * * * find /home/zhongwei/Yandex.Disk/backups/mysql/blog* -mtime +30 -exec rm {} \;

As the uploads folder for my blog, what you need to do is creating a symbol link to the Yandex.Disk folder:

ln -s /www/blog/uploads /home/zhongwei/Yandex.Disk/backups/blog_uploads

This blog is inspired by source