Skip to content

Instantly share code, notes, and snippets.

@jkirk
Created April 13, 2022 16:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jkirk/848ca4a91459147c3a2b6d9326b99c1d to your computer and use it in GitHub Desktop.
Save jkirk/848ca4a91459147c3a2b6d9326b99c1d to your computer and use it in GitHub Desktop.
Access QNAP encrypted HDD with GNU/Linux Debian

QNAP HDD Recovery Test (encrypted)

Removed HDD-2 from NAS (while running) and plugged into a Sharkoon USB-Bay and tried to recover data.

Tried to assemble all existing volumes:

  % sudo mdadm --assemble --scan
  mdadm: /dev/md/9 has been started with 1 drive (out of 24).
  mdadm: /dev/md/256 has been started with 1 drive (out of 2).
  mdadm: /dev/md/13 has been started with 1 drive (out of 24).
  
  % cat /proc/mdstat
  Personalities : [raid1]
  md13 : active (auto-read-only) raid1 sdb4[1]
        458880 blocks super 1.0 [24/1] [_U______________________]
        bitmap: 1/1 pages [4KB], 65536KB chunk
  
  md256 : active (auto-read-only) raid1 sdb2[1]
        530112 blocks super 1.0 [2/1] [_U]
        bitmap: 0/1 pages [0KB], 65536KB chunk
  
  md9 : active (auto-read-only) raid1 sdb1[1]
        530048 blocks super 1.0 [24/1] [_U______________________]
        bitmap: 1/1 pages [4KB], 65536KB chunk

/dev/sdb3 did not get detected. Started raid manually:

  % sudo mdadm --verbose --assemble /dev/md1 /dev/sdb3
  mdadm: looking for devices for /dev/md1
  mdadm: /dev/sdb3 is identified as a member of /dev/md1, slot 1.
  mdadm: no uptodate device for slot 0 of /dev/md1
  mdadm: added /dev/sdb3 to /dev/md1 as 1
  mdadm: /dev/md1 assembled from 1 drive - need all 2 to start it (use --run to insist).
  % sudo mdadm --readonly --run /dev/md1
  mdadm: started array /dev/md1

Activated volume group:

  % sudo pvscan 
  % sudo vgchange -ay vg1
  2 logical volume(s) in volume group "vg1" now active

Decrypt volume:

  % perl -e 'print crypt("__PASSWORD__HERE__", "\$1\$YCCaQNAP\$")' > qnap.key
  % sudo cryptsetup open /dev/vg1/lv1 test --key-file=qnap.key

See: https://www.kormoc.com/2014/06/10/unlock-qnap-encrypted-disk/ 1

Mount volume:

  % sudo mount -o ro /dev/mapper/test /mnt/source/

Unmount and stop volumes:

  % sudo mount -o ro /dev/mapper/test /mnt/source/
  % sudo cryptsetup close test
  % sudo vgchange -an vg1
  % sudo mdadm --stop --scan

Re-Inserted HDD in QNAP and the rebuild process was started automatically.

Footnotes

  1. Yes, URL does not exist anymore and was excluded from Wayback Machine! sigh! Any other options?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment