Upgrade to Pro — share decks privately, control downloads, hide ads and more …

LinuxでNASのdiskのデータを復旧

 LinuxでNASのdiskのデータを復旧

Kenichiro MATOHARA

October 31, 2020
Tweet

More Decks by Kenichiro MATOHARA

Other Decks in Technology

Transcript

  1. / 最近の発表 最近の発表 2020-09-20(Sun) 2020-10-03(sat) 2020-10-10(sat) Rakutem miniを非常用Linux端末に出来ないか試す 鹿児島Linux勉強会 2020.09(オンライン開催)

    F2FSの透過圧縮機能を使いたい 東海道らぐ!ておくれライブフェスティバル NetworkManagerのWi-Fi接続のQR code共有 小江戸らぐ 10月のオフな集まり(第219回) 3 / 46
  2. / 受け取る 受け取る NASと取り出されたDisk Buffalo LinkStation LS210SC Series 1TB版(TOSHIBA DT01ACA100)

    disk 1本のモデル 中身はLinuxでファイルシステムも一般的なものらしい(認識した らmountしてcpするだけ?) 7 / 46
  3. / ハードディスク接続場所 ハードディスク接続場所 SATAの直付がいいけど今回はUSB経由 USB portの場所に注意 lsusbなどで速度が速くて混んでないポートを探して使う 今回は2ポート必要 $ lsusb

    -t /: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/3p, 480M |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/8p, 480M |__ Port 1: Dev 3, If 0, Class=Mass Storage, Driver=ums-realtek, 480M /: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/3p, 480M |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/6p, 480M |__ Port 2: Dev 6, If 0, Class=Mass Storage, Driver=uas, 480M |__ Port 4: Dev 3, If 2, Class=Vendor Specific Class, Driver=, 12M |__ Port 4: Dev 3, If 0, Class=Wireless, Driver=btusb, 12M |__ Port 4: Dev 3, If 3, Class=Application Specific Interface, Driver=, 12M |__ Port 4: Dev 3, If 1, Class=Wireless, Driver=btusb, 12M |__ Port 5: Dev 4, If 0, Class=Hub, Driver=hub/4p, 480M 9 / 46
  4. / USB-SATAの注意点 USB-SATAの注意点 ブロックデバイスとして使えてもS.M.A.R.T.等の詳細情報が見えな いものがある この辺の物なら大丈夫かも? 今回は を利用(S.M.A.R.T.見えた) $ sudo

    smartctl --info /dev/sdc smartctl 7.1 2019-12-30 r5022 [x86_64-linux-5.8.0-26-generic] (local build) Copyright (C) 2002-19, Bruce Allen, Christian Franke, www.smartmontools.org /dev/sdc: Unknown USB bridge [0x0bda:0x0159 (0x5888)] Please specify device type with the -d option. Use smartctl -h to get a usage summary 対応外付けドライブ – Crystal Dew World Logite LHR-2BDPU3ES 10 / 46
  5. / USB-SATA経由で繋いでみる USB-SATA経由で繋いでみる [686723.179448] usb 1-1.5.2: new high-speed USB device

    number 13 using ehci-pci [686723.334895] usb 1-1.5.2: New USB device found, idVendor=0789, idProduct=0262, bcdDevice= 1 [686723.334902] usb 1-1.5.2: New USB device strings: Mfr=2, Product=3, SerialNumber=1 [686723.334906] usb 1-1.5.2: Product: LHR USB Device [686723.334909] usb 1-1.5.2: Manufacturer: Logitec [686723.334913] usb 1-1.5.2: SerialNumber: 20200417xxxxxxxx [686723.337578] scsi host8: uas [686723.342324] scsi 8:0:0:0: Direct-Access TOSHIBA DT01ACA100 0 PQ: 0 ANSI: 6 [686723.347301] sd 8:0:0:0: Attached scsi generic sg4 type 0 [686723.353640] sd 8:0:0:0: [sde] 1953525168 512-byte logical blocks: (1.00 TB/932 GiB) [686723.353645] sd 8:0:0:0: [sde] 4096-byte physical blocks [686723.354258] sd 8:0:0:0: [sde] Write Protect is off [686723.354261] sd 8:0:0:0: [sde] Mode Sense: 43 00 00 00 [686723.355097] sd 8:0:0:0: [sde] Write cache: enabled, read cache: enabled, doesn't support D [686723.356731] sd 8:0:0:0: [sde] Optimal transfer size 33553920 bytes not a multiple of physi 11 / 46
  6. / [686731.587461] sd 8:0:0:0: [sde] tag#3 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_SENSE

    [686731.587471] sd 8:0:0:0: [sde] tag#3 Sense Key : Hardware Error [current] [686731.587480] sd 8:0:0:0: [sde] tag#3 Add. Sense: Internal target failure [686731.587488] sd 8:0:0:0: [sde] tag#3 CDB: Read(10) 28 00 00 00 00 00 00 00 08 00 [686731.587493] blk_update_request: critical target error, dev sde, sector 0 op 0x0:(READ) flag [686731.587506] Buffer I/O error on dev sde, logical block 0, async page read [686731.587996] sd 8:0:0:0: [sde] tag#8 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_SENSE [686731.588000] sd 8:0:0:0: [sde] tag#8 Sense Key : Not Ready [current] [686731.588003] sd 8:0:0:0: [sde] tag#8 Add. Sense: Medium not present [686731.588006] sd 8:0:0:0: [sde] tag#8 CDB: Read(10) 28 00 00 00 00 00 00 00 08 00 [686731.588008] blk_update_request: I/O error, dev sde, sector 0 op 0x0:(READ) flags 0x0 phys_ 12 / 46
  7. / [686731.591023] Buffer I/O error on dev sde, logical block

    3, async page read [686731.591865] sde: unable to read partition table [686731.600016] sd 8:0:0:0: [sde] Attached SCSI disk [686731.621305] sd 8:0:0:0: [sde] tag#2 device offline or changed [686731.621387] sd 8:0:0:0: [sde] tag#3 device offline or changed [686785.366677] sd 8:0:0:0: [sde] tag#10 device offline or changed [686785.366684] print_req_error: 4 callbacks suppressed [686785.366687] blk_update_request: I/O error, dev sde, sector 0 op 0x0:(READ) flags 0x0 phys_ [686785.366689] buffer_io_error: 3 callbacks suppressed [686785.366690] Buffer I/O error on dev sde, logical block 0, async page read [686785.366778] sd 8:0:0:0: [sde] tag#11 device offline or changed [686785.366789] blk_update_request: I/O error, dev sde, sector 0 op 0x0:(READ) flags 0x0 phys_ 13 / 46
  8. / 吸出し…… 吸出し…… ダメ元でGNU ddrescueで吸い出そうとしてみると全てがerrorに $ time sudo ddrescue -n

    -v /dev/sde /mnt/disk.img /mnt/log/ddrescue_-n_-v.001.log GNU ddrescue 1.23 About to copy 1000 GBytes from '/dev/sde' to '/mnt/resque/disk.img' Starting positions: infile = 0 B, outfile = 0 B Copy block size: 128 sectors Initial skip size: 19584 sectors Sector size: 512 Bytes Press Ctrl-C to interrupt ipos: 12872 MB, non-trimmed: 12879 MB, current rate: 0 B/s opos: 12872 MB, non-scraped: 0 B, average rate: 0 B/s non-tried: 987325 MB, bad-sector: 0 B, error rate: 1636 MB/s rescued: 0 B, bad areas: 0, run time: 8s pct rescued: 0.00%, read errors: 196621, remaining time: n/a time since last successful read: n/a Copying non-tried blocks... Pass 5 (forwards) 16 / 46
  9. / ディスクイメージの中を見る ディスクイメージの中を見る パーティション情報が無いように見える $ sudo fdisk -l ./disk.img Disk

    ./disk22.img: 931.53 GiB, 1000204886016 bytes, 1953525168 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes 26 / 46
  10. / Superblockが見つからない Superblockが見つからない $ sudo fsck.ext4 -v ./disk.img e2fsck 1.45.5

    (07-Jan-2020) ext2fs_open2: Bad magic number in super-block fsck.ext4: Superblock invalid, trying backup blocks... fsck.ext4: Bad magic number in super-block while trying to open ./disk22.img The superblock could not be read or does not describe a valid ext2/ext3/ext4 filesystem. If the device is valid and it really contains an ext2/ext3/ext4 filesystem (and not swap or ufs or something else), then the superblock is corrupt, and you might try running e2fsck with an alternate superblock: e2fsck -b 8193 <device> or e2fsck -b 32768 <device> 27 / 46
  11. / backup確認 backup確認 $ mke2fs -n ./disk22.img mke2fs 1.45.5 (07-Jan-2020)

    Creating filesystem with 244190646 4k blocks and 61054976 inodes Filesystem UUID: c41b57a4-5563-4f82-8447-33ecc5cfbe8d Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 102400000, 214990848 29 / 46
  12. / Superblock backupからの復元を Superblock backupからの復元を 試みる 試みる 全て確認 → NG

    $ sudo e2fsck -b 32768 ./disk.img e2fsck 1.45.5 (07-Jan-2020) e2fsck: Bad magic number in super-block while trying to open ./disk22.img The superblock could not be read or does not describe a valid ext2/ext3/ext4 filesystem. If the device is valid and it really contains an ext2/ext3/ext4 filesystem (and not swap or ufs or something else), then the superblock is corrupt, and you might try running e2fsck with an alternate superblock: e2fsck -b 8193 <device> or e2fsck -b 32768 <device> 30 / 46
  13. / 拡張子毎にディレクトリを作って復元してくれる ファイル名,タイムスタンプは失われている ファイルの破片がたくさん出てくるけどそのまま開けるものは殆 ど無いので途中で中断した foremost foremost $ file foremost_Tue_Sep_29_08_59_29_2020/jpg/03155321.jpg

    foremost_Tue_Sep_29_08_59_29_2020/jpg/03155321.jpg: JPEG image data $ display foremost_Tue_Sep_29_08_59_29_2020/jpg/03155321.jpg display-im6.q16: Invalid JPEG file structure: two SOI markers `foremost_Tue_Sep_29_08_59_29_20 33 / 46
  14. / PhotoRecではパーティションの PhotoRecではパーティションの 区切りは見えているようだった 区切りは見えているようだった 復元できそう? ※この情報で mount -o loop,offset=〜

    でも行けたかも? PhotoRec 7.1, Data Recovery Utility, July 2019 Christophe GRENIER <[email protected]> https://www.cgsecurity.org Disk /mnt/resque/disk22.img - 1000 GB / 931 GiB (RO) Partition Start End Size in sectors Unknown 0 0 1 121601 80 63 1953525168 [Whole disk] > 1 P MS Data 0 0 35 124 126 3 1999967 [primary] 2 P MS Data 124 140 17 746 233 63 9998336 [primary] 3 P Unknown 746 234 1 746 246 13 769 [primary] 5 P MS Data 746 246 15 871 117 15 1999999 [primary] 6 P MS Data 871 119 17 120603 205 50 1923500032 [primary] 37 / 46
  15. / TestDisk起動 TestDisk起動 該当ディスクイメージなのを確認して Proceed TestDisk 7.1, Data Recovery Utility,

    July 2019 Christophe GRENIER <[email protected]> https://www.cgsecurity.org TestDisk is free software, and comes with ABSOLUTELY NO WARRANTY. Select a media (use Arrow keys, then press Enter): >Disk /mnt/resque/disk-partition_repair.img - 1000 GB / 931 GiB >[Proceed ] [ Sudo ] [ Quit ] Note: Some disks won't appear unless you are root user. 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. 39 / 46
  16. / パーティションテーブルタイプ パーティションテーブルタイプ を選択 を選択 今回は Intel を選択 lease select

    the partition table type, press Enter when done. >[Intel ] Intel/PC partition [EFI GPT] EFI GPT partition map (Mac i386, some x86_64...) [Humax ] Humax partition table [Mac ] Apple partition map (legacy) [None ] Non partitioned media [Sun ] Sun Solaris partition [XBox ] XBox partition [Return ] Return to disk selection 40 / 46
  17. / パーティション構造を解析 パーティション構造を解析 Analyse を選択してパーティション情報解析画面へ Backup で作業前の情報をログファイルに書き出し(option) Quick Search で解析

    結果が表示されたら内容を確認してOKなら Write で反映 NGなら Deeper Search → 確認 → Write で反映 Write するまでディスクイメージは書き換わらない もし失敗したらオリジナルイメージからコピーしなおしてやり直 す 41 / 46
  18. / パーティション情報が復元でき パーティション情報が復元でき た! た! fdisk -l /mnt/resque/disk.img でも見える Device

    Boot Start End Sectors Size Id Type ./diskimage/disk-partition_repair.img1 * 34 1999993 1999960 976.5M 83 Linux ./diskimage/disk-partition_repair.img2 2000896 11999231 9998336 4.8G 83 Linux ./diskimage/disk-partition_repair.img3 14000128 1937500159 1923500032 917.2G 83 Linux 42 / 46
  19. / マウントしてデータコピー マウントしてデータコピー 後はkpartx, mount(-o ro), rsyncで終了 :) 恐らく1パーティション目はuboot,2パーティション目はNASの root,3パーティション目がNASのデータ

    $ sudo kpartx -av ./diskimage/disk-partition_repair.img Warning: Disk has a valid GPT signature but invalid PMBR. Assuming this disk is *not* a GPT disk anymore. Use gpt kernel option to override. Use GNU Parted to correct disk. add map loop32p1 (253:3): 0 1999960 linear 7:32 34 add map loop32p2 (253:4): 0 9998336 linear 7:32 2000896 add map loop32p3 (253:5): 0 1923500032 linear 7:32 14000128 $ sudo mount -o ro /dev/mapper/loop32p3 /mnt $ ls /mnt/ mt-daapd share spool 43 / 46
  20. / 余録)沢山のツール 余録)沢山のツール 今回は主にTestDiskを利用したが他にも使えそうなツールがある Debian/Ubuntuだとメタパッケージ forensic* に沢山ツールが (TestDiskは forensics-extra に含まれる)

    デジタルフォレンジック特化ディストリビューションとかも もっと調べたい diskに余裕があると複数のツールが並列実行できて効率良さそう forensic-artifacts - knowledge base of forensic artifacts (data files) forensics-all - Debian Forensics Environment - essential components (metapackage) forensics-all-gui - Debian Forensics Environment - GUI components (metapackage) forensics-colorize - show differences between files using color graphics forensics-extra - Forensics Environment - extra console components (metapackage) forensics-extra-gui - Forensics Environment - extra GUI components (metapackage) forensics-full - Full forensics station (metapackage) forensics-samples-all - Set of files to help learn/test forensics tools and techniques (metapa 44 / 46
  21. / まとめ まとめ 運良くハンダゴテとTestDiskのおかげでパーティション情報の復元 が出来た 大事なデータをバックアップなし通常のハードディスクのみに格 納するのはかなり怖い RAID1/5/6/10とかなら耐障害性upするので少し安心だけどバック アップ重要 災害を考えると遠隔バックアップも欲しい

    ランサムウェア対策にはオフラインバックアップ クラウドバックアップ……財布や回線と相談(G Suite容量無制限死 んだ.画像は未だAmazon PhotosがRAWも含め無制限) バックアップ重要(たまには復元も試そう) 45 / 46
  22. / 奥付 奥付 発表 2020-10-31(土) 発表者 ライセンス CC BY-NC-SA 4.0

    鹿児島Linux勉強会 2020.10(オンライン開催) Kenichiro Matohara(matoken) 46 / 46