/ varコンテンツが削除または破損したRaspbianの適切な問題

/ varコンテンツが削除または破損したRaspbianの適切な問題

どうやら本番サーバーに問題があり、誰かが/varこのフォルダの内容を削除したようです。

これにより、さまざまなサービスをWebサーバーとして使用する際にいくつかのエラーが発生しました。

私が経験している問題aptは、パッケージを更新、削除、またはインストールできないことです。

たとえば、データベースサーバーを再インストールしたいが、mariadb-serverパッケージがシステムにインストールされていないというメッセージが表示されます(間違っています。自分でインストールしました)。

root# apt remove mariadb-server
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package 'mariadb-server' is not installed, so not removed
You might want to run 'apt-get -f install' to correct these:
The following packages have unmet dependencies:
 chkconfig : Depends: perl but it is not going to be installed
             Recommends: insserv but it is not going to be installed
 libboost-chrono1.50.0 : Depends: libgcc1 (>= 1:4.4.0) but it is not going to be installed
                         Depends: libstdc++6 (>= 4.4.0) but it is not going to be installed
 libboost-system1.50.0 : Depends: libgcc1 (>= 1:4.4.0) but it is not going to be installed
                         Depends: libstdc++6 (>= 4.4.0) but it is not going to be installed
 libboost-thread1.50.0 : Depends: libgcc1 (>= 1:4.4.0) but it is not going to be installed
                         Depends: libstdc++6 (>= 4.6) but it is not going to be installed
 libc6 : Depends: libgcc1 but it is not going to be installed
 libprotobuf-lite7 : Depends: libgcc1 (>= 1:4.4.0) but it is not going to be installed
                     Depends: libstdc++6 (>= 4.4.0) but it is not going to be installed
                     Depends: zlib1g (>= 1:1.1.4) but it is not going to be installed
 oracle-java8-jdk : Depends: libasound2 (>= 1.0.16)
                    Depends: libgcc1 (>= 1:4.4.0) but it is not going to be installed
                    Depends: libx11-6 but it is not going to be installed
                    Depends: libxext6 but it is not going to be installed
                    Depends: libxi6 but it is not going to be installed
                    Depends: libxrender1 but it is not going to be installed
                    Depends: libxtst6 but it is not going to be installed
                    Recommends: netbase but it is not going to be installed
 redis-server : Depends: init-system-helpers (>= 1.18~) but it is not going to be installed
                Depends: libjemalloc1 (>= 2.1.1) but it is not going to be installed
                Depends: adduser but it is not going to be installed
 redis-tools : Depends: libjemalloc1 (>= 2.1.1) but it is not going to be installed
 watchdog : Depends: debconf (>= 0.5) but it is not going to be installed or
                     debconf-2.0
            Depends: init-system-helpers (>= 1.18~) but it is not going to be installed
            Depends: makedev (>= 2.3.1-24) but it is not going to be installed or
                     udev but it is not going to be installed
            Depends: lsb-base (>= 3.2-14) but it is not going to be installed
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).

満たされていない依存関係を解決するようにコマンドを実行する場合:

root# apt-get -f install
Reading package lists... Done
Building dependency tree
Reading state information... Done
Correcting dependencies... Done
The following extra packages will be installed:
  adduser apt apt-utils base-passwd ca-certificates coreutils debconf debconf-i18n debianutils dpkg e2fslibs e2fsprogs gnupg gnupg-curl gpgv ifupdown init-system-helpers initscripts insserv iproute2 isc-dhcp-client isc-dhcp-common
  krb5-locales libacl1 libalgorithm-c3-perl libapt-inst1.5 libapt-pkg4.12 libarchive-extract-perl libasound2 libasound2-data libatm1 libattr1 libaudit-common libaudit1 libblkid1 libbz2-1.0 libcgi-fast-perl libcgi-pm-perl
  libclass-c3-perl libclass-c3-xs-perl libcomerr2 libcpan-meta-perl libcurl3-gnutls libdata-optlist-perl libdata-section-perl libdb5.3 libdebconfclient0 libdns-export100 libfcgi-perl libffi6 libgcc1 libgcrypt20 libgdbm3 libgmp10
  libgnutls-deb0-28 libgpg-error0 libgpm2 libgssapi-krb5-2 libhogweed2 libidn11 libirs-export91 libisc-export95 libisccfg-export90 libjemalloc1 libk5crypto3 libkeyutils1 libkrb5-3 libkrb5support0 libldap-2.4-2 liblocale-gettext-perl
  liblog-message-perl liblog-message-simple-perl liblzma5 libmodule-build-perl libmodule-pluggable-perl libmodule-signature-perl libmount1 libmro-compat-perl libncurses5 libnettle4 libp11-kit0 libpackage-constants-perl libpam-modules
  libpam-modules-bin libpam0g libparams-util-perl libpcre3 libpng12-0 libpod-latex-perl libpod-readme-perl libreadline6 libregexp-common-perl librtmp1 libsasl2-2 libsasl2-modules libsasl2-modules-db libselinux1 libsemanage-common
  libsemanage1 libsepol1 libslang2 libsmartcols1 libsoftware-license-perl libss2 libssh2-1 libssl1.0.0 libstdc++6 libsub-exporter-perl libsub-install-perl libsystemd0 libtasn1-6 libterm-ui-perl libtext-charwidth-perl libtext-iconv-perl
  libtext-soundex-perl libtext-template-perl libtext-wrapi18n-perl libtinfo5 libusb-0.1-4 libustr-1.0-1 libuuid1 libx11-6 libx11-data libxau6 libxcb1 libxdmcp6 libxext6 libxi6 libxrender1 libxtables10 libxtst6 lsb-base makedev netbase
  openssl passwd perl perl-base perl-modules psmisc raspbian-archive-keyring readline-common redis-server redis-tools rename sensible-utils startpar sysv-rc sysvinit-utils tar tzdata util-linux uuid-runtime x11-common zlib1g
Suggested packages:
  aptitude synaptic wajig dpkg-dev apt-doc python-apt debconf-doc debconf-utils whiptail dialog gnome-utils libterm-readline-gnu-perl libgtk2-perl libnet-ldap-perl libqtgui4-perl libqtcore4-perl gpart parted fuse2fs e2fsck-static
  gnupg-doc libpcsclite1 parcimonie xloadimage imagemagick eog ppp rdnssd net-tools bootchart2 iproute2-doc resolvconf avahi-autoipd libasound2-plugins alsa-utils rng-tools gnutls-bin gpm krb5-doc krb5-user libpam-doc
  libsasl2-modules-otp libsasl2-modules-ldap libsasl2-modules-sql libsasl2-modules-gssapi-mit libsasl2-modules-gssapi-heimdal perl-doc make libb-lint-perl libcpanplus-dist-build-perl libcpanplus-perl libfile-checktree-perl
  libobject-accessor-perl readline-doc bum bootlogd sash bzip2 ncompress xz-utils tar-scripts dosfstools kbd console-tools util-linux-locales
Recommended packages:
  libarchive-tar-perl
The following NEW packages will be installed:
  adduser apt apt-utils base-passwd ca-certificates coreutils debconf debconf-i18n debianutils dpkg e2fslibs e2fsprogs gnupg gnupg-curl gpgv ifupdown init-system-helpers initscripts insserv iproute2 isc-dhcp-client isc-dhcp-common
  krb5-locales libacl1 libalgorithm-c3-perl libapt-inst1.5 libapt-pkg4.12 libarchive-extract-perl libasound2 libasound2-data libatm1 libattr1 libaudit-common libaudit1 libblkid1 libbz2-1.0 libcgi-fast-perl libcgi-pm-perl
  libclass-c3-perl libclass-c3-xs-perl libcomerr2 libcpan-meta-perl libcurl3-gnutls libdata-optlist-perl libdata-section-perl libdb5.3 libdebconfclient0 libdns-export100 libfcgi-perl libffi6 libgcc1 libgcrypt20 libgdbm3 libgmp10
  libgnutls-deb0-28 libgpg-error0 libgpm2 libgssapi-krb5-2 libhogweed2 libidn11 libirs-export91 libisc-export95 libisccfg-export90 libjemalloc1 libk5crypto3 libkeyutils1 libkrb5-3 libkrb5support0 libldap-2.4-2 liblocale-gettext-perl
  liblog-message-perl liblog-message-simple-perl liblzma5 libmodule-build-perl libmodule-pluggable-perl libmodule-signature-perl libmount1 libmro-compat-perl libncurses5 libnettle4 libp11-kit0 libpackage-constants-perl libpam-modules
  libpam-modules-bin libpam0g libparams-util-perl libpcre3 libpng12-0 libpod-latex-perl libpod-readme-perl libreadline6 libregexp-common-perl librtmp1 libsasl2-2 libsasl2-modules libsasl2-modules-db libselinux1 libsemanage-common
  libsemanage1 libsepol1 libslang2 libsmartcols1 libsoftware-license-perl libss2 libssh2-1 libssl1.0.0 libstdc++6 libsub-exporter-perl libsub-install-perl libsystemd0 libtasn1-6 libterm-ui-perl libtext-charwidth-perl libtext-iconv-perl
  libtext-soundex-perl libtext-template-perl libtext-wrapi18n-perl libtinfo5 libusb-0.1-4 libustr-1.0-1 libuuid1 libx11-6 libx11-data libxau6 libxcb1 libxdmcp6 libxext6 libxi6 libxrender1 libxtables10 libxtst6 lsb-base makedev netbase
  openssl passwd perl perl-base perl-modules psmisc raspbian-archive-keyring readline-common rename sensible-utils startpar sysv-rc sysvinit-utils tar tzdata util-linux uuid-runtime x11-common zlib1g
The following packages will be upgraded:
  redis-server redis-tools
2 upgraded, 153 newly installed, 0 to remove and 3 not upgraded.
11 not fully installed or removed.
Need to get 37.1 MB of archives.
After this operation, 120 MB of additional disk space will be used.
Do you want to continue? [Y/n]
Get:1 http://archive.raspberrypi.org/debian/ jessie/main libasound2-data all 1.0.28-1+rpi3 [65.3 kB]
Get:2 http://archive.raspberrypi.org/debian/ jessie/main libasound2 armhf 1.0.28-1+rpi3 [320 kB]
Get:3 http://mirrordirector.raspbian.org/raspbian/ jessie/main libgcc1 armhf 1:4.9.2-10+deb8u2 [39.5 kB]
Get:4 http://archive.raspberrypi.org/debian/ jessie/main x11-common all 1:7.7+16 [251 kB]
[...]
Get:152 http://mirrordirector.raspbian.org/raspbian/ jessie/main libterm-ui-perl all 0.42-1 [19.1 kB]
Get:153 http://mirrordirector.raspbian.org/raspbian/ jessie/main libtext-soundex-perl armhf 3.4-1+b2 [13.3 kB]
Get:154 http://mirrordirector.raspbian.org/raspbian/ jessie/main psmisc armhf 22.21-2 [117 kB]
Get:155 http://mirrordirector.raspbian.org/raspbian/ jessie/main rename all 0.20-3 [12.4 kB]
Fetched 37.1 MB in 2min 29s (249 kB/s)
Reading changelogs... Done
E: Cannot get debconf version. Is debconf installed?
debconf: apt-extracttemplates failed: No such file or directory
Extracting templates from packages: 19%E: Cannot get debconf version. Is debconf installed?
debconf: apt-extracttemplates failed: No such file or directory
Extracting templates from packages: 38%E: Cannot get debconf version. Is debconf installed?
debconf: apt-extracttemplates failed: No such file or directory
Extracting templates from packages: 58%E: Cannot get debconf version. Is debconf installed?
debconf: apt-extracttemplates failed: No such file or directory
Extracting templates from packages: 77%E: Cannot get debconf version. Is debconf installed?
debconf: apt-extracttemplates failed: No such file or directory
Extracting templates from packages: 96%E: Cannot get debconf version. Is debconf installed?
debconf: apt-extracttemplates failed: No such file or directory
Extracting templates from packages: 100%
dpkg: regarding .../libgcc1_1%3a4.9.2-10+deb8u2_armhf.deb containing libgcc1:armhf, pre-dependency problem:
 libgcc1 pre-depends on multiarch-support
  multiarch-support is unpacked, but has never been configured.

dpkg: error processing archive /var/cache/apt/archives/libgcc1_1%3a4.9.2-10+deb8u2_armhf.deb (--unpack):
 pre-dependency problem - not installing libgcc1:armhf
Errors were encountered while processing:
 /var/cache/apt/archives/libgcc1_1%3a4.9.2-10+deb8u2_armhf.deb

E: Sub-process /usr/bin/dpkg returned an error code (1)

以下はmariadb-serverがインストールされているという証拠です(エラーは/ varを削除したために発生するので、再インストールしたいと思います)。

root# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111 "Connection refused")

ご覧のとおり、両方ともディレクトリにコンテンツがありませんというエラーがapt発生します。それで、ループに閉じ込められていて、この問題を解決し続ける方法がわかりません。mariadb-server/var

ベストアンサー1

以下を参考にします記事そしてDebian Wiki 投稿私の答えのために。

まず、動作しているRaspbianシステムに環境を作成しますdebootstrap。次のガイドラインに従ってください。Debian Wikiあなたがしなければならないことは、次のことを完了することだけです。

mkdir /debootstrap
debootstrap stable /debootstrap http://deb.debian.org/debian/

私はRaspbianを使用しているので、正しいgpg-keyを追加する必要があるかもしれません。ここで指摘したように、Raspbian Deb Mirrorを参照してください。このような: http://archive.raspbian.org/raspbian。含めますリンククロスプラットフォームビルドガイドは、Raspberry Piではなくamd64システムでこれを行うことを示しています。

重要:メッセージが表示されたらgrubMBRにインストールしないでください。これにより、既存のインストールが中断される可能性があります。

次に、破損したシステムにインストールされているすべてのプログラムのリストを取得します。最初は使用を提案しましたが、dpkg --get-selectionsユーザーABが指摘したように、これは失敗します。dpkgさまざまな/varディレクトリへの参照が機能します。/var一つを失うと当然失敗します。ユーザーABは、引用可能な内容/usr/share/doc/と関連するシンボリックリンクを指摘しました。まず、利用可能なものを確認し、結果installed.txtに基づいて1つを作成します。

cd /usr/share/doc && for i in *; do echo $i install >> /home/user/installed.txt; done

その結果をinstalled.txtあなたの期待と比較しなさい。確認するもう一つの場所はです/usr/share/man。このディレクトリにはマンページが含まれていますが、マンページをインストールするパッケージにのみ適用されます。比較可能な動作中のRaspberry Piがある場合、故障したラズベリーパイと構成が同じです。installed.txtRaspberry Piの出力を使用してビルドできますdpkg --get-selections

installed.txt失われたホストから/var回復した/varホストにコピーします。scpまたは、rysncここでは機能しますが、この時点では、ssh破損したホストと回復を実行するホストの間に動作する構成があることを確認する必要があります。 2つのホスト間に有効な設定がないとssh複製できません。/var続行する前にssh問題を解決する必要があります。

これで、このファイルを/deboostrap環境に移動し、このchroot内に同じソフトウェアをすべてインストールする準備が整いました。

cp installed.txt /debootstrap/
chroot /bootstrap/
mount -t proc none /proc
dpkg --set-selections < installed.txt

sources.list必要に応じて一致することを確認してください。debootstrap基本的にはmain

apt update
apt install dselect
dselect update
apt-get dselect-upgrade

良い建物を作れないならinstalled.txt

debootstrapchrootに必要なすべてのパッケージを手動でインストールする必要があるかもしれません。ここが良い設定文書やコードとしてのインフラが便利なところです。可能な限り元のバージョンに近づけるには、apt install package1 package2 package3 ... packageNchrootで実行してください。インストールする代わりに、次の手順に従う必要があります。/var/vardselect

chroot /bootstrap/
mount -t proc none /proc
apt update
apt install package1 package2 package3 ... packageN

この時点で、あなたのdebootstrap環境は、破損したターゲットホストの環境と一致する必要があります。ここでrsyncコピーする必要/varがあります。rsync -Aそれだけで十分です。私が指摘したように協会PermitRootLogin without-password、が動作することを許可する必要がsshd_configあるかもしれませんrsync

また、Alephnull.ukのPete Donnellが実行すべき最終ステップと考慮事項を直接引用します。

mariadb-server...壊れたサーバーにパッケージを再インストールする必要がありましたapt-get install --reinstall mariadb-server mariadb-server-10.1 mariadb-server-core-10.1

次のステップは、ユーザーデータを回復することです。これは使用する構造によって異なり、指示を提供することはできません。これを完了したら、ワーカーサーバー(またはブートストラップ)のファイルに対する権限を確認して、ファイルが正しいことを確認してください/var/lib/var/logシステムアカウントのユーザーIDは、サーバーとブート環境の間で異なる可能性があります。

これで、インストールしたさまざまなサービスを確認する必要がありますservice --status-all。すべてのサービスを有効にする必要はありません。もう一度稼働しているサーバーと比較することをお勧めします。現在実行されていないが実行する必要があるサービスを再起動してみてください。すべての権限が正しく、関連するユーザーデータ(存在する場合)が復元された場合、サービスは正常に開始されます。そうでない場合は、sでsystemdの状態を確認し、systemctl status <service-name>でsystemdのログを確認し、journalctl -xesでサービスのログファイルを確認してください/var/log。これにより、残りの問題を追跡するのに十分な情報を得ることができます。

debootstrap幸運なことに、2番目の作業ホストがある場合は、時間をかけて環境と破損したホストを比較することをお勧めします。すべての権限が正しいこと、サービスが正しく実行されていることを確認する必要があります。これが完了したら、コンソールを再起動し、すべてが復元されたことを確認します。

コマンドを試す前に、私が提供する各リンクを注意深く読んでください。私の記事に誤りや誤解、問題がある場合は、お知らせください。修正するよう努めます。

頑張ってください!

おすすめ記事