Here we go folks. Complete, yet half-baked documentation on how to setup your very own home NAS using free Linux software. I know this has been written about before, and in fact I have pulled from many fine sources (see my acknowledgement below). This is documented here mainly so I don’t forget how I did this. It’s not really for you – sorry internet. Let’s get started:
Step 1: First, goto ubuntu.com and download the latest ISO for ubuntu server. Today I’m using Ubuntu Server 11.10 64-bit. Burn the CD, create a bootable USB, whatever suits you best. I chose to use a bootable CD, easy.
Step 2: Select a boot device for your NAS. In my case, I’m selecting a 16GB Lexar USB flash drive. It’s really low profile and will plug right into the back of the system without any clutter. It’s so tiny that it doesn’t run the risk of being bumped or dislodged from the back of the system. No need to buy an expensive HDD to add to the system. With USB flash drives with huge capacity being so ubiquitous and inexpensive, it was an attractive option.
- 1.5TB HDD (/sda)
- 1.5TB HDD (/sdb)
- 16GB Lexar USB (/sdc)
I configured the 16GB Lexar USB drive first, since it is essentially my boot drive. I made this drive primary, set the mount to /, set the file system to ext4 and made it bootable. (later you’ll need to go into your BIOS setup to ensure that this device is in your boot device list such that it auto-boots to this device) I used the entire 16GB of this drive for root. Note: It’s probably a really good idea to have your server restart after a power outage, so poke around in your BIOS settings to setup this behavior. Usually it called “After G3 Enable”, or sometimes BIOS screens are a little less cryptic and actually state behavior after power-loss.
I configured the RAID as RAID 1 (mirroring), with two drives (members), as you can probably guess the 1.5TB HDD’s. Ubuntu uses mdadm which I happen to be fairly comfortable using, but it’s awful nice that they will help you setup these devices upon install of the OS. After installation you’ll find your array at /dev/md0 happily synching (hopefully) and you can check this via this command:
mdadm -D /dev/md0
Time to install some software packages. Again, also super nice, makes things easy to get started. Here’s what the screen looks like (apparently there is bug in Ubuntu 11.10 which causes an extra option to show up called Ubuntu usb or something of that sort – ignore that).
I chose OpenSSH, LAMP, and Samba for my server. You may have other needs. Follow the prompts and finish the installation. This may take ages… I’m pretty impatient, but wow. It’s probably due to the fact that I was installing from a CD to a flash drive. Slow reads and writes.
Step 4: Once you’ve rebooted, it’s time to do some house cleaning and getting things setup. Here’s what I did:
Configure a Static IP Address
(excerpt found here: https://help.ubuntu.com/11.10/serverguide/C/network-configuration.html)
To configure your system to use a static IP address assignment, add the static method to the inet address family statement for the appropriate interface in the file /etc/network/interfaces.
sudo nano /etc/network/interfaces
The example below assumes you are configuring your first Ethernet interface identified as eth0. Change the address, netmask, and gateway values to meet the requirements of your network.
auto eth0 iface eth0 inet static address 10.0.0.100 netmask 255.255.255.0 gateway 10.0.0.1 dns-nameservers 188.8.131.52 184.108.40.206
By adding an interface configuration as shown above, you can manually enable the interface through the ifup command.
sudo ifup eth0
Update all software packages:
Open the sources.list file and uncomment any sources that you may want to use. I found that with 11.10, it had defaulted to pretty much everything I wanted (including multi-verse, etc. )
sudo nano /etc/apt/sources.list
To update the apt package database with the latest software lists type the following command:
Then to install all the latest updated packages (if there are any) type this command:
Mount the RAID Array and Make it Persistent (show up after reboot)
MDADM is a great, solid solution for RAID under Linux. Now, since we have already configured a RAID array during the server install (and hopefully it is done syncing – see the display status command above), we can simply format and mount the array. More details can be found in one of my previous posts or in this article form the How-to Geek.
Format the newly created RAID array:
sudo mkfs -t ext4 /dev/md0
Create mount pount:
sudo mkdir /mnt/sharename sudo chmod 777 /mnt/sharename
Add it to /etc/fstab:
sudo nano /etc/fstab
Add the following line to the end of the file:
/dev/md0 /mnt/sharename auto defaults 0 0
Configure Windows File Sharing (a.k.a. Samba, SMBD or CIFS)
The heart and soul of your new NAS will likely be Windows file sharing, which allows your other PC’s in the house (Mac, Linux, Android, Windows, etc.) to access your files over the network (that is unless you want to setup NFS, which is probably better, but likely only for the Linux users out there). I found this article very helpful on the Ubuntu website.
Open the samba daemon configuration file for editing:
sudo nano /etc/samba/smb.conf
Create a new section at the bottom of the file, or uncomment one of the examples, for the directory to be shared:
[sharename] comment = Ubuntu File Server Share path = /mnt/sharename browsable = yes guest ok = yes read only = no create mask = 0755
Now that Samba is configured, the directory needs to be given ownership and the permissions changed. From a terminal enter:
sudo chown -R nobody:nogroup /mnt/sharename sudo chmod -R 755 /mnt/sharename
Finally, restart the samba services to enable the new configuration:
sudo restart smbd sudo restart nmbd
Startup / Shutdown Beep (Needs Update)
Normally your server will likely be running headless (with no monitor attached). And in this case it’s nice to have some kind of audible beep to indicate when a system is either shutting down or has started up (and is ready). This is the part where I tell you that it should be simple. Unfortunately I have yet to get this to actually work on my server. I know my PC Speaker is working (the BIOS beeps on startup), but I cannot get these instructions to work for me. Your mileage may vary. (leave me a comment if you have any clever ideas)
sudo apt-get install beep
Other Useful Terminal Commands
Check the status of your RAID Array:
sudo mdadm -D /dev/md0
Reboot your server:
shutdown -r now
Check your memory usage. Remember, since we omitted a SWAP partition, we need to make sure that we’re not dangerously close to overflowing system memory.
Don’t freak out if your system memory is fully utilized. Linux is pretty heavily optimized to utilize the actual free memory as a file cache. So if you subtracted the “cache” size from the used memory size you’ll get your actual used memory.
Additional Considerations If converting from FreeNAS…
I had backed up all of my data onto an external USB HDD on Freenas v0.7.2 (Sabanda) to transfer to the RAID array after it was setup. FreeNAS 0.7.2 uses UFS and doesn’t really support EXT4 which is what really wanted to use, but luckily my ubuntu server also supports UFS. For mounting A UFS partition from a FreeNAS 0.7.2.5543 (Sabanda)box based on FreeBSD 7.2, enter the following in your terminal:
sudo mount -r -t ufs -o ufstype=ufs2 /dev/sdx1 /media/usbDrive/
Stayed tuned for our next next installment, which will cover additional software installation like Web UI, Subsonic, Transmission (bittorrent), etc.
Resources & Citations
The internet helped me greatly in completing this project. The following sites were referenced above but are compiled here for quick access.