How to Turn a Raspberry Pi into a Low-Power Network Storage Device

0
353
How to Turn a Raspberry Pi into a Low-Power Network Storage Device

Here we can see, “How to Turn a Raspberry Pi into a Low-Power Network Storage Device”

You can make an ultra-low-power and always-on network storage device by combining one Raspberry Pi with a few affordable external hard drives. Continue reading to learn how to set up your own Pi-based NAS.

Why Do I Want to Do This?

The advantage of having an always-on network storage device is that your data (or backup destination) is always accessible to machines both inside and outside your network. The disadvantage is that, in most cases, you’re wasting a lot of energy for convenience.

For example, our office server operates 24 hours a day, consuming about $200 in electricity each year. A Raspberry Pi-based network storage device, on the other hand, uses roughly $5 per year in electricity.

We’ll be the first to admit that a full-fledged server will have greater storage space and be able to perform more tasks (such as transcoding a multi-terabyte video collection in a reasonable period). However, the primary aim of having an always-on computer somewhere in the house is to function as a file server and backup repository for most individuals. For such jobs, the Raspberry Pi is more than capable and will save you a significant amount of money in power consumption.

What do I require?

This article expands on our previous tutorial, The HTG Guide to Getting Started with Raspberry Pi, and we’ll assume you’ve already finished it. That is, you have your Raspberry Pi, it’s powered up, connected to a mouse and keyboard, and Raspbian loaded.

Also See:  Samsung Galaxy Book, Galaxy Book Pro, as well as the Galaxy Book Pro 360 launched from ~RM3,547

You’ll need the following hardware in addition to the items listed in the Getting Started with Raspberry Pi tutorial:

  • One USB external hard drive (at a minimum) for simple network backups and file serving

or

  • Two USB external hard drives (at a minimum) for local data redundancy

That concludes our discussion. You’ll need one hard disc if you want a simple network hooked drive. We strongly advise utilizing at least two hard drives to provide local data redundancy (on the Raspberry Pi). We’ll use a matching pair of Seagate Backup Plus 1TB Portable External Hard Drives for this tutorial. They’re extremely compact, don’t require any external power, and were on sale when we looked for replacement parts.

You can use any external hard drives you have on hand, but small low-power drives are preferable because the project’s goal is to create a small and low-power NAS that you can tuck away and forget about.

Before we go any further, you should be aware of a handful of design decisions we took in terms of how we’re configuring our Raspberry Pi NAS. While most users will want to do everything exactly as we’ve done it, you may want to change some of the processes to match your needs and how you use the computers on your network.

For starters, we’re working with NTFS-formatted hard drives. Having NTFS-formatted discs makes it dead simple to take the portable USB drives we’re using on the NAS build and plug them right into one of the many Windows machines we use every day if the Raspberry Pi NAS fails for some reason or we want to quickly copy the information over a USB 3.0 connection instead of over the network.

Second, we’re utilizing Samba for our network shares because it’s easier to integrate the Raspberry Pi NAS with our mostly Windows network with Samba.

Preparing for and Mounting the External Hard Drives

It’s time to start setting up your Pi as a NAS once you’ve gathered the necessary hardware and followed the Getting Started with Raspberry Pi instruction to get up to speed (and are running Raspian).

The hardest part is connecting the hard discs to the Raspberry Pi (or the attached USB hub, depending on your configuration and whether or not the hard drives are self-powered or externally powered). It’s time to get to work when the hard discs have been connected, and the Pi has been turned on.

It’s worth noting that we’re employing two hard discs. If you only want to utilize one hard drive, ignore all of the commands in this section that are meant to mount, alter, or otherwise interact with the second hard disc.

  • All of our work will be completed within the terminal. As a result, you can either use LXTerminal in Raspian to operate directly on your Raspberry Pi or use a tool like Putty to SSH onto it. It’s OK either way.
  • Once you’re at the command prompt, the first thing you should do is add support for NTFS-formatted discs to Rasbian. Type the following command to do so:
sudo apt-get install ntfs-3g
  • The packages will take a minute or two to download, unpack, and install. It’s time to seek unmounted partitions on the attached external hard drives once the NTFS package has been installed.
sudo fdisk -l

You should see two discs at a minimum and three if you’ve added a backup drive for data mirroring (like we have):

  • The SD card inside the Raspberry Pi that stores our Raspbian system is the first disc, /dev/mmcb1k0. We’re going to ignore that one entirely.
  • Our first 1TB external hard drive, /dev/sda, is the second disc. Our second 1TB external hard disc, /dev/sdb, is the third disc. We’re interested in the partitions on these two drives are /sda1/ and /sdb1/, respectively. Make a list of the names of the hard drives.

We must first construct a directory to which the discs will be mounted before we can mount them. For the sake of simplicity, we’ll create two directories for each drive: USBHDD1 and USBHDD2. We must first create the drives. Enter the following commands at the command prompt:

sudo mkdir /media/USBHDD1

sudo mkdir /media/USBHDD2

It’s time to mount the external discs to each location after you’ve built the two directories. Enter the following commands at the command line once more:

sudo mount -t auto /dev/sda1 /media/USBHDD1

sudo mount -t auto /dev/sdb1 /media/USBHDD2

The two external hard discs have now been installed in the USBHDD1 and USBHDD2 folders, respectively. It’s time to create a dedicated folder on both drives to house our shared folders (for the sake of keeping things tidy and compartmentalizing our work on the drives). Use the following instructions to get started:

sudo mkdir /media/USBHDD1/shares

sudo mkdir /media/USBHDD2/shares

Now we need to set up Samba to access the storage from anywhere on the network. Enter the following command at the command prompt:

sudo apt-get install samba samba-common-bin

When prompted to continue, press Y to continue. As everything unpacks and installs, sit back and relax. It’s time to do some settings after the Samba package has been installed. Please make a backup copy of the Samba configuration file before we do anything else if we need to revert to it. Type the following command at the command prompt:

sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.old
  • This creates a backup of the configuration file smb.conf.old and saves it in the same directory as the original.
  • After producing the backup, we’ll need to make some basic changes to the Samba configuration file. At the command prompt, type the following:
sudo nano /etc/samba/smb.conf

This will launch the nano text editor, which will allow us to make some minor adjustments. If you’re new to nano, the Linux command-line text editor, we recommend starting with The Beginner’s Guide to Nano, the Linux Command-Line Text Editor.

The keyboard controls nano; move the cursor to the spot you wish to modify with the arrow keys. As you scroll through the setup options, you’ll notice a couple that are worth noting or adjusting.

Also See:  NTOSKRNL.EXE is missing or corrupt: Fix for Windows XP
  • The first is the workgroup identification, which is set to WORKGROUP by default. If your home workgroup has a different name, go ahead and change it now; otherwise, leave it as is.
  • Next, we’ll enable user authentication for our Samba storage; otherwise, anyone with general network access (such as guest Wi-Fi users) will be able to stroll right in. Scroll down until you find the following section in the Samba config file:
  • To enable username/password verification for Samba shares, erase the # symbol from the security = user line (by selecting it with the mouse and pressing delete).

Then, in the configuration file, we’ll add a completely new section. Enter the following text at the very bottom of the file:

[Backup]
comment = Backup Folder
path = /media/USBHDD1/shares
valid users = @users
force group = users
create mask = 0660
directory mask = 0771
read only = no

Note: The folder’s name as it appears on the network share will be whatever you put in the brackets in the top line. Now is the moment to change the name to something other than “Backup.”

  • To exit, hit CTRL+X, then Y when prompted to keep your changes and overwrite the existing configuration file. To restart the Samba daemons, return to the command prompt and type the following command:
sudo /etc/init.d/samba restar

We’ll need to create a user who can access Pi’s samba shares at this point. We’ll create an account with the backups username and backups4ever password. Your username and password can be whatever you like. To do so, type the commands below:

sudo useradd backups -m -G users

sudo passwd backupst

To confirm the password, you’ll be asked to key it in twice. It’s time to add “backups” as a real Samba user after confirming the password. Type the following command in the prompt:

sudo smbpasswd -a backups

When prompted, provide the backup account’s password. You don’t need to restart the Samba daemon once you’ve created the user account and password because we’ve already told it to seek authenticated users. We can now test connectivity to the network share from any Samba-capable system on our network.

  • We launched the Windows file explorer from a nearby Windows PC, clicked on Network, confirmed that the hostname RASPBERRYPI was in the WORKGROUPS workgroup, and then click on the shared folder Backups:
  • When prompted, enter the credentials you created in the previous step (the login is backups, and the password is backups4ever if you’re following along line by line).
  • Because there isn’t anything in the share yet, you’ll be greeted with an empty folder after your credentials are accepted. Let’s make a basic file from the computer we used to test the connection to make sure everything is operating properly (in our case, the Windows 7 desktop).
  • Let’s check to see if the file we produced on the Windows desktop appears correctly within the share directory we created using the command line we’ve been using all along. Type the following command at the command prompt:
cd /media/USBHDD1/shares

ls

The file hello-is-it-me-you’re-looking-for.txt has been found in the directory; our simple shared directory experiment has worked!

  • We have one more task to complete before we exit this phase of the tutorial. We’ll need to set up our Pi to mount the external hard discs when it restarts automatically. To accomplish so, we’ll use the nano editor to make a simple edit. Type the following command at the command prompt:
sudo nano /etc/fstab

This will open the file systems table in nano, allowing us to add a few entries quickly. Add the following lines to the nano editor:

/dev/sda1 /media/USBHDD1 auto noatime 0 0

/dev/sda2 /media/USBHDD2 auto noatime 0 0
  • To exit, hit CTRL+X, then Y to save and replace the existing file.

If you’re only utilizing a single hard disc for basic network sharing with no redundancy, that’s it. You’ve completed the configuring process and are now ready to use your ultra-low-power NAS.

Configuring Your Raspberry Pi NAS for Simple Data Redundancy

So far, our Raspberry Pi NAS is connected to the network, and file transfers are working, but there’s one major flaw. Although the secondary hard disc is configured, it is now unusable.

This tutorial section will configure our Raspberry Pi NAS to conduct a nightly data mirror from the /shares/ folder on the primary drive to the /shares/ folder on the secondary drive using two basic but powerful Linux programs, rsync and cron. Although this isn’t a real-time RAID-like data mirroring solution, a daily (or semi-daily) data backup to the secondary drive is an excellent approach to add another layer of data security.

  • First, we must install rsync on our Rasbian system. If this is your first time using rsync, we recommend reading How to Use rsync to Backup Your Data on Linux to understand the command better.

Enter the following command at the command prompt:

sudo apt-get install rsync
  • After you’ve installed rsync, you’ll need to create a cron job to automate the process of moving files from USBHDD1 to USBHDD2. Enter the following command at the command prompt:
crontab -e
  • The command will open your cron scheduling table in the nano text editor, which you should be familiar with by now. Scroll to the bottom of the page and type the following line:

0 5 * * * rsync -av --delete /media/USBHDD1/shares /media/USBHDD2/shares/

This command tells rsync to compare the two directories every day at 5:00 AM (the 0 5 part), every single day (* * *, wild cards in the year, month, and day spots), and delete anything in the backup directory that no longer matches something in the primary directory—for example, if we delete a movie file on HDD1, we also want that file to be removed from the backup on the next synchronization.

The most crucial component of establishing this command is choosing a time that does not conflict with any other planned network activities to shared folders. Suppose you’re using your Raspberry Pi NAS as a backup destination for some automated software that copies your files to the NAS at 5 AM every morning, for example. In that case, you’ll need to adjust the backup time in your backup software or the time for the cron job on the Pi—you can’t have both the remote backup dumping data onto the network share and the Raspberry Pi trying to sync that data between local drives at the same time.

To leave and save the file after entering the crontab entry, press CTRL+X. If you want to execute the rsync right away to have the data duplicated faster and make the initial cron job a little lighter on the system, type the same rsync command into the command line as you did in the crontab:

rsync -av --delete /media/USBHDD1/shares /media/USBHDD2/shares/

That concludes our discussion. All that’s left to do now is check in on your Raspberry Pi in the next day or two to ensure that the scheduled process is running as predicted and that the data from /USBHDD1/shares/ is showing up in /USBHDD2/shares/.

Everything you put into your Raspberry Pi-powered NAS from now on will be mirrored every day across both hard drives.

Conclusion

I hope you found this information helpful. Please fill out the form below if you have any queries or comments.

User Questions:

  1. Is it possible to use a Raspberry Pi as a network server?

It’s simple to set up a Raspberry Pi as a Samba file server for storing backups and sharing data with other computers on your network. You may swiftly copy files from a computer on your network to a Raspberry using wireless LAN if Samba is enabled (or a direct Ethernet connection).

  1. Can I run a network server on a Raspberry Pi?

It’s simple to set up a Raspberry Pi as a Samba file server to store backups and share files with the rest of your network. You may swiftly copy files from a computer on your network to a Raspberry using wireless LAN if Samba is enabled (or a direct Ethernet connection).

  1. Can I build my network-attached storage (NAS)?

It is feasible to buy a prebuilt NAS, but the costs can quickly escalate depending on the needs and features. Still, if you’d rather work on a fun project or want to customize your system (which is better for streaming and other demanding operations), you can build your own NAS.

Also See:  How to: Fix ACPI BIOS FATAL ERROR Error in Windows 10
  1. Raspberry Pi 4 as a NAS starter?

Raspberry pi 4 as starting NAS? from homelab

  1. I have a raspberry pi and an external hard drive; how do I start?

I have a raspberry pi and an external hard drive, how do I start? from DataHoarder