12 November 2007

HDDの消失したパーティションをtestdiskで復旧

ハードディスクのパーティション操作をPartition Magic 7を用いて行ったときに、「パーティションテーブルの定義でLBAとCHSの設定値が異なっているために、自動修正しますか」という質問に「YES」と答えたために、13個あったパーティションのうち2つを除いてすべて消去されてしまった。

まず、Knoppixでブートしてfdiskで現在の状況を見てみる。


root@Knoppix:/ramdisk/home/knoppix# fdisk /dev/sda

このディスクのシリンダ数は 30401 に設定されています。
間違いではないのですが、1024 を超えているため、以下の場合
に問題を生じうる事を確認しましょう:
1) ブート時に実行するソフトウェア (例. バージョンが古い LILO)
2) 別の OS のブートやパーティション作成ソフト
(例. DOS FDISK, OS/2 FDISK)

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

Disk /dev/sda: 250.0 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders
Units = シリンダ数 of 16065 * 512 = 8225280 bytes

デバイス Boot Start End Blocks Id System
/dev/sda1 * 1 255 2048256 b W95 FAT32
/dev/sda2 256 30342 241673827+ f W95 Ext'd (LBA)
/dev/sda5 2425 3699 10241406 c W95 FAT32 (LBA)

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

FAT32, NTFS, Ext3 複数ののパーティションが削除されてしまっている。

testdisk を起動しようとするとエラーになるので、回避措置をとる


knoppix@Knoppix:~$ su
root@Knoppix:/ramdisk/home/knoppix# testdisk
testdisk: error while loading shared libraries: libntfs.so.9: cannot open shared object file: No such file or directory
root@Knoppix:/ramdisk/home/knoppix# ls /usr/lib/libntfs.so.*
/usr/lib/libntfs.so.10 /usr/lib/libntfs.so.10.0.0
root@Knoppix:/ramdisk/home/knoppix# cp /usr/lib/libntfs.so.10.0.0 /usr/lib/libntfs.so.9

testdiskを起動すると、さらにエラー


TestDisk 6.5, Data Recovery Utility, October 2006
Christophe GRENIER <grenier@cgsecurity.org>
http://www.cgsecurity.org

TestDisk need 25 lines to work.
Please enlarge the terminal.

シェルのウィンドウを少し縦に引きのばして、25行以上表示できるようにすると起動する。


TestDisk 6.5, Data Recovery Utility, October 2006
Christophe GRENIER <grenier@cgsecurity.org>
http://www.cgsecurity.org


TestDisk is a data recovery designed to help recover lost partitions
and/or make non-booting disks bootable again when these symptoms
are caused by faulty software, certain types of viruses or human error.
It can also be used to repair some filesystem errors.

Information gathered during TestDisk use can be recorded for later
review. If you choose to create the text file, testdisk.log , it
will contain TestDisk options, technical information and various
outputs; including any folder/file names TestDisk was used to find and
list onscreen.

Use arrow keys to select, then press Enter key:
[ Create ] Create a new log file
[ Append ] Append information to log file
[ No Log ] Don't record anything

[No Log] を反転させて、ENTER


TestDisk 6.5, Data Recovery Utility, October 2006
Christophe GRENIER <grenier@cgsecurity.org>
http://www.cgsecurity.org

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

Select a media (use Arrow keys, then press Enter):
Disk /dev/hdc - 711 MB / 678 MiB (RO)
Disk /dev/sda - 250 GB / 232 GiB



[Proceed ] [ Quit ]

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

修復したいディスク(今回は Disk /dev/sda - 250 GB) を反転させて、 [Proceed]でENTER


TestDisk 6.5, Data Recovery Utility, October 2006
Christophe GRENIER <grenier@cgsecurity.org>
http://www.cgsecurity.org


Disk /dev/sda - 250 GB / 232 GiB

Please select the partition table type, press Enter when done.
[Intel ] Intel/PC partition
[Mac ] Apple partition map
[None ] Non partioned media
[Sun ] Sun Solaris partition
[XBox ] XBox partition
[Return ] Return to disk selection



Note: Do NOT select 'None' for media with only a single partition. It's very
rare for a drive to be 'Non-partitioned'.

Intelのマザーボードに接続されているので、[Intel]を選択してENTER


TestDisk 6.5, Data Recovery Utility, October 2006
Christophe GRENIER <grenier@cgsecurity.org>
http://www.cgsecurity.org


Disk /dev/sda - 250 GB / 232 GiB - CHS 30401 255 63

[ Analyse ] Analyse current partition structure and search for lost partitions
[ Advanced ] Filesystem Utils
[ Geometry ] Change disk geometry
[ Options ] Modify options
[ MBR Code ] Write TestDisk MBR code to first sector
[ Delete ] Delete all data in the partition table
[ Quit ] Return to disk selection



Note: Correct disk geometry is required for a successful recovery. 'Analyse'
process may give some warnings if it thinks the logical geometry is mismatched.

[Analyze] を選択して ENTER

現在認識されているパーティションマップを表示する


TestDisk 6.5, Data Recovery Utility, October 2006
Christophe GRENIER <grenier@cgsecurity.org>
http://www.cgsecurity.org

Disk /dev/sda - 250 GB / 232 GiB - CHS 30401 255 63
Current partition structure:
Partition Start End Size in sectors
1 * FAT32 0 1 1 254 254 63 4096512 [BOOT]
2 E extended LBA 255 0 1 30341 254 63 483347655
5 L FAT32 LBA 2424 1 1 3698 254 63 20482812 [DATA-1]
X extended 3699 0 1 4973 254 63 20482875






*=Primary bootable P=Primary L=Logical E=Extended D=Deleted

[Proceed ] [ Backup ]
Try to locate partition

[Proceed] を選択して ENTER を押すと、復旧可能なパーティション情報をサルベージしてくれる。
サルベージ状況が瞬間的に表示された後に、次のような「復旧不可能なパーティション」の候補を表示する。


TestDisk 6.5, Data Recovery Utility, October 2006
Christophe GRENIER <grenier@cgsecurity.org>
http://www.cgsecurity.org

Disk /dev/sda - 250 GB / 232 GiB - CHS 30401 255 63

The harddisk (250 GB / 232 GiB) seems too small! (< 268 GB / 250 GiB)
Check the harddisk size: HD jumpers settings, BIOS detection...

The following partition can't be recovered:
Partition Start End Size in sectors
D HPFS - NTFS 26262 254 63 32636 253 62 102398247










[ Continue ]

NTFS, 52 GB / 48 GiB

スタートセクタが63からとなっていて、いかにも異常。
ここでは、修正などの操作はできないので、なにもなすすべもなく [CONTINUE] を選択して ENTER


TestDisk 6.5, Data Recovery Utility, October 2006
Christophe GRENIER <grenier@cgsecurity.org>
http://www.cgsecurity.org

Disk /dev/sda - 250 GB / 232 GiB - CHS 30401 255 63
Partition Start End Size in sectors
* FAT32 0 1 1 254 254 63 4096512 [BOOT]
L FAT32 LBA 255 1 1 2423 254 63 34844922 [PROG]
L FAT32 LBA 2424 1 1 3698 254 63 20482812 [DATA-1]
L FAT32 LBA 3699 1 1 4973 254 63 20482812 [TEMP]
L HPFS - NTFS 4974 1 1 6885 254 63 30716217 [WIN2000]
L HPFS - NTFS 6886 1 1 8797 254 63 30716217 [WINXP]
L HPFS - NTFS 8798 1 1 10709 254 63 30716217 [WINVISTA]
L Linux 10710 1 1 11984 254 63 20482812
L Linux 11985 1 1 13259 254 63 20482812 [/1]
L Linux Swap 13260 1 1 13514 254 63 4096512

D FAT32 LBA 13515 1 1 19888 254 63 102398247 [MUSIC]
D HPFS - NTFS 19888 254 63 26262 254 63 102398311
L FAT32 LBA 26263 1 1 30341 254 63 65529072 [DATA-3]
Structure: Ok. Use Up/Down Arrow keys to select partition.
Use Left/Right Arrow keys to CHANGE partition characteristics:
*=Primary bootable P=Primary L=Logical E=Extended D=Deleted
Keys A: add partition, L: load backup, T: change type, P: list files,
Enter: to continue
FAT32, 2097 MB / 2000 MiB

実際の画面キャプチャはこんな感じ…

20071112-testdisk.png

復旧可能なパーティションが緑で反転(左端に D 以外の文字)されている。

ボリュームラベルに MUSIC と書かれたパーティションは正常にみえるため、その行を反転させて左右のカーソルキーを押して「左端の文字をDからL」に変更。

スタートセクタがおかしい壊れたNTFSパーティションを復旧するため、あらたなパーティションを作成する。

[A] キーを押して、新しいパーティション作成画面へ。


TestDisk 6.5, Data Recovery Utility, October 2006
Christophe GRENIER <grenier@cgsecurity.org>
http://www.cgsecurity.org

Disk /dev/sda - 250 GB / 232 GiB - CHS 30401 255 63





empty 0 0 1 30400 254 63 488392065







[Cylinder] [ Head ] [ Sector ] [Cylinder] [ Head ] [ Sector ]
[ Type ] [ Done ]

領域開始と終わりのシリンダ、ヘッド、セクタを入力してパーティションタイプを入力すれば新しいパーティションが作成されて、次のような画面になる。


TestDisk 6.5, Data Recovery Utility, October 2006
Christophe GRENIER <grenier@cgsecurity.org>
http://www.cgsecurity.org

Disk /dev/sda - 250 GB / 232 GiB - CHS 30401 255 63
Partition Start End Size in sectors
L FAT32 LBA 255 1 1 2423 254 63 34844922 [PROG]
L FAT32 LBA 2424 1 1 3698 254 63 20482812 [DATA-1]
L FAT32 LBA 3699 1 1 4973 254 63 20482812 [TEMP]
L HPFS - NTFS 4974 1 1 6885 254 63 30716217 [WIN2000]
L HPFS - NTFS 6886 1 1 8797 254 63 30716217 [WINXP]
L HPFS - NTFS 8798 1 1 10709 254 63 30716217 [WINVISTA]
L Linux 10710 1 1 11984 254 63 20482812
L Linux 11985 1 1 13259 254 63 20482812 [/1]
L Linux Swap 13260 1 1 13514 254 63 4096512
L FAT32 LBA 13515 1 1 19888 254 63 102398247 [MUSIC]

D HPFS - NTFS 19888 254 63 26262 254 63 102398311
L HPFS - NTFS 19889 1 1 26262 254 63 102398247
L FAT32 LBA 26263 1 1 30341 254 63 65529072 [DATA-3]

Structure: Ok. Use Up/Down Arrow keys to select partition.
Use Left/Right Arrow keys to CHANGE partition characteristics:
*=Primary bootable P=Primary L=Logical E=Extended D=Deleted
Keys A: add partition, L: load backup, T: change type, P: list files,
Enter: to continue
FAT32, 33 GB / 31 GiB

パーティションのリストに矛盾がないか確認してから、ENTERキーを押す


TestDisk 6.5, Data Recovery Utility, October 2006
Christophe GRENIER <grenier@cgsecurity.org>
http://www.cgsecurity.org

Disk /dev/sda - 250 GB / 232 GiB - CHS 30401 255 63

Partition Start End Size in sectors
1 * FAT32 0 1 1 254 254 63 4096512 [BOOT]
2 E extended LBA 255 0 1 30341 254 63 483347655
5 L FAT32 LBA 255 1 1 2423 254 63 34844922 [PROG]
6 L FAT32 LBA 2424 1 1 3698 254 63 20482812 [DATA-1]
7 L FAT32 LBA 3699 1 1 4973 254 63 20482812 [TEMP]
8 L HPFS - NTFS 4974 1 1 6885 254 63 30716217 [WIN2000]
9 L HPFS - NTFS 6886 1 1 8797 254 63 30716217 [WINXP]
10 L HPFS - NTFS 8798 1 1 10709 254 63 30716217 [WINVISTA]
11 L Linux 10710 1 1 11984 254 63 20482812
12 L Linux 11985 1 1 13259 254 63 20482812 [/1]
13 L Linux Swap 13260 1 1 13514 254 63 4096512
14 L FAT32 LBA 13515 1 1 19888 254 63 102398247 [MUSIC]
15 L HPFS - NTFS 19889 1 1 26262 254 63 102398247



[ Quit ] [Search! ] [ Write ] [Extd Part]
Return to main menu

この確認画面でよければ、[Write] を選択して ENTER
ディスクに書き込みが行われる。


TestDisk 6.5, Data Recovery Utility, October 2006
Christophe GRENIER <grenier@cgsecurity.org>
http://www.cgsecurity.org

Write partition table, confirm ? (Y/N)

しつこいくらいに、確認してくる。


TestDisk 6.5, Data Recovery Utility, October 2006
Christophe GRENIER <grenier@cgsecurity.org>
http://www.cgsecurity.org


You will have to reboot for the change to take effect.



[Ok]

天に祈りつつ、リブート...