Published on by

So, you have a NAS, be it Synology, QNAP, NetGear, or some other device running Linux? Your device got broken and you lost access to your RAID0, RAID1 or RAID5 volume? Or you removed drives and updated firmware only to realize that it no longer recognizes the array when you tried putting drives back like I did recently? Well, you are in a right place, keep reading and I will show you how to restore access to your RAID volume without paying a single cent.

1. Drives
First thing to do is to remove drives that make an array from the device. Do not try to create new RAID volume because you will lose data. Do not write to those drives. Take them out, and connect them into your desktop PC.

2. Linux
NAS devices usually run Linux. If yours does not then this HOWTO is not for you, but it may still give you some usefull pointers. If you are running Linux on your desktop PC then you can skip to step 5, otherwise go and download the following software:

Proceed by installing VirtualBox (default settings are ok), and then create a new virtual machine. Select Linux as OS type, and then select Ubuntu (32-bit or 64-bit depending on which one you downloaded). Create a new disk for virtual machine (default is 8 GB and dynamic allocation which is ok). For the performance reasons you should change disk controller emulation to ICH9 and for simplicity you should remove default IDE controller which is created for CD-ROM emulation and instead create CD-ROM under SATA controller where your virtual machine disk is listed. Also, if you have option of host I/O caching available, turn it on. For the CD-ROM, select your downloaded Ubuntu Server ISO image. Finally, select Bridged Networking instead of NAT for virtual machine LAN adapter, and after you finish with virtual machine creation, power on the virtual machine.

3. Installing Linux
You will be presented with a series of screens that will guide you through the installation of Ubuntu. Just accept default settings for everything and do not select any additional packages at this time. When you are asked to create a user, enter your full name, then as the username and password enter the same credentials you are using for your Windows account — that will simplify setting up file sharing on Linux later. After the installation is complete, the virtual machine will reboot. If you get installer from the CD again, after choosing the language, select Boot from hard disk option and after a while you should get a login prompt.

4. Enabling access to physical drives
At this point you can power off the virtual machine because you need to enable full access to your hard drives which were part of a RAID array from the virtual machine. Launch command prompt (with administrative privileges in case UAC is not disabled) and type:

diskpart<Enter>

Once diskpart has started, you just need to find out which physical drives are the ones that you need to access from Ubuntu virtual machine. You will do that by typing:

list disk<Enter>

You should be able to recognize your RAID array member disks by size and capacity. Make a note of their disk numbers and exit diskpart by typing:

exit<Enter>

In the command prompt CD to your VirtualBox installation folder and type:

VBoxManage internalcommands createrawvmdk -filename [path]driveN.vmdk -rawdisk \\.\PhysicalDriveX<Enter>

Where path is a full path to your Ubuntu virtual machine folder (if it contains spaces you must put quotes around it), N is a number from 0 to number of RAID member drives, and X is a drive number you saw in diskpart. Repeat the command for all other RAID member drives by incrementing N and changing X to proper drive numbers. For example, if you have created virtual machine in C:\VM\UBUNTU folder and you have two RAID0 member drives listed with numbers 2 and 3 in diskpart you should type:

VBoxManage internalcommands createrawvmdk -filename C:\VM\UBUNTU\drive0.vmdk -rawdisk \\.\PhysicalDrive2<Enter>
VBoxManage internalcommands createrawvmdk -filename C:\VM\UBUNTU\drive1.vmdk -rawdisk \\.\PhysicalDrive3<Enter>

Once those small files are created, open virtual machine settings and add new disk to SATA controller. When asked, choose existing disk and navigate to drive0.vmdk. Repeat for all files you created. When you add all member drives, you can power on the virtual machine.

5. Mounting your RAID volume
After you login to your Ubuntu Server using credentials you created while installing, type:

sudo su -

Then authenticate using your password again. Now you have root privilege so be EXTRA carefull not to make a mistake or you can lose the data you are trying to recover. First step is to refresh the software repository and upgrade software:

apt-get update<Enter>
apt-get upgrade<Enter>

After those two commands finish, you can proceed with installing necessary packages:

apt-get install mdadm<Enter>
apt-get install samba<Enter>

During mdadm install you will be prompted for email server settings — just select no email configuration and let it finish. After all packages are installed it is time to assemble an array. I will give an example for RAID0, but the same principle applies to RAID5. The only difference is a number of drives involved and their names. To find out which devices you should use, take a look at kernel log:

dmesg | more<Enter>

Keep pressing <Space> until you find mentions of SCSI disk drives and look for their names, serial numbers, size, etc as well as their matching device names. Let's say that have you found two 1 TB drives with device names /dev/sdb and /dev/sdc. Those drives will usually have multiple partitions, but all of them should have the same number of partitions and usually the largest one is your data partition. In case of my Synology NAS, data partition number was 3:

mdadm --assemble md0 /dev/sdb3 /dev/sdc3<Enter>

If all goes well, there should be no errors reported. You can check status by typing:

cat /proc/mdstat<Enter>

Next, you should mount this partition so you can access the data — I recommend mounting read-only:

mkdir /mnt/volume1<Enter>
mount -r /dev/md3p1 /mnt/volume1<Enter>

If you were using RAID volume for iSCSI, then you should also specify the type of the filesystem you formatted it with. For example if you used the volume over iSCSI on a Windows PC:

mount -r -t ntfs /dev/md3p1 /mnt/volume1<Enter>

After mounting, you should see your data in /mnt/volume1 folder:

ls -l /mnt/volume1<Enter>

If you get an error from mdadm or during mount, then your case is more complicated and you should stop at this point, and ask for professional help.

6. Making data available to your Windows PC
This step is optional for people running Linux on their desktop PC. For those who run Windows it is necessary to enable access to data from Windows. Type the following command:

nano /etc/samba.d/smb.conf<Enter>

In the editor add the following at the end of the file:

[volume1]
	comment = RAID0 volume
	read only = yes
	locking = no
	path = /mnt/volume1

And uncomment the line which says security = user, then start Samba by typing:

smbd<Enter>

If everything went well, samba is now running. To find out the virtual machine IP type:

ifconfig<Enter>

And look for an IP address which is in the same subnet as the address of your PC. For example, if your PC address is 192.168.1.100, your virtual machine IP address might be 192.168.1.110. Once you find the IP address you should be able to open the share in Windows Exlporer by going to:

\\192.168.1.110\volume1

Of course, replace the IP address with the one you found.

If you can see your files in Windows Explorer, then congratulations — now you can copy your precious data, and the best thing is that you have just saved €100 or more on RAID recovery software.