削除できない /etc/resolv.conf

削除できない /etc/resolv.conf

今日、12.04 へのアップグレード中に、resolvconfパッケージのインストール後フックを実行するとエラーが発生しました:

Setting up resolvconf (1.63ubuntu11) ...
resolvconf.postinst: Error: Cannot replace the current /etc/resolv.conf with a symbolic link because it is immutable. To correct this problem, gain root privileges in a terminal and run 'chattr -i /etc/resolv.conf' and then 'dpkg --configure resolvconf'. Aborting.

確かに、 を実行してみましたchattr -i /etc/resolv.confが、dpkg --configure resolvconf同じエラーが発生しました。

ファイルを手動で移動または削除しようとしましたが、root でも実行できません。

sudo mv /etc/resolv.conf /etc/resolv.conf.old 
mv: cannot move `/etc/resolv.conf' to `/etc/resolv.conf.old': Operation not permitted

sudo rm /etc/resolv.conf                                                       
rm: cannot remove `/etc/resolv.conf': Operation not permitted

/etc にファイルを作成して削除することはできます (root として)。そのため、ルート パーティションは読み取り専用でマウントされることはありません。また、次のようになります。

lsattr /etc/resolv.conf
-----a--------- /etc/resolv.conf

答え1

私の場合、ファイルの不変属性が原因です。sudo chattr -a -i /etc/resolv.conf

答え2

ヘルプファイル(man chattr)によると、

A  file  with the `a' attribute set can only be open in append mode for writing.

あなたの場合、ファイルにはこの属性があります

The  operator  `+'  causes  the  selected attributes to be added to the
       existing attributes of the files; `-' causes them to  be  removed;

試すべきコマンドは次のようになります

sudo chattr -a /etc/resolv.conf

そしてもう一度属性をリストしてみましょう

lsattr /etc/resolv.conf

次にファイルを削除してみてください

関連情報