This is part of our series on building a NAS. In this article we will get the box set up with a static IP address, and get your drives set up for RAID 1.
We are assuming that at this point you have Ubuntu installed. We are gong to install software raid in a moment. The first thing I want to do is make sure we have a static ip address. Usually Ubuntu will start up with a dynamic ip address. This can make it more difficult to transfer files to this box, so lets make it static.
Setting a static IP address
Type ifconfig eth0, and you will see your current address.
Lets make it static. Note, typing sudo in front of commands lets you assume the privileges of the administrator, or super user.
sudo nano /etc/network/interfaces
We will replace the text there with this text, which will assign 10.0.0.50 to our server, and assume the gateway is at 10.0.0.1:
auto eth0 iface eth0 inet static address 10.0.0.50 netmask 255.255.255.0 network 10.0.0.0 broadcast 10.0.0.255 gateway 10.0.0.1
restart the network to get the new settings :
sudo /etc/init.d/networking restart
ifconfig eth0 and you should see the new settings.
If you want to see a whole lot more networking commands, see here.
Finding out drives
Great. Now before we can put two drives into a RAID 1 array, we need to tell linux what drives we are going to use for this.
How do we know what disks? I just type dmesg. This will scroll lots of stuff down the screen. If you are in the GUI at a terminal you can scroll. Otherwise type dmesg | less which will let you move through the text with the cursor keys.
This is all the hardware that was found and initialized. You will first see the ataX with X being the number of the drive. You need to look for a section after this that has letters like hda or sda. The drives I am using are SATA drives and they are sda and sdb. I could tell by the size of the drives. (press Q to exit less if you need to)
Partition¬†for Raid 1
Ok, lets tell Linux that we want those drives to be used for raid.
sudo fdisk /dev/sda
[p] will list the partitions. If you had one previously, you will see it. Remove them. Press d for delete, then give a partition number. (no need if you only had one)
Now add a [n]ew [p]rimary partition number  with default start and end (the whole disk)
n [enter] p [enter] 1 [enter][enter][enter]
Now [p] again to verify that the partition is there. Note the type: 83. Type [l] to see all the types. We need to set the type to fd for Linux software raid.
t [enter] fd [enter]
Now write the partition table and exit: w [enter]
Now we repeat the process with the other drive.
sudo fdisk /dev/sdb
And repeat the fdisk commands.
Setting up mdadm for Raid1
Ok, now for Linux software raid. First we need to install it.
sudo apt-get install mdadm
When I did this, I was prompted that citadel-server was being installed. This is what is used by default as the mail server. Mdadm is dependant on a mail server so it can mail you of failures. Pick an admin user and say no to external auth.
Once installed you can build an array. I am going to use two drives in a RAID 1, mirrored setup. This duplicates all the data on both drives. They are mirrored. This is the command with my drives used. You will substitute for your devices:
sudo mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 /dev/sda1 /dev/sdb1
This should tell you that the array /dev/md0 has started.
If you would like to see when the array is built:
This will tell you how long it will take, or if it is done.
Ok, that’s it for now.¬† We will look at commands to manipulate the array in a later article in the series. Next up will be creating the resizable volumes on the array using LVM.