Setting up a NAS using Ubuntu server
My
quest (or rather, sick obsession) in getting an affordable and flexible
NAS solution has taken me through more builds than I’d care to
remember. I’ve tried FreeNAS, Vortexbox and Openfiler.
I’ve sworn, kicked the dog and sobbed inconsolably till I finally gave
up and decided to go the full hog and commit to using Ubuntu Server
edition. Granted, the other solutions can probably work, but the
thought of committing time to something only to find out it’s not 100%
perfect for my needs put me off. This is after having lived with FreeNAS for some time. I kinda figured if I’m going to commit the time then I can just as well do it properly!
So,
I settled on Ubuntu Server. After installing it for the first time, I
was greeted by a login prompt after it booted up. Entering my
credentials rewarded me with a CLI and that’s it. I just knew I was
going to be in for a lot of coffee and late nights…
After
many iterations and experimenting, I’ve managed to come to a
combinations of features I needed and also included some nice ones from
other packages as well.
Here’s a breakdown of what I have so far:
- Ubuntu Server 10.10, installed on a USB flash disk
- Installation tweaked to make best use of flash disk limitations
- System can be managed remotely using SSH or Webmin
- RAID 5 storage pool
- Fully fledged SAMBA server, serving files up at network linespeed
- SqueezeboxServer loaded
- Host for all music and video files
I
still need to spend some time getting the UPS integrated, this will
happen as soon as I’ve got some time (read energy) to spend on this
again.
I’ve
decided to put a little How-To guide together to document what I’ve
done, so figured I’d share it here for everybody else’s benefit as
well. This is by no means a complete document, but it should be enough
to get you going. Believe me, if I can figure this stuff out then it’ll
be childsplay for
anybody else ;-) Much of the info here was collected from various
sources on the web. It does make sense though to keep it all together
for a configuration like this.
So,
here we go. I’ve tried to be as concise as possible and give step by
step instructions, but would welcome any suggestions and feedback to
improve this. Also, there may be many things here that can be done in a
better way. Again, all suggestions welcome so we can all benefit! Also,
my HTML skills suck, so the first guy to comment on how crap this all
looks will be shot.
Install Ubuntu Server on flashdisk
First
things first, make sure you have a bootable USB drive inserted and is
picked up by the BIOS. Also, make sure it's at least 2GB. Because of
GRUB being installed, it’s super important to make sure that any other
hard drives are disconnected!!! It’s got a nasty habit of installing
itself where it feels like and this can mess you around to no end! Only
the CD Rom and USB flash drive should be connected.
Insert Ubuntu Server CD and Boot
Select "English"
Select "Install Ubuntu Server"
Select "English" (Again)
Select "South Africa"
Select "No" to detect Keyboard type
Select "USA" layout (twice)
At
this point you want the installer to look for a DHCP server to
configure the network. We can change it for a static IP later, but
doing it this way makes setup so much easier.
At the hostname prompt, enter something suitable (like Ubuntu ;-))
Select the default timezone of JHB/Africa
On Partitioning, select the "Guided - use entire disk and set up LVM" option
Make sure that the installer detects the USB flash disk
If the disk is not clean, it'll prompt you that whatever is on there will be overwritten.
You'll be prompted to allow the installer to write Partitioning info to the disk
Type in "max" to use the whole flash disk
You will again be asked to permit the changes to be written to disk.
The installation will take some time to complete...
When prompted, enter your name, followed by a username
You will also need to enter password details (twice) for the user
Don't encrypt your home directory
If you are running a proxy for HTTP, you need to enter these details.
More waiting...
I suggest you don't enable Automatic updates, but proceed at your own risk
Still more waiting...
Select "Samba file server" as the intended server type.
Even more waiting...
Install the Grub Bootloader
Once done, the initial installation is complete and you'll be prompted to do a restart.
Once restarted, the system will boot into the Ubuntu login prompt. Enter your credentials as given at installation.
Install Webmin
The Webmin package is not part of the default Ubuntu install, so we need to add the package to the source list. Type in “sudo nano /etc/apt/sources.list” to open the source list file. Once opened, add ”deb http://download.webmin.com/download/repository sarge contrib” at the end of the file and save.
Next enter the following commands:
sudo apt-get update (May come up with an error that the signatures can't be verified - just ignore)
sudo apt-get install webmin (May warn that some packages can't be authenticated - just ignore)
CTRL+ALT+DELETE to restart.
Once rebooted, Webmin can be accessed from https://<ipaddress>:10000. You can login with your default credentials.
Install RAID (and other) capability
sudo apt-get update
sudo apt-get install openssh-server mdadm perl openssl samba
Select "No configuration" when prompted under Postfix Configuration
CTRL+ALT+DELETE to restart.
Move temp & log folders to RAM and configure for less IO to flash
Type in “sudo nano /etc/sysctl.conf” to open the /sysctl file. Once opened, add “vm.swappiness=10” at the end of the file and save.
Next step, open the /fstab file by typing in “sudo nano /etc/fstab”
At this point, you’ll only have the one disk in the system (your flashdisk), so look for the line below and make the change highlighted:
UUID=559c5376-7cc2-441d-bd31-27b901fb6928 /boot ext2 noatime,defaults 0 2
Also, add this to the end of the file. This will force the system to keep temp and log files in memory, thus limiting writes to flash disk.
tmpfs /var/log tmpfs defaults 0 0
tmpfs /tmp tmpfs defaults 0 0
tmpfs /var/tmp tmpfs defaults 0 0
And finally, open the grub configuration file by typing “sudo nano /etc/default/grub” and change the line below:
GRUB_CMDLINE_LINUX="elevator=noop quiet"
Commit the changes by typing “sudo update-grub”
Installing Squeezebox Server
As with Webmin, SqueezeboxServer is
not part of the standard Ubuntu distribution, so the best way to make
it so is to include it in the sources list. So, open the sources file
again by typing “sudo nano/etc/apt/sources.list” and add the following to the end: “deb http://debian.slimdevices.com stable main”
And then run the install:
sudo apt-get update
sudo apt-get install squeezeboxserver
After lengthy install process, it will ask (3 times!) for a default MySQL password. Leave this blank.
After the install is done, you can access the SqueezeboxServer from http://<ipaddress>:9000.
Once you are done, clean up to make a little space
sudo apt-get clean
Manually Set IP address
Type in “sudo nano /etc/network/interfaces” to open the file and then change as below:
auto eth0
iface eth0 inet static
address xxx.xxx.xxx.xxx
netmask xxx.xxx.xxx.xxx
network xxx.xxx.xxx.0
broadcast xxx.xxx.xxx.255
gateway xxx.xxx.xxx.xxx
Also need to update DNS:
Type in “sudo nano /etc/resolv.conf” and enter as below:
name server xxx.xxx.xxx.xxx
If you not planning on using DHCP, you should remove the client:
sudo apt-get remove dhcp3-client
And when you done, you need to restart the network:
sudo /etc/init.d/networking restart
Shutting down
Should you need to shut the NAS box down, you can enter this:
sudo shutdown -P now
Now for the next big step, using Webmin
Open Webmin by entering https://<ipaddress>:10000.
Firstly, whenever any software is installed after Webmin, it is recommended to "Refresh Modules" to make all features visible.
Adding Disks -> RAID
Click "Hardware" -> "Linux RAID"
Select RAID level and then click "Create RAID device"
Select the drives under "Partitions in RAID" to use in the RAID pool (by using CTRL+Click)
Click "Force init of RAID" and then "Create".
The Array will now be created and will take some time to complete.
Once complete, open Array (at the top) and Create an ext3 partition on the Array.
Creating a mountpoint and mounting
There's
many ways to do this, but I chose the least secure way of doing it,
seeing as it's much simpler this way and there's no security threats in
my household...
Click on "Others" -> "File Manager". If prompted to load a Java applet, click "Yes" and ignore security warnings.
Once
open, create a new folder in the root folder and call it something
creative, like "data". (There's a few "New" icons, make sure to select
the blue folder icon)
Select
the newly created folder in the right hand pane and then click on
"Info". Because this is not meant to be a secure server, enable write
permissions for all checkboxes and click "Save"
Go to System, Disk and Network Filesystems. Select "Linux Native Filesystem (ext3)" partition in the dropdown and then click on "Add Mount"
At "Mounted As" select the browse button and then double click the folder created earlier. ("data" in my case)
At "Linux Filesystem" select the "Other device" radio button and then click the browse button. Navigate to "/dev" then "/md0" and select it.
Click on the "Create" button at the bottom of the page.
Sharing the mountpoint
Navigate to Servers->Samba Windows File Sharing
Click on "Create a new file share" and give the share a name.
At "Directory to share", click the browse button and double click the folder created above.
Once created, select your share again and then click on "Security and Access control".
Click on "Writeable" "Yes" and make the "Guest Access" "Yes" and then click "Save".
Click on "Folder Permissions" and then at "Force Unix user" select "root" by clicking on the browse button.
Click on "Save" and then "Save" on the page you went back to.
To test that the drive is visible, on the Windows PC select "Start" then "Run". In the "Run" dialog, type in the IP address of the NAS box.
A
window should pop open with the share name. Double click on it to open
then copy a file into it to make sure you've set your permissions
correctly.
If all went well, you should have the file copy without problem, showing that your NAS is now ready.
Simply map the NAS to a network drive and you all set.
Additional misc features to add
Install power saving
Go to the CLI and type in “sudo nano /etc/modules” and then add:
acpi-cpufreq
Type in “sudo nano /etc/rc.local” and then add:
/usr/bin/test -e /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor && /bin/echo conservative > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
/usr/bin/test -e /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor && /bin/echo conservative > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor
/usr/bin/test -e /sys/devices/system/cpu/cpu2/cpufreq/scaling_governor && /bin/echo conservative > /sys/devices/system/cpu/cpu2/cpufreq/scaling_governor
/usr/bin/test -e /sys/devices/system/cpu/cpu3/cpufreq/scaling_governor && /bin/echo conservative > /sys/devices/system/cpu/cpu3/cpufreq/scaling_governor
exit 0
Disable logging in Webmin
"Webmin" -> "Webmin Configuration". Click on "Background Status Collection" and then switch off both options.
Click Save.
References:
http://members.iinet.net/~herman546/p19.html