はじめに
半年ほど運用していたRaspbianで、久しぶりにメンテのためapt upgrade
したら、エラーが出てupgrade
出来なくなりました。
pi@raspibp:~ $ sudo apt upgrade -y Reading package lists... Done Building dependency tree Reading state information... Done Calculating upgrade... Done The following packages will be upgraded: tzdata 1 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. Need to get 0 B/273 kB of archives. After this operation, 2048 B of additional disk space will be used. apt-listchanges: Reading changelogs... Preconfiguring packages ... dpkg: warning: files list file for package 'openssh-sftp-server' missing; assuming package has no files currently installed dpkg: unrecoverable fatal error, aborting: files list file for package 'iputils-ping' is missing final newline E: Sub-process /usr/bin/dpkg returned an error code (2)
きちんとupgrade
出来るように処置した手順をまとめました。
進め方
こちら1のサイトを参考にしました。 基本的には、エラーの対象になっているパッケージの再インストールを行います。
#エラーのファイルを一旦別名で退避 pi@raspibp:/var/lib/dpkg/info $ sudo mv iputils-ping.* /var/lib/dpkg/info/old #iputils-pingの再インストール pi@raspibp:/var/lib/dpkg/info $ sudo apt-get install iputils-ping --reinstall Reading package lists... Done Building dependency tree Reading state information... Done 0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 1 not upgraded. Need to get 0 B/54.1 kB of archives. After this operation, 0 B of additional disk space will be used. dpkg: warning: files list file for package 'iputils-ping' missing; assuming package has no files currently installed dpkg: warning: files list file for package 'openssh-sftp-server' missing; assuming package has no files currently installed dpkg: unrecoverable fatal error, aborting: files list file for package 'iptables' is missing final newline E: Sub-process /usr/bin/dpkg returned an error code (2)
今度はiptablesがエラーを出してますね。
#エラーのファイルを一旦別名で退避 pi@raspibp:/var/lib/dpkg/info $ sudo mv iptables.* /var/lib/dpkg/info/old #もう一度、iputils-pingの再インストール pi@raspibp:/var/lib/dpkg/info $ sudo apt-get install iputils-ping --reinstall Reading package lists... Done Building dependency tree Reading state information... Done 0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 1 not upgraded. Need to get 0 B/54.1 kB of archives. After this operation, 0 B of additional disk space will be used. dpkg: warning: files list file for package 'iputils-ping' missing; assuming package has no files currently installed dpkg: warning: files list file for package 'openssh-sftp-server' missing; assuming package has no files currently installed dpkg: unrecoverable fatal error, aborting: files list file for package 'iptables' is missing final newline E: Sub-process /usr/bin/dpkg returned an error code (2)
エラーが出てきた順番に、次のiptablesを再インストール
pi@raspibp:/var/lib/dpkg/info $ sudo apt-get install iptables --reinstall Reading package lists... Done Building dependency tree Reading state information... Done 0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 1 not upgraded. Need to get 259 kB of archives. After this operation, 0 B of additional disk space will be used. Get:1 http://ftp.jaist.ac.jp/raspbian stretch/main armhf iptables armhf 1.6.0+snapshot20161117-6 [259 kB] Fetched 259 kB in 0s (878 kB/s) dpkg: warning: files list file for package 'openssh-sftp-server' missing; assuming package has no files currently installed dpkg: warning: files list file for package 'iptables' missing; assuming package has no files currently installed (Reading database ... 38388 files and directories currently installed.) Preparing to unpack .../iptables_1.6.0+snapshot20161117-6_armhf.deb ... Unpacking iptables (1.6.0+snapshot20161117-6) over (1.6.0+snapshot20161117-6) ... Setting up iptables (1.6.0+snapshot20161117-6) ... Processing triggers for man-db (2.7.6.1-2) ...
エラーが出てきた順番に、最後のopenssh-sftp-serverを再インストール
pi@raspibp:/var/lib/dpkg/info $ sudo apt-get install openssh-sftp-server --reinstall Reading package lists... Done Building dependency tree Reading state information... Done 0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 1 not upgraded. Need to get 0 B/32.9 kB of archives. After this operation, 0 B of additional disk space will be used. dpkg: warning: files list file for package 'openssh-sftp-server' missing; assuming package has no files currently installed (Reading database ... 38529 files and directories currently installed.) Preparing to unpack .../openssh-sftp-server_1%3a7.4p1-10+deb9u6_armhf.deb ... Unpacking openssh-sftp-server (1:7.4p1-10+deb9u6) over (1:7.4p1-10+deb9u6) ... Setting up openssh-sftp-server (1:7.4p1-10+deb9u6) ... Processing triggers for man-db (2.7.6.1-2) ... pi@raspibp:/var/lib/dpkg/info $
これでapt upgrade
が出来るようになりました。
swapの無効化
ファイルが壊れてしまった原因は分かりませんが、SDカードの書き込み頻度が多いので、その影響で壊れてしまったかな・・・
今後swapの無効化を容易にする為に、簡単なスクリプトを作ってみました。2
#!/bin/bash #-------------------------------------------------------------------- # swapの無効化 #-------------------------------------------------------------------- echo "Stopping and disable swap daemon..." sudo systemctl stop dphys-swapfile.service sudo systemctl disable dphys-swapfile.service echo "Removing swap file..." sudo rm /var/swap echo "done."
おわりに
対処療法的にはなってしましたが、ご参考頂けると幸いです。