How can I use a PC to recover data when my Synology NAS malfunctions?
How can I use a PC to recover data when my Synology NAS malfunctions?
Environment
Applicable to:
- DSM version 6.2.x and above
- Volumes using the Btrfs or ext4 file systems
- Ubuntu version 18.04 (Download ubuntu-18.04-desktop-amd64.iso here)
Not applicable to:
- Volumes using read-write SSD cache
Resolution
Recover data using a PC
- Make sure your PC has sufficient drive slots for drive installation.
- Remove the drives from your Synology NAS and install them in your PC. For RAID or SHR configurations, you must install all the drives (excluding hot spare drives) in your PC at the same time.
- Prepare an Ubuntu environment by following the instructions in this tutorial.
- Go to the Files on the left bar and select Home.
- Right-click and select New Folder, and create one or more folders as mount points for accessing data.1
- Right-click on the new folder(s), click Properties, the parent folder with folder name is
${mount_point}
.- Example: If the parent folder is
/home/ubuntu/
and the folder name isTest
, the mount point will be/home/ubuntu/Test/
- Example: If the parent folder is
- Go to Show Application in the lower-left corner > Type to search....
- Enter Terminal in the search bar and select Terminal.
- Enter the following command to obtain the root privileges.
sudo -i
- Enter the following commands to install
mdadm
andlvm2
, both of which are RAID management tools.lvm2
must be installed orvgchange
will not work.apt-get update
apt-get install -y mdadm lvm2 - Enter the following command to assemble all the drives removed from your Synology NAS. The results may differ according to the storage pool configurations on your Synology NAS.
mdadm -AsfR && vgchange -ay
- Enter the following command to get the information of
${device_path}
.According to the output ofcat /proc/mdstat
lvspvs/vgs/lvs
, the device paths are as follows:Below are the samples of
md status
corresponding to its RAID and volume type:Device PathsClassic RAID with single volumecat /proc/mdstat
root@ubuntu:~# cat /proc/mdstat
Personalities : [raid1]
md4 : active raid1 sdc3[0]
73328704 blocks super 1.2 [1/1] [U]
unused devices:<none>
lvsNo output${device_path}
/dev/md4
Device PathsSHR with single volumecat /proc/mdstat
root@ubuntu:~# cat /proc/mdstat
Personalities : [raid1]
md3 : active raid1 sda5[0]
73319616 blocks super 1.2 [1/1] [U]
unused devices:<none>
lvsroot@ubuntu:~# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv vg1000 -wi-a----- 69.92g
${device_path}
/dev/vg1000/lv
Device PathsClassic RAID/SHR with multiple volumecat /proc/mdstat
Personalities : [raid1]
md3 : active raid1 sdc3[0] sdd3[1]
73328704 blocks super 1.2 [2/2] [UU]
unused devices:<none>
lvsroot@ubuntu:~# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy% Sync Convert
syno_vg_reserved_area vg1 -wi-a----- 12.00m
volume_1 vg1 -wi-a----- 30.00g
volume_3 vg1 -wi-a----- 30.00g
${device_path}
/dev/vg1/volume_1
/dev/vg1/volume_3 - Enter the following commands to mount all the drives as read-only to access your data. Enter your device path (according to RAID and volume type in Step 12) in
${device_path}
and mount point (created in Step 6) in${mount_point}
. Your data will be placed under the mount point.mount ${device_path} ${mount_point} -o ro
- Check the data in Files > Home > the folders you created in Step 5.
- For encrypted volumes and shared folders:
If you still cannot recover the data through the above steps, refrain from trying any other methods to repair because it may cause more damage to your data. As your last option, seek the help of a local data rescue company. Kindly understand that data retrieval is still not guaranteed.
Mount an encrypted volume on a PC
Make sure you have the recovery key of your encrypted volume. The following steps only work if the recovery key is correct.
- In Terminal, enter the following command to install
cryptsetup
.apt-get install cryptsetup
- Enter the following command to decode your recovery key. Replace
${your_recovery_key_path}
with the location of the recovery key and${base64_decode_output_path}
with the desired output file name and location.base64 --decode ${your_recovery_key_path} > ${base64_decode_output_path}
- Example: If the recovery key is located at
/mnt/volume1.rkey
and you want the output file to be named asdecode_output
and located in/mnt
, the entered command will be:base64 --decode /mnt/volume1.rkey > /mnt/decode_output
- Example: If the recovery key is located at
- Enter the following command to test if the recovery key is correct. Replace
${base64_decode_output_path}
with the output file name and location.cryptsetup open --test-passphrase /dev/vgX/volume_Y -S 1 -d ${base64_decode_output_path} -v
- Example: If the output file name is
decode_output
and located in/mnt
, the entered command will be:cryptsetup open --test-passphrase /dev/vgX/volume_Y -S 1 -d /mnt/decode_output -v
- Example: If the output file name is
- Check the result to see if the recovery key is correct:
- Correct key:
Key slot 1 unlocked.
Command successful. - Incorrect key:
Find the correct key and return to the previous step to decode again.
No key available with this passphrase.
Command failed with code -2 (no permission or bad passphrase).
- Correct key:
- Enter the following command to decrypt the encrypted volume with your decoded recovery key.
cryptsetup open --allow-discards /dev/vgX/volume_Y cryptvol_Y -S 1 -d ${base64_decode_output_path}
- Enter the following command to mount all the drives as read-only to access your data. Replace
${device_path}
with your device path/dev/mapper/cryptvol_Y
and${mount_point}
with the mount point created in Step 6). Your data will be placed under the mount point.mount ${device_path} ${mount_point} -o ro
- Refer to Step 14 to recover your data.
Mount an encrypted shared folder on a PC
Make sure you have the encryption key of your encrypted shared folder. The following steps only work if the encryption key is correct.
- In Terminal, enter the following command to obtain the root privileges.
sudo -i
- Enter the following commands to enable
universe repo
and installecryptfs-utils
.apt-get-repository universe
apt-get update
apt-get install ecryptfs-utils - Enter the following command to get the FNEK (Filename Encryption Key) value of your encryption key.
ecryptfs-add-passphrase --fnek
- When prompted, enter your encryption key into the
Passphrase
field. - You will see an output similar to the following:
The value within the second square brackets is your FNEK value. Take note of this value because you will need it in the following steps.
Inserted auth tok with sig [79d78a9afb5ebc95] into the user session keyring
Inserted auth tok with sig [e4e4e8a3ca7d5d54] into the user session keyring
- When prompted, enter your encryption key into the
- Use the
cd
command to navigate to the mount point you have created in Step 6 of the previous section.cd ${mount_point}
- Example: If the mount point
${mount_point}
is/home/ubuntu/Test/
, the entered command would look like:cd /home/ubuntu/Test/
.
- Example: If the mount point
- Create a temporary folder as a mount point for your encrypted shared folder. Use the
mkdir
command to create a new folder.In the command above, replacemkdir folder_name
folder_name
with a name you want to give to the folder. - Enter the following command to mount your encrypted shared folder.
Make sure to replace
mount -t ecryptfs folder_name
folder_name
with the name of the temporary folder you have created in the previous step. To complete the mount, additional inputs are required. Follow the instructions below:Passphrase
: Enter your encryption key.Select cipher
: Enter1
to select aes as the cipher.Select key bytes
: Enter2
to select 32 as the key bytes.Enable plaintext passthrough
: Entern
to disable this option.Enable filename encryption
: Entery
to enable this option.Filename Encryption Key (FNEK) Signature
: Enter your FNEK value from Step 3.- After entering your FNEK value, you will see an output similar to the following:
The warning message is just a reminder. If you have checked that your encryption key is correct, you can safely ignore this warning and proceed.
Attempting to mount with the following options:
ecryptfs_unlink_sigs
ecryptfs_fnek_sig=e4e4e8a3ca7d5d54
ecryptfs_key_bytes=32
ecryptfs_cipher=aes
ecryptfs_sig=79d78a9afb5ebc95
WARNING: Based on the contents of [/root/.ecryptfs/sig-cache.txt], it looks like you have never mounted with this key before. This could mean that you have typed your passphrase wrong. Would you like to proceed with the mount
: Entery
to agree to proceed with the mount.Would you like to append sig … in order to avoid this warning in the future
: Entern
to continue.- If the mount is successful, you will see the following output:
Mounted eCryptfs
Notes:
- A mount point is equal to one volume. If you have multiple volumes that need to be recovered, please create the same number of folders as the number of volumes.
- The number of md (array) will be listed in the result of
cat /proc/mdstat
. syno_vg_reserved_area
can be ignored, the number of volume_x is equal to the number of volumes.