Build your own NAS using a PI5 and a SATA controller card!!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
storage of your data is one of the most important things in Computing be it your collection of photos videos important documents or whatever you want to be able to store all of these things reliably and safely now back in the day I think most of us relied on just having a single disc to store everything on and maybe we'd then take backups of that every now and again and that is okay but your data is only as good as the last backup that you took and anything beyond there has now been lost if your dis fails a better way is to use an array of discs all working together with your data spread across them so that if any single disc fails everything keeps on working now previously on a Raspberry Pi this was quite difficult to do because the io was quite limited however with the Raspberry Pi 5 and the introduction of the PCI Express socket things have changed and now we can build ourselves a reliable disc R let me show you [Music] how hello once again P Geeks and techno nerds all around the world my name's Jeff and I'm an IT professional who's been in the industry for over 30 years I've been using Raspberry Pi since I first came out and I love finding or coming across new ways to make use of them and I want to share that with you here if you like what you see on this channnel please hit that Thumbs Up Button subscribe if you want to see more and hit that notification Bell so you can be told when I put a new video out also let me know in the comments about any projects that you've taken on with your raspberry pies and any suggestions that you have for projects for me to do in the future in a recent video I took you through how you can connect PCI Express devices to a Raspberry Pi 5 and I tried out a variety of cards however when I was putting everything away after that video I chanced upon another card that was lurking in the back of a cupboard it was a SATA controller card that could be used to attach conventional hard diss into a computer and that got me thinking could I make use of that to then create a fully featured NZ out of a Raspberry Pi 5 and that's exactly what I'm going to do here so first off let's take a look at all the kit that we need to put it together now the first thing that need for this project is obviously the Raspberry Pi itself now here just like in my prior video I've connected the P Moroni mvme base onto the Raspberry Pi 5 normally the purpose of this is to allow an m.2 SSD to be connected onto your Pi however in this case I flipped the base round so it actually sits on top of the Raspberry Pi 5 and then I've connected an adapter that turns the m.2 socket into a normal PCI Express Express socket this then allows me to connect any PCI Express card onto my Pi 5 I also have a 32 GB SanDisk micro SD card plugged in that I use to store the operating system the next thing you need is the SATA controller card itself now this one has got four ports allowing me to connect four SATA hard drives into my Raspberry Pi now for three of these ports I'm going to be connecting these three hard drives and these are going to form my resilient data storage array now here I've used three Western Digital 2 tbte hard drives from their red range these are designed for NZ usage and to run 24/7 however don't feel you've got to use something like this you could use any discs you like but just bear in mind they really do need to be the same size you can technically use ones that are different sizes and I'll show you how to work around that later however you will be limited as to whichever one is smallest and that will ultimately govern the capacity of your array so it's best to get three that are the same the fourth drive I'm going to connect I'm going to use for backups now this is deliberately sized as twice the size of the smallest hard drive that I'm using in my data array and again the reasons for this will become clear later the next thing is to provide Power to all of my Diss and to do that I'm going to be making use of this it's it's a Pico power supply now you can use these to actually power PCS this is a 160 watt version now you can see that all of its circuitry is exposed there and you may feel this is really dangerous however the great thing about picco power supplies is that everything is low voltage they take in a 12volt power supply and then makes available both 12vt and 5vt supplies to all of our devices since everything is low voltage then it's all perfectly safe to handle so please don't worry about the fact there is no case around this now the only problem with these kind of PC style power supplies is that by default they're Switched Off just like with your home PC nothing happens until you press the power button on the front of your case now we don't have that in this situation so we've got to simulate it and that's what this little device does it's called an ATX power starter and it connects on to the ATX power connector and and then on the rear of it it connects these two pins together now one of these corresponds to the power button connector and the other one to ground so what it means is that it behaves just like if you pressed and held down the power button on your PC so effectively as soon as we plug in our Pico power supply it will immediately start providing power to all of our hard drives now conventional spinning hard diss do get quite hot and so I wanted to get some fans to provide cooling For This now these are three 80 mm fans and they're not the most premium make in the world but I was able to get them quite cheaply from AliExpress and they do work really well now the picco power supply doesn't have any fan headers on it so I've had to get this adapter cable that allows you to plug into a regular Molex connector on one end and then it's got five connectors on the other end to allow you to hook up all of the different fans now the PCI Express adapter on the Raspberry Pi also needs power and the cable that comes with this also uses a Molex connector so I've had to get a splitter here to allow me to connect both the PCI Express adapter and the adapter that will provide Power to all of the fans the other issue I have with power is that the PCO power supplier only has a single SATA power output so I've had to get this splitter cable that allows me to connect to that and then split that to provide Power to all of my hard diss now I mentioned earlier that the Pico power supply takes a 12vt input and that's what this power brick provides this is a 12vt 150 W power supply so it can provide plenty of current to feed everything that we have here now rather than having all of this just sitting on a desk as a sprawling mess I thought it was a good idea to have some kind of enclosure now rather than buying a regular PC case it would have been quite a lot of money but just over £1 I was able to buy this it's an acrylic hard drive enclosure now normally this would allow you to connect up to 10 hard drives to it in our case we're only going to connect four but then I also want some space to allow our Raspberry Pi and its SATA controller C to sit in here and the Pico power supply the little brackets in the middle allow each of the three fans to be connected so they will sit on the front of the enclosure now this is actually all clear acrylic but you can see it's still got the covers on and that can only mean one thing it's time for aeling [Music] Montage now we've got our enclosure sorted out the other thing I need is something to act as a shelf for my Raspberry Pi and also another to act as a shelf for the picco power supply so I picked up a couple of these 2 and 1/2 in to 3 and 1/2 in disc adapters now I picked the these up on Amazon they were probably a little bit more than I really wanted to spend on them and you may be able to find something a lot cheaper on AliExpress so do shop around but what was really useful with these particular ones was that they had this fairly solid metal plate surface to them now this allowed me to drill some extra holes into it and then mount my Raspberry Pi straight on top of it so I could then put this in the enclosure and everything would be held really securely and once all of this is put together it looks something like this I'm really happy with the end results it looks a little bit chaotic but also quite industrial and fairly cyberpunk so I'm really happy with the end result but now we've got all of the hardware configured let's go and take a look at configuring the operating system and actually get these hard drives set up now the first thing you're going to want to do here is install Raspberry Pi OS onto the micro SD card now I used Raspberry Pi imag for this in order to install raspb pios 64bit Light version if you've never installed raspb Pi OS before and you want more information on how to do this take a look at my video right here and it will take you through the entire process however when you're all finished you'll be able to SSH onto your Raspberry Pi and you'll be able to get onto a terminal window just like this now in my prior video where I connected other PCI Express devices onto my Raspberry Pi I explained what kind of speeds you can expect to experience on your Raspberry Pi and that's shown in this table here there are two different generations of PCI Express that are supported on the pi5 generation 2 and Generation 3 now a buy one socket for a generation 2 socket will have throughput of 4 gbits per second however for Generation 3 it can provide 7.88 GBS per second so for this particular project we definitely want to enable that in order to do that you want to go back to your terminal and you need to edit the file /boot SLC config.txt if you go all the way to the bottom of this file then there are two parameters that you need to provide the first one DT pram equals PCI ex1 actually activates the PCI Express interface on the pi5 the second parameter DT PRM equals PCI ex1 underscore gen equal 3 forces the PCR Express socket into Generation 3 mode and that way we can get the highest throughput we possibly can once you've added those lines into the config.txt file just save it out and then reboot now our PI is rebooted we should now be able to see the discs let's go and take a look firstly let's make sure we can see the SATA controller and indeed we can see the SATA controller there and drivers have been loaded this is a great start now let's see if we can see the Diss and yes we can see SDA sdb SDC and SD we can see the first three are our data discs as their size is shown as 1.8 tabt which is the amount of usable space on our 2 tbte hard drives sdd is our backup disc shown as 3.6 terb which is the usable space out of a 4 terb drive now we're going to build a raid array on our data discs and it's important that you understand what I mean by a raid array so let's go and take a look at that now the easiest way to set up a load of storage is to just connect each independent dis onto your machine Mount them separately and then store files on them the problem of course is that if you lose any one of those diss then all of the files that you had on it will be lost and you won't be able to get them back again so if we look at the maximum capacity across all of your discs it's whatever they all add up to however your maximum Drive loss before you start losing data is zero the moment you lose any disc at all you lose data and you can't get it back so it's better if you can connect diss together in the form of an array and a technology that allows this is called raid now raid operates at a bunch of different levels so let's go and take a look at each of them the first of these is raid zero now this doesn't actually help a lot with resilience but it does help with performance in this case if you've got a single file then parts of it will be spread across all of your diss so in this case each of the three green blobs that you can see represent one file now what happens is as you have something that's trying to read that file as your reading the data from the first dis it'll be in the background preparing the second disc so that all of its heads are in exactly the right place for you to then read the data for the next section of that file so you can seamlessly just move on to it and then it will do exactly the same with the third part of the file that sits on the third dis and this will just keep on going preparing the next dis in the chain or looping back around to the first dis again to get that ready to read the next part of the file now if you lose any one of these discs you're effectively in the same position as you were before in that you can't access anything anymore because your data is spread across all of the discs it means you've lost everything so with raid Z your maximum capacity is again the sum of all of the discs that you have and again the maximum number of drives you can lose before you lose data is zero you lose one you've lost everything however you do get better read performance out of raate zero but because of the lack of resilience it's very rarely used as its own thing the next level is raid one and this is referred to as mirroring with this system as soon as you write to one of the diss its data is also written to the second disk and they're kept exactly in step with each other and what this means is that if you lose one of the discs you haven't lost any data at tool you can still read and write to the second disc with absolutely no problem and then you can replace the failed disc resynchronize everything and then just keep on going so you won't necessarily have any downtime whatsoever now this has a trade-off in capacity because the maximum capacity of your array is half the sum of all of the discs because half of your discs are effectively mirror copies of the other half but in this system you can lose half of your discs without losing any data although that does assume that the discs that you lose aren't both sides of a mirror if you lose both sides of a mirror you have no way forward there's then what's called raid 1+0 sometimes called 0 + 1 or RAID 10 and this is a combination of raid zero and raid 1 so here we've got three discs on the top and these are configured as raid zero so our file is spread across each of three discs however in order to provide redundancy to that we've then got a mirror pair for each of the discs on the bottom and so what this means is if we lose any given dis the array can keep on going because it can use its mirrored pair to still provide service so here once again the maximum capacity is half the sum of all of our discs and again you can lose up to half of your discs assuming you don't lose both sides sides of a mirror and you also get the better read performance that you would have got from raid zero a sort of compromise to this is what's called raid five now with raid five when you write to it parts of your files are spread across all of your Diss and there's then what's called parity information added as well now this is kind of like check suming in a way but it also provides a way to construct data that's missing and by spreading all of this data around and making copies of it and having this parity information that again is spread across all three disks what it means is if you lose any dis in your array your service can actually keep on running with absolutely no problem and again you can swap out the fail dis bring in a new one resynchronize everything and just carry on now with Road five the maximum capacity you have is the capacity of your total discs minus the capacity of one dis this is because all of that parity information takes up the equivalent of one dis now if you lose any single Drive in your raid five array everything is fine and you can keep on going if you lose two drives or more then you will lose absolutely everything so in effect the more drives you have in terms of capacity raid five is more and more and more efficient because the overall capacity you have is always the sum of all of your discs minus the capacity of one disc and you get all of the benefits of the better read performance now in this project I'm going to be setting up my three data discs as a raid five array so out of those three if I lose any single disc I'll still be absolutely fine and I'm also going to keep a separate backup on the other hard drive just to provide even more redundancy but this is is why my backup Drive was sized at 4 terb I've got three 2 tbte drives so my maximum data capacity is 4 terabytes 6 terabytes across all of my data discs minus the capacity of one disk so here I should have a pretty good and pretty reliable system now in order to set up our road five array on our data discs I need to install some software first the first thing to install is the logical volume manager or lvm and I can install that with this command here now the reason I'm installing the logical volume manager is because of the issue whereby your discs may not be exactly the same size as each other to get around this what I like to do is create logical volumes on each of the diss I can then ensure that they are exactly the same size as each other even if the physical discs are are slightly different so when I was talking about the discs earlier and I was saying that you don't necessarily need to buy diss that are identical for the purpose of building a raid array they do need to be the same size so as long as your discs are roughly the same size that's fine you've just got to size all of them based upon the smallest one now this may mean that you're wasting a bit of space on the larger hard drives but as long as they're not wildly different from each other then that's not really a big in efficiency in my casee all of the drives are the same size but I'm going to go through this process anyway firstly I need to add each of the drives into the system so it's aware of them I do that with this command here so now the logical volume manager is aware of them I now need to create what called volume groups for each of the discs now this was designed as another way to aggregate discs together but you don't get a lot of resilience from it so I need to create a different volume group for each dis and then I'm going to use a different system to bind everything I'm also going to create a volume group for the backup dis as well now they're all created I now need to create the logical volumes themselves now I need to provide sizing information here and this is where you need to check the size of each of your discs if I run BG display against my first data dis you can see that its complete size is 476,000 identical so everything is fine if you have any differences between your discs make note of the smallest number and then always use that in this next step this is created a logical volume called lvor data1 within that volume group group on the first dis and its size is exactly 476,000 but I need to now create a logical volume for my backup disc that's going to be a lot bigger so let's check the maximum size of that with VG display and you can see this is 95 3861 so I can create a logical volume up to that size so now I have all of my logical volumes I know all the ones for data are exactly the same size and then I have also one for my backup now I can go ahead and create my RAID five volume but for this I need a command called mdadm and I can install that like this now I can create my road five array and I do that with this command here the first parameter defines what I want to call my RAID array in this case I'm calling it md1 127 I then specify what raid level I want to create in this case five The Raid devices argument specifies how many devices there will be in the array in this case three and then I finally provide all of the device IDs for my data diss this has now created my array but it will actually take some time to build as it has to synchronize metadata about the array across all the diss you can see the status of this with the slpr slmd stat file here you can see it's reporting that two out of three discs are up and the entire synchronization process should take about another 222 minutes or roughly speaking for 4 hours now I should still be able to use the system in this time but performance will certainly be compromised but let's see if I can create a file system on this array okay we now have a file system on our raid arrray and so I should now be able to mount it firstly I'll make a directory to mount it into oh actually in my case I created this on my Pi earlier but that's the command I used to do it however I should now be able to mount my Raad five volume onto here and if I run DF minus K I should now be able to see that my 4 tbte volume is now mounted there next I want to change the ownership of that directory so that my Pi user can write into it and let's just make sure that I can that's worked successfully and if I do a directory listing of that directory there you can see our test.txt file I'll just clean that up again now the next thing I want to do for this is set up some software that I can use to actually share this directory out to other computers on the network this software is called sber and I can install it with this I then have to create a configuration file for sber and if I go right to the very bottom of the file I can see this now I just need to create a new section for my NZ the first line here just gives a general description of what the volume is that you're sharing the second parameter is a pass to the file system that you're going to be sharing out the third parameter says that you can just browse this file system the next parameter says that it's not read only and the final parameter says that you have to be logged in in order to be able to see the share now I have this I just have to save it out the next thing I need to do is Define a user that is allowed to use the share in this case I'm just going to make the pi user capable of doing that I can do that with this command here it asks me for a password to set for the sharing this is actually a different password to the one that's normally used for the pi user however I'm going to make it the same in this case as raspberry I then need to restart two services for all of this to take effect the first of these is SMB and this is the service that actually takes care of all the file sharing itself the other one is NMB and this takes care of advertising the share across your network now we've done all of this technically your NZ is ready to go however its performance will be severely limited by that initialization process so I want to wait for that to complete I can monitor its status with this command and this will update every two seconds so now I'm just going to wait for this to complete and come back in about 4 hours as you can see our array is now entirely built and we have these three U's here showing that each of our discs is up now it's all complete we can take a look at the performance of our array in order to do that I'm just going to use our normal disk test and here you can see it's able to read at 270 megabytes a second this is roughly speaking about 2.2 gbits a second so it's really really great performance now of course your NZ is going to be capped not by this read performance but by the speed of the network given that the pi5 has got a gigabit network interface so you're never going to be able to read more than a gigabit but this is great because it means that the discs themselves are not the bottleneck to your system it's the networking instead but now let's go and take a look at a couple of different systems actually accessing our NZ and see what performance they get in order to test the performance of our system I'll need a test file that I can use I'm going to create this here it's just going to create a file that's 1 GB in size consisting of nothing but random characters now we have this we can use it to check out the performance of our NZ the first test I'm going to run here is on a Windows box on the right hand side I've mounted our NZ as the X drive and I've just done that using the normal window sharing mechanism on the left I've got a local directory on my windows box with the test file that we generated so if I just drag that across the NZ and then copy it you can see that the performance we're getting is roughly speaking about 105 108 110 megabytes per second and that works out pretty much to gigabit speed so that's really cool so then let's try copying it back again and see what performance we get there and again it's coming down at really very much full speed so gigabit kind of speeds and this is great because it means that we're limited by our Network bandwidth rather than the dis performance the second test I'm going to do here is on my Linux box and I'm going to do effectively the same thing I've already mounted the NZ into a directory called SL MNT NZ test and what I'm going to do here is remove the test.at file then use SSH to actually create it on the NZ copy it over onto the local box and then copy it back again now if we're getting anything near about gig bit performance each of the transfers should take roughly speaking 9.2 9.3 seconds so let's see what performance we get here and yes as you can see against the real time that's been recorded here when we copied from the NZ to local it took 9.17 seconds and then copying from the local to the NZ storage took 9.2 seconds so again we're getting very very close to gigabit performance and this is really excellent we can look here at the power that the Naz is consuming from the main power supply and as you can see it's only about 21 Watts this is really really cool and just shows how efficient the Pioneers is now if I bring in the terminal that we were using before and I repeat that copy you can see that the power will jump up a little bit but not very much jump up a little bit even when it was at it highest load it only made it to about 26 27 Watts so the system really is very very power efficient and whilst I can't say for sure I'd certainly Hazard a guess that if you compared this to a Mini PC it would probably work out more power efficient than that the only other thing I really wanted to mention in terms of performance is that with all of the fans going this is really quite noisy here you can see I was running my noise meter and it recorded something close to about 50 DB now in ter of background noise that can get really annoying especially where it's quite a high pitched wine but a lot of this is generated by the fact that the fans are going at full speed all the time because they've got nothing to slow them down and what you can do here is buy something like this where you could attach the power connector that is driving all three of the fans into this and then you could use the control to slow the fans down and that would quieten things down quite dramatically now I haven't bothered to do that here because I've got the NZ kind of away somewhere so it's not really bothering me but if you did have it close to you then I would recommend picking up something like this they're not very expensive and can make a tremendous difference to the amount of noise that's generated now the last thing to do is to set up that backup disc and then create a routine job that we can use to back up our data from our NZ onto that backup disc at regular intervals I'm going to set mine up weekly so I'll show you how to set that up now so the first thing we need to do is actually format our backup dis and now we've got that done I can now create a directory to mount it into and then mount it and now you can see that both our NZ directory and our backup directory are both mounted the next thing I want to do is set up a script that I can use to create periodic backup TOS all this script does is call the rsync command again to back up anything that exists under mntn and then copy that to/ mntb backup it will do this recursively and it'll also copy only stuff that's new so the first time we run it it will copy over everything but after this it'll only copy an anything that's changed now one thing to bear in mind here is that if you delete anything under slmn NES those files will still exist under SL mntb backup next time the backup script is run it won't delete them from there now this is a really good thing because if you accidentally delete something at least you'll have your backup of it that you can restore however if you are worried about dis space at any point you'll have to go in and clear out any files that you intentionally deleted from your backup drive now all we need to do is change the permissions on it and now let's run it and see what happens and there you see it's completed now the command gave no output so we actually have to do something else to see the log messages that got written we can do that with a journal CTL command if we scroll this all the way to the bottom then we can see these messages here and this was the output of our backup job and here you can see that it's copied both of the files that were there in our NZ directory off to our backup drive and we can prove that by looking at our backup directory so now all that's left to do is actually run this on a schedule and we can do this using Chron all we have to do is create a file under /c/ ch. D to form our job now the first bit of data that we need to put in here is the minute at which we want our Chron job to run in this case I actually want it to run at 1:00 a.m. every Sunday so I'm going to set the minute to zero then I'm going to set the hour to 1 so this represents 1:00 a.m. the next parameter represents which day of a month that you want to run it I'm going to say say star for that because I don't care what day of the month this runs on I just want it to run every Sunday the next parameter is specifying the month that you want it to run and again I want it to run in all months so I'm just going to provide a star there and then the next parameter represents the day of the week that you want it to run on now this starts at zero for a Sunday and goes through to 6 for a Saturday so since I want this to always run at 1:00 a.m. on a Sunday I just have to put in zero here here I then have to put in the name of the user that I want the job to run as in this case root and then finally the name of the script that I want to run and then I just have to save this out and that will then just set up that job to run every single Sunday the last thing we have to do here is set up what's called the Auto Mount file in order for our NAS drive and our backup drive to be mounted at boot time in order to do this we need to Ed it slcfs tab file and here I just want to add a couple of lines to the end the first one is to mount our NZ drive here we say we want the device /dev md27 which is our road five volume to be mounted at/ mntn and that it's used in the ext4 file system it's applying all defaults to that all of the rest are just parameters to the Mount system and now we do a similar thing for our backup drive and then this will specify taking our backup Drive mounting it into SL mntb backup again specifying the file system and all other parameters when that's done we can just save this out now we've made a change to the fs tab file we need to actually reload that into system CTL and now that's done we can reboot and now here we are rebooted and if I run DF minus K you can see that both our NZ and our backup drives are now automatically mounted and so there you go your very own NZ built around a Raspberry Pi 5 and that's it for this video once again if you liked what you see here please hit that like button subscribe if you want to see more and also hit that notification Bell so you can be told when I put a new video out let me know in the comments how you get on with this project and also let me know in there if you've got any other ideas for projects that you'd like to see me do thanks so much for watching till the end and until next time bye for [Music] now
Info
Channel: Jeffs Pi in the Sky
Views: 4,898
Rating: undefined out of 5
Keywords: pi, pi5, raspberry pi, nas, network, attached, storage, tech, hobbies, data, raid, zfs, backup, resillient, resillience, safe, redundant, redundancy, disk, disks, cooling
Id: yzqFOgN3Sl0
Channel Id: undefined
Length: 38min 50sec (2330 seconds)
Published: Sun Apr 07 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.