R.A. Epigonos et al.

[linux] 異なるデバイスを跨いだ mv で inter-device move failed エラー

異なるデバイスを跨いだ mv でエラー発生して、inter-device move failed, unable to remove target: Is a director などといわれた。

通常のブロックデバイスと nfs の間で mv しようとおもったら下のようなエラーがでた。で、探していたら面白そうなページを見つけたのでチェックしておく。

inter-device move failed

英語のページだったから引用して適当に訳しておく。適当なので、あんまり正確じゃない。なんか抜けている気がする。

Linux: Cannot move folders – inter-device move failed, unable to remove target: Is a directory

Linux: フォルダの移動が出来ない。 - デバイス間移動に失敗しました。ターゲットを削除できません。: ディレクトリ?

This is somewhat simple as long as we understand the concept. mv or move does not actually move the file/folder to another location, it rather replaces the pointer in the first sector of your device. The pointer (in inode table) will be moved, but nothing is actually being copied. This will work as long as you stay within the same media/device.

このエラーを理解するには、mv コマンドのコンセプトを知らねばならない。mv や move コマンドはファイルやフォルダの実体を移動するわけではない。これらのコマンドは、デバイスの最初のセクタにあるポインタを移動する (あるデータの inode 番号を変えずにパスが示す先を変化させる) だけなのである。ポインタとは、inode テーブル (ある inode をもつファイルがどのパスにあるかの対応表) のことで、これが移動されるだけで実体がコピーされるわけではない。各デバイスは独立に inode テーブルを持っているので、mv や move コマンドは同じデバイス内での移動に限り上手く動作する。

Now, when you try to move files from one device to another (/dev/sda1 to /dev/sda2) you will run into "inter-device move failed, unable to remove target: Is a directory" error. This happens when mv has to actually move your data to another device, but cannot remove the inode/pointer, because if it did then there will be no data to fall back to, and if it didn't then mv operation is not really complete because we will end up with data in source. Damned if you do and damned if you don’t, so it’s wise not to do it to begin with!

さて、あるデバイスから別のデバイス (/dev/sda1 から /dev/sda2) にファイルを移動することを考えよう。このとき、"inter-device move failed, unable to remove target: Is a directory" というエラーがでる。これは、mv コマンドがデバイスを跨いでデータを移動した後に、inode (ポインタ) を削除できない時に出るエラーだ。なぜなら、inode テーブルから移動したいデータの inode とパスの対応を削除できた場合、パスを元にデータを参照出来なくなるからだ。inode テーブルから移動したいデータの inode とパスの対応を削除できなかった場合、移動元には参照可能なデータがのこっているので、mv コマンドは正しく完了しなかったことになる。

In such situation cp is best. Copy your data over and then remove your source manually.

このように、異なるデバイス間の移動においてはcpを使うのが最善である。必要なデータを全てコピーした後に、移動元のデータを削除すればいいのだ。

リファレンス

  1. Linux: Cannot move folders – inter-device move failed, unable to remove target: Is a directory | Ali Aboosaidi
  2. inter-device move failed - Google 検索

ソーシャルブックマーク

  1. はてなブックマーク
  2. Google Bookmarks
  3. del.icio.us

ChangeLog

  1. Posted: 2009-05-31T11:33:23+09:00
  2. Modified: 2009-05-31T11:33:23+09:00
  3. Generated: 2023-08-27T23:09:10+09:00