2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Ubuntu で USB メモリ上の削除ファイルを復旧する

Posted at

復元したいもの

間違って削除した Excel ファイル。
Photorec は 画像ファイルや ZIP ファイルが復元できます。
Excel ファイルも ZIP ファイルの亜種となるので復元できそうです。

環境

  • Ubuntu 22.04
  • USBメモリ I-O DATA 8GBytes FATフォーマット
  • USBメモリ自体は正常に動作しています。

ツールのインストール

photorec を使います

$ sudo apt install testdisk

リカバリーファイルの保管場所

フォルダーを作成し、そこに復旧ファイルを格納するようにします。

$ mkdir recoverusb

USBメモリをデバイスとして認識

dmesg を起動しておいて

$ sudo dmesg -w

USBメモリを挿入します。

.
.
.
[26716.676250] usb 1-1.2: new high-speed USB device number 6 using ehci-pci
[26716.787314] usb 1-1.2: New USB device found, idVendor=04bb, idProduct=101a, bcdDevice=11.00
[26716.787331] usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[26716.787336] usb 1-1.2: Product: USB Flash Disk
[26716.787339] usb 1-1.2: Manufacturer: I-O DATA
[26716.787342] usb 1-1.2: SerialNumber: 2960412190170011
[26716.826238] usb-storage 1-1.2:1.0: USB Mass Storage device detected
[26716.826438] scsi host6: usb-storage 1-1.2:1.0
[26716.826598] usbcore: registered new interface driver usb-storage
[26716.830448] usbcore: registered new interface driver uas
[26718.448480] scsi 6:0:0:0: Direct-Access     I-O DATA USB Flash Disk   1100 PQ: 0 ANSI: 4
[26718.449445] sd 6:0:0:0: Attached scsi generic sg1 type 0
[26718.451265] sd 6:0:0:0: [sdb] 15155200 512-byte logical blocks: (7.76 GB/7.23 GiB)
[26718.453781] sd 6:0:0:0: [sdb] Write Protect is off
[26718.453789] sd 6:0:0:0: [sdb] Mode Sense: 43 00 00 00
[26718.454741] sd 6:0:0:0: [sdb] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[26718.467499]  sdb: sdb1
[26718.467687] sd 6:0:0:0: [sdb] Attached SCSI removable disk
.
.
.

/dev/sdb として正常に認識できていることがわかります。

論理フォーマットを確認

fdisk でパーティーション情報を確認します。

$ sudo fdisk /dev/sdb
fdisk (util-linux 2.37.2) へようこそ。
ここで設定した内容は、書き込みコマンドを実行するまでメモリのみに保持されます。
書き込みコマンドを使用する際は、注意して実行してください。

This disk is currently in use - repartitioning is probably a bad idea.
It's recommended to umount all file systems, and swapoff all swap
partitions on this disk.

パーティションおよびフォーマットを確認します。

コマンド (m でヘルプ): p

ディスク /dev/sdb: 7.23 GiB, 7759462400 バイト, 15155200 セクタ
Disk model: USB Flash Disk  
単位: セクタ (1 * 512 = 512 バイト)
セクタサイズ (論理 / 物理): 512 バイト / 512 バイト
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
ディスクラベルのタイプ: dos
ディスク識別子: 0xc3072e18

デバイス   起動 開始位置 最後から   セクタ サイズ Id タイプ
/dev/sdb1            248 15155199 15154952   7.2G  b W95 FAT32

コマンド (m でヘルプ): q

photorec を起動する

先程確認した /dev/sdb1 を指定して起動します。

$ sudo photorec /dev/sdb1

とすると、以下のように表示されます。

PhotoRec 7.1, Data Recovery Utility, July 2019
Christophe GRENIER <grenier@cgsecurity.org>
https://www.cgsecurity.org

  PhotoRec is free software, and
comes with ABSOLUTELY NO WARRANTY.

Select a media (use Arrow keys, then press Enter):
>Disk /dev/sdb1 - 7759 MB / 7399 MiB (RO) - I-O DATA USB Flash Disk



>[Proceed ]  [  Quit  ]

Note:
Disk capacity must be correctly detected for a successful recovery.
If a disk listed above has an incorrect size, check HD jumper settings and BIOS
detection, and install the latest OS patches and disk drivers.

正しく USB メモリが指定されているので Proceed を選び、次に表示される


   P FAT32                    0   0  1  1022 176 44   15154952 [NO NAME]

をサーチします。

>[ Search ] 

今回は削除ファイルを探すのが目的なので、Free を選びます。

>[   Free    ] Scan for file from FAT32 unallocated space only

復元先を先ほど作成した recoverusb を指定します。

>drwxrwxr-x  1000  1000      4096 10-Oct-2023 16:10 recoverusb

復元

しばらく時間がかかり、以下のように復元していきます。

Pass 1 - Reading sector    9198424/15154952, 2343 files found
Elapsed time 0h05m24s - Estimated time to completion 0h03m29
zip: 1171 recovered
jpg: 552 recovered
doc: 319 recovered
pdf: 299 recovered
png: 2 recovered

終了すると、recoverusb 内に以下のようにフォルダができていて、復元されたファイルが入っています。

~/recoverusb$ ls
recup_dir.1  recup_dir.2  recup_dir.3  recup_dir.4  recup_dir.5

Excel ファイルとして復元されたものについては、Excel の拡張子はついてますがファイル名は復元できず数字などのファイル名になっています。中身を見て必要なファイルかどうか確認します。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?