The next step to making your DIY NAS serve its purpose is to format and add those hard drives (HDD) to the system. You have them all plugged in the different SATA ports and so now it is time to make your operating system acknowledge them and make use of them. For this guide, I will only be going through the steps to format the HDD by itself and not make use of any RAIDs. RAID will be discussed in a later part. Once the drive is formatted and mounted, I will then go on to show you how you can set up your Samba File Server to start serving up those files to your network. Read on to continue the guide. All of this might be a tedious job to execute, especially with HDDs, which are delicate pieces of technologies. Such hindrances have led the storage industry into developing a new game changer: Hybrid Cloud Architecture: What Is It and Why Should You Care.
Partitioning, Formatting and Mounting of Hard Drive
First thing first, you will have to format the drives that you have hooked up to the system. The way you want to partition it is ultimately up to you but for the ease of explanation I will simply format and partition the HDD into just one partition. The drives will be formatted to ext4 and the reason why Iâ€™ve chosen such a file system is mainly due to the fact that it has the best balance between stability as well as performance. You can google up the different file formats and read the different advantages and disadvantages. In fact, you can format it to whichever file format that you are more comfortable with.
We will now have to find out what drives we have and what their drive letters are. The first command you want to type is:
sudo fdisk â€“l
Now take note which is your system HDD, it should already be formatted and partition as seen (yours may vary should you decide to partition it in a different way at the start):
Taking note of the drive letter of your HDD (/dev/sd* where * is the letter of your HDD. For this guide the HDD is sdb) you will want to continue to format it using the utility fdisk (if your HDD is larger than 3TB you will have to use the utility gdisk instead):
sudo fdisk /dev/sdb
Next to start partition and formatting your drives you will type â€œnâ€ and press enter. You will then see the choices you can make and what you will want to do is to type â€œpâ€ to create a primary partition. Since this is the only partition, type â€œ1â€ and enter. Now it will ask you about the first cylinder, basically asking about the size of the partition. Simply hit â€œ1â€ and enter as that will tell the system to use up everything on the HDD. Now that you have told the system what partition you want, you can now confirm your input and make it write the partition table by typing â€œwâ€ and enter. It should tell you that the partition table has been altered.
You should now have a properly partitioned HDD and since its the first and only partition, it will be recognized as /dev/sdb1 by the system. (You can confirm this by listing your drives again) You will now want to format the partition to the file system that you want. To do this, type:
sudo mkfs â€“t ext4 /dev/sdb1
It should format the partition and the partition will soon be ready to be used. Â What you will need to do next is to mount the partition to a particular place. This mounting process is basically to tell your system where to access the drive. To do that you will want to create a new folder. You can do this anywhere but preferably under /media as it is the default location used by Ubuntu. You will want to make a directory by using the command:
sudo mkdir /media/drivename
With the directory created, you will now want to mount the drive. To make sure the system automatically mounts the drive every time it boots you will want to follow these steps:
First type â€œ
sudo blkidâ€. Find the UUID that matches your drive. For /dev/sdb the UUID is â€œâ€ Next enter the following command:
sudo nano /etc/fstab
Add the following line (replacing UUID with the actual UUID of your drive):
UUID /media/drivename ext4 defaults 0 2
Once done exit and save the file. You can reboot the system to see if the drive mounts or you can type â€œsudo mount â€“aâ€
Setting Up Samba File Server
First you will want to get the files for the Samba server and install it:
sudo apt-get install samba
Once done, we will now be editing the server settings to achieve a common shared storage among all approved users. For now, we will edit the Samba configuration file:
sudo nano /etc/samba/smb.conf
There are many different options and settings that you can adjust in the configuration file. You can read up more of the individual configurations on your own but as for now, I will simply guide you to getting the file server working. Head all the way down the file till the end and start typing the following:
writeable = yes
path = /media/primary
force group = nas
valid users = @nas
create mode = 0664
directory mode = 0775
What this will do is identify the path as of which will become a network share as well as set it up such that all users under the group â€œnasâ€ will be able to access and use it. This in a way creates a shared space for all approved users. All files created will also bear the group â€œnasâ€ so as to allow all approved users to view the files. You can edit the settings respectively to suit your own needs.
Once done, save it and exit out. Now what you want to do is to â€œcreateâ€ a samba user. Do note that Samba maintains its own user management outside of the operating system. You will thus have to add users into the Samba system aside from adding into Ubuntu. For example you already have a user â€œswiftâ€ created, you will still have to add the user again and define the samba password for the user by the command (the â€œ-aâ€ means create new user):
sudo smbpasswd â€“a swift
Enter the password you desire and then once youâ€™re done, you have successfully created a samba login for yourself! All you will have to do now is to restart the samba server by typing:
sudo service smbd restart
Note: you will have to add your user (Ubuntu side) to whichever group that you have allowed in the configuration so for the example in this guide, you will have to add â€œswiftâ€ into the group â€œnasâ€. This can be done by typing:
sudo usermod â€“G nas swift
sudo usermod -a -G nas swift
You should have the group created before you start adding the users into it.
You can play around with the permissions and settings to create private spaces and folders for particular groups of people or individuals. For simplicity, Iâ€™ve simply created a shared storage space for all approved users to access and use.
There you go! The DIY NAS is all set up and ready to rock and roll.
Updated (21/10/13): Corrected command from “sudo usermod -G nas swift” to “sudo usermod -a -G nas swift”. This will prevent you overwritting any exisiting groups the user belongs to. The “-a” will modify the command into adding the new group rather than overwritting the existing groups. Thanks Willis Pilarte for pointing that out!