■debian stretchからbusterにアップグレードしてみた。(簡易版)
今回も各ステップの細かい確認は行わないので、簡易版としました。
$ lsb_release -d
Description: Debian GNU/Linux 9.9 (stretch)
■本来は少なくとも以下や非公式ソースのパッケージ、古くなったパッケージの扱いを検討する必要があります。
第2章 Debian 10 の最新情報
https://www.debian.org/releases/buster/amd64/release-notes/ch-whats-new.ja.html
第5章 buster で注意すべき点
https://www.debian.org/releases/stable/amd64/release-notes/ch-information.ja.html
付録A アップグレードの前に stretch システムを調整する
https://www.debian.org/releases/buster/amd64/release-notes/ap-old-stuff.ja.html
■今回も以下の第4章を参考に進めます。
Debian 10 (buster) リリースノート (64 ビット PC 用)
https://www.debian.org/releases/stable/amd64/release-notes/
■debianが提供するパッケージではなさそうなものをリスト化する。
$ aptitude search '~i(!~ODebian)' > stretch_notdebian.log
$ wc -l stretch_notdebian.log
168 stretch_notdebian.log
■いざとなったら切り分けのためにアンインストール出来るようにしておく。
$ awk -F\- '{gsub("i|A| ","",$1);print $1 | "sort -uV"}' stretch_notdebian.log | head -7
alsa
aptdaemon
asl
automake1.10
chkconfg
clsp
cpp
■word変数で「proposed-updates」セクションを指定して検索
「/etc/apt/」配下のフルパスから、ファイル及びディレクトリの「source」文字列にマッチするファイルを検索する。
ファイルの中身のどこかに「proposed-updates」文字列があるファイルにマッチして、ファイル名とその行を表示。
ただし、ファイルの中身の行頭が「#」で始まる場合を除く。
$ awk -v word="proposed-updates" 'FILENAME ~ /source/&&$0 ~ word && $1 !~ /^#/ {print FILENAME,$0}' $(find /etc/apt/ -type f )
■上記が正しく動作することを確認するためにword変数を「main」に変えてみる。
これでおよそ非公式なソースが見つかる。
(findに「-name *.list」を渡さなかったのは、名前を変えているバックアップも含めて確認するため)
MSもdockerも「buster」はまだ無いようなので、メインで使用しているなら用意されるまで待った方が良いかも。
$ awk -v word="stretch.* main" 'FILENAME ~ /source/&&$0 ~ word && $1 !~ /^#/ {print FILENAME,$0}' $(find /etc/apt/ -type f )
/etc/apt/sources.list.d/docker.list deb https://apt.dockerproject.org/repo debian-stretch main
/etc/apt/sources.list.d/microsoft.list deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-debian-stretch-prod stretch main
/etc/apt/sources.list deb http://ftp.jp.debian.org/debian/ stretch main contrib non-free
/etc/apt/sources.list deb-src http://ftp.jp.debian.org/debian/ stretch main
/etc/apt/sources.list deb http://security.debian.org/ stretch/updates main
/etc/apt/sources.list deb-src http://security.debian.org/ stretch/updates main
/etc/apt/sources.list deb http://ftp.jp.debian.org/debian/ stretch-updates main
/etc/apt/sources.list deb-src http://ftp.jp.debian.org/debian/ stretch-updates main
■ubuntuやnon-freeのイレギュラーなソースも確認しておく。
$ awk -v word="non-free|ubuntu" 'FILENAME ~ /source/&&$0 ~ word && $1 !~ /^#/ {print FILENAME,$0}' $(find /etc/apt/ -type f )
/etc/apt/sources.list.d/gns3.list deb http://ppa.launchpad.net/gns3/ppa/ubuntu xenial main
/etc/apt/sources.list.d/gns3.list deb-src http://ppa.launchpad.net/gns3/ppa/ubuntu xenial main
/etc/apt/sources.list.jessie deb http://ftp.jp.debian.org/debian/ jessie main contrib non-free
/etc/apt/sources.list deb http://ftp.jp.debian.org/debian/ stretch main contrib non-free
■pin機能は使用していない。
$ echo /etc/apt/preferences*
/etc/apt/preferences.d
■パッケージの状態をチェック。hold状態のパッケージが無いこと。
$ dpkg --audit
$ aptitude search "~ahold"
$ dpkg --get-selections | grep 'hold$'
■結局のところ、メインのsource.listを変更すれば良い。
というか、そのためにファイルを分けるなどしてメンテしてきた。
どう見てもこのPCは2013/06/15のwheezyから、jessie、stretchと三世代使っている。
今回のbusterは四世代目だ。
$ grep ^# /etc/apt/sources.list
■一応、過去のアップグレード時の記録を辿ると、やはり、
「2013年にWheezyをインストールした記録は残しておくことにした」とあった。
WheezyからJessieにアップグレードしてみた。(簡易版)
http://labunix.hateblo.jp/entry/20150531/1433077890
jessie を stretch にアップグレードしてみた。(簡易版)
http://labunix.hateblo.jp/entry/20170717/1500228179
■バックアップを取得してソースファイルを書き換える。
$ sudo cp /etc/apt/sources.list{,.stretch}
$ sudo sed -i -e 's/stretch/buster/g' /etc/apt/sources.list
$ diff /etc/apt/sources.list{,.stretch}
7,8c7,8
< deb http://ftp.jp.debian.org/debian/ buster main contrib non-free
< deb-src http://ftp.jp.debian.org/debian/ buster main
---
> deb http://ftp.jp.debian.org/debian/ stretch main contrib non-free
> deb-src http://ftp.jp.debian.org/debian/ stretch main
10,11c10,11
< deb http://security.debian.org/ buster/updates main
< deb-src http://security.debian.org/ buster/updates main
---
> deb http://security.debian.org/ stretch/updates main
> deb-src http://security.debian.org/ stretch/updates main
13,15c13,15
<
< deb http://ftp.jp.debian.org/debian/ buster-updates main
< deb-src http://ftp.jp.debian.org/debian/ buster-updates main
---
>
> deb http://ftp.jp.debian.org/debian/ stretch-updates main
> deb-src http://ftp.jp.debian.org/debian/ stretch-updates main
■セクションの記録
$ script -t 2>~/upgrade-busterstep.time -a ~/upgrade-busterstep.script
Script started, file is /home/labunix/upgrade-busterstep.script
■パッケージリストの更新
$ sudo apt-get update
■空き容量の確認
$ df -h | grep var
/dev/sda4 191G 44G 138G 24% /var
■システムの最小アップグレード
アップグレードしても他のパッケージをインストール・削除する必要がないパッケージだけをアップグレードするので、
「-y」オプション付きで実行した。
設定変更の選択肢があればそこで止まることもあるのでご注意を。
$ sudo apt-get upgrade -y
■最小アップグレード後、残りどの位の更新がありそうかパッケージの影響を確認する。
$ apt list --upgradable | wc -l
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
1290
■最小アップグレード後、後で削除出来そうなパッケージを確認する。
$ dpkg -l | awk '$1 ~ /^rc/{print $2}' | wc -l
128
■それではメインディッシュのフルアップグレード。
$ sudo apt full-upgrade
■今回はすべてメンテナバージョンに書き換えたので、再設定が必要な箇所の洗い出し。
$ sudo find /etc/ -type f -name "*dpkg-old" -exec ls -l --time-style='+%Y%m%d-%H%M%S' {} \;
-rw-r--r-- 1 root root 14449 20190817-014552 /etc/ansible/ansible.cfg.dpkg-old
-rw-r--r-- 1 root root 2570 20140715-001957 /etc/locale.alias.dpkg-old
-rw-r--r-- 1 root root 1707 20140226-193911 /etc/ssh/ssh_config.dpkg-old
-rw-r--r-- 1 root root 10478 20180715-071438 /etc/ca-certificates.conf.dpkg-old
-rw-r--r-- 1 root root 2119 20190510-070850 /etc/ntp.conf.dpkg-old
-rw-r--r-- 1 root root 25297 20151113-020954 /etc/mime.types.dpkg-old
-rw-r--r-- 1 root root 2852 20171003-151956 /etc/rsyslog.conf.dpkg-old
-rw-r--r-- 1 root root 2081 20130829-212111 /etc/sysctl.conf.dpkg-old
$ sudo find /etc/ -type f -name "*dpkg-old" -exec ls -l --time-style='+%Y%m%d-%H%M%S' {} \; | \
awk '{gsub(".dpkg-old","{,&",$NF);print "echo \042["$NF"]\042;sdiff -s "$NF"}" | "sort -uV"}'
echo "[/etc/ansible/ansible.cfg{,.dpkg-old]";sdiff -s /etc/ansible/ansible.cfg{,.dpkg-old}
echo "[/etc/ca-certificates.conf{,.dpkg-old]";sdiff -s /etc/ca-certificates.conf{,.dpkg-old}
echo "[/etc/locale.alias{,.dpkg-old]";sdiff -s /etc/locale.alias{,.dpkg-old}
echo "[/etc/mime.types{,.dpkg-old]";sdiff -s /etc/mime.types{,.dpkg-old}
echo "[/etc/ntp.conf{,.dpkg-old]";sdiff -s /etc/ntp.conf{,.dpkg-old}
echo "[/etc/rsyslog.conf{,.dpkg-old]";sdiff -s /etc/rsyslog.conf{,.dpkg-old}
echo "[/etc/ssh/ssh_config{,.dpkg-old]";sdiff -s /etc/ssh/ssh_config{,.dpkg-old}
echo "[/etc/sysctl.conf{,.dpkg-old]";sdiff -s /etc/sysctl.conf{,.dpkg-old}
$ sudo find /etc/ -type f -name "*dpkg-old" -exec ls -l --time-style='+%Y%m%d-%H%M%S' {} \; | \
awk '{gsub(".dpkg-old","{,&",$NF);print "echo \042["$NF"]\042;sdiff -s "$NF"}" | "sort -uV"}' | bash
■変更箇所の自環境との差異を修正
$ sudo cp /etc/ntp.conf{,.bak-$(date '+%Y%m%d')}
$ sudo sed -i -e 's/^pool/#&/' /etc/ntp.conf
$ sudo sed -i -e 's/pool 3.*/&\nserver 172.31.31.66 iburst\nserver 172.31.31.92 iburst/' /etc/ntp.conf
$ echo 'disable monitor' | sudo tee -a /etc/ntp.conf
disable monitor
$ sudo systemctl restart ntp
$ sudo ntpq -pn
remote refid st t when poll reach delay offset jitter
==============================================================================
*172.31.31.66 172.31.31.60 3 u 10 64 1 0.296 -9.423 0.888
172.31.31.92 .INIT. 16 u - 64 0 0.000 0.000 0.000
$ sudo cp /etc/sysctl.conf{,.bak-$(date '+%Y%m%d')}
$ sudo sed -i -e 's/#\(net.ipv4.ip_forward=1\)/\1/' /etc/sysctl.conf
$ sudo sysctl -a | grep ^net.ipv4.ip_forward.=
net.ipv4.ip_forward = 1
■メタパッケージの確認
$ dpkg -l "linux-image*" | grep ^ii | grep -i meta
ii linux-image-amd64 4.19+105 amd64 Linux for 64-bit PCs (meta-package)
$ apt-cache search linux-image- | grep -i meta | grep -v transition
linux-image-686-dbg - Debugging symbols for Linux 686 configuration (meta-package)
linux-image-cloud-amd64 - Linux for x86-64 cloud (meta-package)
linux-image-cloud-amd64-dbg - Debugging symbols for Linux cloud-amd64 configuration (meta-package)
linux-image-rt-686-pae-dbg - Debugging symbols for Linux rt-686-pae configuration (meta-package)
linux-image-rt-amd64-dbg - Debugging symbols for Linux rt-amd64 configuration (meta-package)
-------------
■削除したパッケージを完全削除する。
必要になったらまた入れれば良いので。
$ dpkg -l | awk '/^rc/ {print $2}' | wc -l
136
$ dpkg -l | awk '/^rc/ {print $2}' | sudo apt-get purge -y `xargs`
$ dpkg -l | awk '/^rc/ {print $2}' | wc -l
0
■旧バージョンのパッケージを検索
dockerだけなので。
Get Docker Engine - Community for Debian
https://docs.docker.com/install/linux/docker-ce/debian/
$ dpkg -l | awk -F" *" '/^ii/&&/wheezy|jessie|stretch/&&!/stretching/{printf "%-22s %-22s %-6s %s\n",$2,$3,$4,$5}'
docker-engine 17.05.0~ce-0~debian-stretch amd64 Docker: the open-source application container engine
$ sudo sed -i -e 's/.*stretch.*/#&/' /etc/apt/sources.list.d/docker.list
$ echo "deb [arch=amd64] https://download.docker.com/linux/debian \
$(lsb_release -cs) \
stable" | sudo tee -a /etc/apt/sources.list.d/docker.list
deb [arch=amd64] https://download.docker.com/linux/debian buster stable
$ curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
OK
$ sudo apt-key fingerprint 0EBFCD88
pub rsa4096 2017-02-22 [SCEA]
9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
uid [ 不明 ] Docker Release (CE deb) <docker@docker.com>
sub rsa4096 2017-02-22 [S]
$ sudo apt-get update
$ sudo apt-get install -y docker-ce docker-ce-cli containerd.io
$ dpkg -l | awk -F" *" '/^ii/&&/wheezy|jessie|stretch/&&!/stretching/{printf "%-22s %-22s %-6s %s\n",$2,$3,$4,$5}'
■利用されなくなったパッケージの確認
$ sudo apt-get autoremove -y
$ sudo aptitude search '~o' | wc -l
356
■最初にやった確認をもう一度。
$ dpkg --audit
$ aptitude search '~i(!~ODebian)' > stretch_notdebian.log.buster
$ awk -F\- '{gsub("i|A| ","",$1);print $1 | "sort -uV"}' stretch_notdebian.log.buster | head -7
appdata
aptdaemon
asl
automake1.10
checknstall
chkconfg
contanerd.o
■移行用ダミーパッケージの確認と削除の検討
$ dpkg -l | awk '$1 ~ /^rc/{print $2}' | xargs sudo apt-get purge -y
$ dpkg -l | awk -F" *" '$1 ~ /^ii/&&/dummy/{printf "%-22s %-22s %-6s %s\n",$2,$3,$4,$5}'
appdata-tools 0.6.8-1 all Transitional dummy package (appdata-tools -> appstream-util)
bkhive 3.0.0-6 all transitional dummy package for samdump2
gnupg2 2.2.12-1 all GNU privacy guard - a free PGP replacement (dummy transitional package)
iasl 20140926-1 all transitional dummy package
iproute 1:4.9.0-1+deb9u1 all transitional dummy package for iproute2
jadetex 3.13-17 all transitional dummy package
libegl1-mesa:amd64 18.3.6-2 amd64 transitional dummy package
libgl1-mesa-glx:amd64 18.3.6-2 amd64 transitional dummy package
libkutils4 4:4.14.38-3 amd64 dummy transitional library
libwayland-egl1-mesa:amd64 18.3.6-2 amd64 transitional dummy package
ndiswrapper-utils-1.9 1.60-3 all Transitional dummy package upgrading to ndiswrapper
qemu 1:3.1+dfsg-8~deb10u1 amd64 fast processor emulator, dummy package
texlive-generic-extra 2018.20190227-2 all TeX Live: transitional dummy package
texlive-generic-recommended 2018.20190227-2 all TeX Live: transitional dummy package
texlive-htmlxml 2018.20190227-2 all TeX Live: transitional dummy package
transfig 1:3.2.6a-2+deb9u1 all transitional dummy package for fig2dev
x11proto-composite-dev 1:2018.4-4 all transitional dummy package
x11proto-core-dev 2018.4-4 all transitional dummy package
x11proto-damage-dev 1:2018.4-4 all transitional dummy package
x11proto-fixes-dev 1:2018.4-4 all transitional dummy package
x11proto-fonts-dev 2018.4-4 all transitional dummy package
x11proto-input-dev 2018.4-4 all transitional dummy package
x11proto-kb-dev 2018.4-4 all transitional dummy package
x11proto-randr-dev 2018.4-4 all transitional dummy package
x11proto-record-dev 2018.4-4 all transitional dummy package
x11proto-render-dev 2:2018.4-4 all transitional dummy package
x11proto-resource-dev 2018.4-4 all transitional dummy package
x11proto-scrnsaver-dev 2018.4-4 all transitional dummy package
x11proto-video-dev 2018.4-4 all transitional dummy package
x11proto-xext-dev 2018.4-4 all transitional dummy package
x11proto-xf86vidmode-dev 2018.4-4 all transitional dummy package
x11proto-xinerama-dev 2018.4-4 all transitional dummy package
■後片付けというかまずは整理。
$ sudo dpkg --configure -a
$ echo "update upgrade autoremove autoclean clean_all" |\
awk '{for(a=1;a<=NF;a++){gsub("_"," ",$a);print "apt-get -y "$a}}' | sudo sh
$ sudo apt-get dist-upgrade -y
$ echo "update upgrade autoremove autoclean clean_all" |\
awk '{for(a=1;a<=NF;a++){gsub("_"," ",$a);print "apt-get -y "$a}}' | sudo sh
■uim-anthyだったので、日本語入力環境が壊れた。
im-configによると、「日本語: ibus-mozc (最善) または ibus-anthy または ibus-skk」らしいので。
$ apt-cache search ibus-mozc
ibus-mozc - Mozc engine for IBus - Client of the Mozc input method
mozc-utils-gui - GUI utilities of the Mozc input method
$ sudo apt-get install -y ibus-mozc
$ sudo im-config
■不要な日本語環境の削除
$ dpkg -l | awk '/^ii/&&/uim|anthy/{print $2}' | xargs sudo apt-get purge -y
$ sudo rm -fr /etc/anthy/
$ echo "update upgrade autoremove autoclean clean_all" |\
awk '{for(a=1;a<=NF;a++){gsub("_"," ",$a);print "apt-get -y "$a}}' | sudo sh
■アップグレードログの確認と対処
これは各個別の環境によって異なるはずなので、詳細は割愛。
$ awk 'BEGIN{IGNORECASE=1}/err|エラー/' upgrade-busterstep.script | col
$ awk 'BEGIN{IGNORECASE=1}/warn|警告/' upgrade-busterstep.script | col
$ awk 'BEGIN{IGNORECASE=1}/crit|危険|致命/' upgrade-busterstep.script | col
$ awk 'BEGIN{IGNORECASE=1}/fail|失敗/&&!/fail2ban|failure/' upgrade-busterstep.script | col
■システムログの確認。
$ sudo dmesg | awk 'BEGIN{IGNORECASE=1}/crit|危険|致命/'
$ sudo dmesg | awk 'BEGIN{IGNORECASE=1}/error|エラー/'
[ 0.405962] acpi PNP0A08:00: _OSC failed (AE_ERROR); disabling ASPM
[ 3.390945] usb 1-1.1: string descriptor 0 read error: -22
[ 12.569858] EXT4-fs (sda3): re-mounted. Opts: errors=remount-ro
$ sudo dmesg | awk 'BEGIN{IGNORECASE=1}/fail|失敗/&&!/fail2ban|failure/'
[ 0.405962] acpi PNP0A08:00: _OSC failed (AE_ERROR); disabling ASPM
[ 13.747181] ndiswrapper: module verification failed: signature and/or required key missing - tainting kernel
$ sudo dmesg | awk 'BEGIN{IGNORECASE=1}/warn|警告/'
[ 2.422079] ACPI Warning: SystemIO range 0x0000000000000428-0x000000000000042F conflicts with OpRegion 0x0000000000000400-0x000000000000047F (\PMIO) (20180810/utaddress-213)
[ 2.422090] ACPI Warning: SystemIO range 0x0000000000000540-0x000000000000054F conflicts with OpRegion 0x0000000000000500-0x0000000000000563 (\GPIO) (20180810/utaddress-213)
[ 2.422095] ACPI Warning: SystemIO range 0x0000000000000530-0x000000000000053F conflicts with OpRegion 0x0000000000000500-0x0000000000000563 (\GPIO) (20180810/utaddress-213)
[ 2.422100] ACPI Warning: SystemIO range 0x0000000000000500-0x000000000000052F conflicts with OpRegion 0x0000000000000500-0x0000000000000563 (\GPIO) (20180810/utaddress-213)
■特に気になるものではないが、一応それぞれのログの前後も見ておく。
例えば以下のように。
$ uname -a
Linux vmx-rdebian 4.19.0-5-amd64
$ find /sys/bus/acpi/drivers/ /sys/bus/acpi/devices/ -name "PNP0A08:00"
/sys/bus/acpi/devices/PNP0A08:00
$ ls /sys/bus/acpi/devices/PNP0A08:00/
LNXVIDEO:00 PNP0C14:01 device:01 device:17 device:24 device:2b device:31 device:35 device:39 hid physical_node uevent
PNP0C02:01 adr device:02 device:21 device:26 device:2d device:33 device:36 device:3a modalias power uid
PNP0C14:00 device:00 device:0d device:22 device:29 device:2f device:34 device:38 device:3b path subsystem
■再起動後に自身の脆弱性を検査する準備
$ cd myscripts && \
ls penetration.sh || wget https://raw.githubusercontent.com/labunix/penetration/master/penetration.sh && \
chmod +x penetration.sh && cd ~ && \
dpkg -l | grep "^ii.*nmap" || sudo apt-get install -y nmap
penetration.sh
ii nmap 7.70+dfsg1-6 amd64 The Network Mapper
ii nmap-common 7.70+dfsg1-6 all Architecture independent files for nmap
■TCP/UDPのポートチェック
要否を含めて検討する。
$ ip a | awk '$1 ~ /inet/&&$2 ~ /^[1-9]/{gsub("/[0-9]*","",$2);print "sudo nmap -sT "$2}' | sh
$ ip a | awk '$1 ~ /inet/&&$2 ~ /^[1-9]/{gsub("/[0-9]*","",$2);print "sudo nmap -sU "$2}' | sh | grep ^[1-9]
■脆弱性検査の実行。のんびり待つ。
$ sed -i -e 's/P0/Pn/' myscripts/penetration.sh
$ ip a | awk '$1 ~ /inet/&&$2 ~ /^[1-9]/{gsub("/[0-9]*","",$2);print "sudo ./myscripts/penetration.sh "$2" > "$2"_nmap.log"}' | sh
■stretchではサポートされていなかったclispが復活しているとか、
残りは気づいたタイミングで対処していく方針で。