NAS Part 2: Setting up Ubuntu Server 12.10


Like i said in my previous post (DIY Network Attached Storage) a Network Attached Storage (NAS) is useless without some software to run it all. In this post i’ll explain what software i use and how i installed it.

Tutorial / Howto

This post is not it intended to be a straight up tutorial as the whole process is specific to my setup. However, most of these steps are easily tailored to your specific situation and variables. I’ve changed a few things along the way like usernames and passwords, you will have to substitute those for your own username and password. This post is chronological and if you intend to read it as a tutorial, you will need to execute every line of code and make changes where needed.

Media

On my NAS i like to keep my media and Operating System (OS) physically separated, installing an OS may take some time but re-populating my harddrives with media takes a whole lot longer. I’ve installed my OS on a USB Flash drive, which has one big downside: they fail. Flash memory has a limited amount of times it can be rewritten depending on the quality of the Flash memory chips. The upside however is that you can use all the space on your actual harddrives for audio, video, books etc. and 8GB USB Flash drives are rather cheap, too.

Operating System

My environment of choice for any type of server has been Linux for well over 15 years. All major Linux distributions have a large communities behind them and there’s loads of information to be found on their various forums to help you out in case you get stuck and need help. I’ve started off with Redhat, made a brief pitstop at SuSe and eventually moved on to Ubuntu.

The OS for my NAS is going to be the very latest stable release of Ubuntu Server 12.10. I’ve downloaded the file to my desktop and had to get it onto another USB drive to install it from since my NAS doesn’t have an optical drive. To install Ubuntu (server or desktop) from a USB drive you need to prepare the USB drive. How to do so using Windows is explained on Ubuntu’s website.

Since my main computer runs Apple’s OS X Mountain Lion (10.8.2), i used Ubuntu’s OS X version of the same guide to create a bootable USB Drive. After the file has been downloaded in a convenient place, open up the terminal to convert the ISO file into an IMG file:

hdiutil convert -format UDRW -o ~/Desktop/ubuntu-server.img ~/Desktop/ubuntu-12.10-server-amd64.iso

Check the outcome of that process as OS X tends to add .dmg to the filename. Luckily this can be easily remedied:

mv ~/Desktop/ubuntu-server.img.dmg ~/Desktop/ubuntu-server.img

We then clone the image to a USB drive, in my case a 2GB unit. Use “Disk Utility” to find the Disk Identifier assigned to my USB drive.

As can be seen in the above picture the Disk Identifier is “disk4″ (this is probably different on your computer!). Unmount the drive (do not eject it!) and move onto cloning “ubuntu-server.img” onto the flashdrive:

sudo umount /dev/disk4
sudo dd if=~/Desktop/ubuntu-server.img of=/dev/rdisk4 bs=1m

Once this step has finished you can eject and remove the USB Drive and plug it into the NAS, boot from the USB drive and start the installation. The installation is pretty straight forward and i won’t waste too many precious pixels on it. The only thing i did during the install besides filling out computernames, usernames, timezones and keyboardlayouts, was putting checkmarks in openSSH and SaMBa box so that they would be installed from the start. SSH makes it possible to access a computer remotely with a login and password so it doesn’t need a monitor and keyboard connected to it and SaMBa is the most common protocol to share files and folders across local networks with other computers.

After the install finished i checked the SSH connection from my Mac and then removed the keyboard and monitor from the NAS.

ssh username@192.168.2.17

Covering my bases

The first thing i do after any OS install, is making sure i’m up to date before i start installing other programs and applications. In my case Ubuntu Server even reminded me that:

28 packages can be updated.
2 updates are security updates.

In other words, time to update and upgrade.

sudo aptitude update
sudo aptitude upgrade

Incomplete Locales

During a package install (unrelated to this post) i noticed that the Locale’s weren’t set properly or at all. To prevent a lot of confusion and malfunctioning applications (SabNZBd+ for instance doesn’t like a missing locale setting one bit) i set out to correct the issue.

First we identify the unset locales by running:

locale

In my case “LANGUAGE” and “LC_ALL” didn’t have a value assigned to them so i generated the actual locale files and set the locale settings.

locale-gen en_US.UTF-8
sudo dpkg-reconfigure locales

Then i edited “/etc/default/locale” with Nano by adding the two missing locale settings to the end of the file.

sudo nano /etc/default/locale

And the added parameters:

LANGUAGE="en_US.UTF-8"
LC_ALL="en_US.UTF-8"

Press “control+x” to close Nano and “y” and “return” to save the changes you just made. Reboot and be done with it.

Mounting partitions

Because my disks were detached when i installed the OS (for safety reasons), i have to mount them myself. Being a Mac user i like finding my physical volumes in the “/Volumes” folder. Ubuntu however doesn’t have that folder by default so i made it myself:

sudo mkdir /Volumes

And then made subfolders to link each disk to:

sudo mkdir /Volumes/drive1
sudo mkdir /Volumes/drive2

Obviously you can be as descriptive as you want to be but keep in mind to keep it simple.

Mounting alien filesystems: HFS+

Most filesystems can be easily mounted and used with Ubuntu, the drives in my NAS however were used in my Mac before and are therefor formatted as HFS+. HFS+ is similar to Linux native filesystems like EXT but different enough for Ubuntu not to like them too much. Generally it can read HFS+ partitions but can’t write to them. To make it possible for Ubuntu to write to HFS+ partitions we need to install HFSTools and a few packages it requires:

sudo apt-get install hfsplus hfsprogs hfsutils

Next we figure out what the drives and partitions are named by Ubuntu. Typically they consists of a device identifier and partition number.

ls -lah /dev/disk/by-partlabel

This will give you a list of disks, their labels and their identifiers. In my case i had 2 drives and one of those had a hidden (apparently) volume, their identifiers are sda2 and sdb1 where sda and / or sdb is the device identifier and the number stands for the partition.

Now you run a filesystem check just to make sure the partitions are healthy and will not cause any problems later on:

sudo fsck.hfsplus /dev/sda2
sudo fsck.hfsplus /dev/sdb1

Once the partitions have been checked you can manually mount the drives and test if they can be written to:

sudo mount -o force -t hfsplus /dev/sda2 /Volumes/disk1
cd /Volumes/disk1
touch test.txt
ls

Everything executed without problems and the “ls” (list) command showed us a empty file called test.txt that we created with “touch”. Remove test.txt and run the same commands to mount and test the second harddrive.

rm -rf test.txt
sudo mount -o force -t hfsplus /dev/sdb1 /Volumes/disk2
cd /Volumes/disk2
touch test.txt
ls
rm -rf test.txt

Automounting with FSTAB

Mounting the drives manually proved to work, but you really don’t want to have to do that every time the NAS is rebooted. That’s where “FSTAB” comes in. The fstab configuration file can be found in “/etc/fstab” and basically holds all the necessary information to reliably mount the different devices and partitions when you (re)boot the system.

sudo nano /etc/fstab

You will see a few lines with what seems to be just a bunch of random numbers. They are however UUID’s, the only identifiers linked to partitions that will not change unless the drive is repartitioned. Exit Nano (control + x) to figure out which UUID is linked to the partitions.

ls /dev/disk/by-uuid/ -alh

Write down the UUID numbers associated with the partitions and open up “/etc/fstab” for editing:

sudo nano /etc/fstab

To add a line to this file you will have to adhere to a strict format, otherwise the system will have no idea what you meant to do. The proper syntax is:
[partition identifier] [mounting location] [filesystem] [options] [dump] [fsck order]

The “partition identifier” is pretty straight forward. By default it expects a partition identifier similar to “/dev/sda1″. However, i recommend using UUID’s and therefor you will have to use a syntax similar to “UUID=1234-mumbojumbo-uuid-7890″ instead.

“Mounting location” is basically one of the folders we made earlier on, /Volumes/disk1 or /Volumes/disk2. The “filesystem” bit is self explanatory as well, “hfsplus” will work for mine. There are a bunch of “options” including:

  • R – read-only
  • RW – for reading and writing
  • force – to suppress Ubuntu’s concerns and force it into submission
  • auto – required to automatically mount the drives on startup
  • users – creates access to the nas for other users in the same group

The “dump” option has apparently something to do with backups. I haven’t read up too much on the subject but i’m not too concerned with it and set it to 0. The last “fsck_order” option determines the order in which the filesystems are checked during boot, mine are both set to 1.

All in all this results in the following two new lines at the bottom of my “/etc/fstab”:

UUID=4c0ae1d4-5e0a-3f67-9b7b-7f910fb271da /Volumes/disk1 hfsplus force,rw,users,auto 0 1
UUID=541dd3a0-b89e-39bb-a91f-7f15d477ce4f /Volumes/disk2 hfsplus force,rw,users,auto 0 1

Save the file, unmount both of the partitions manually and do an auto-mount much like they happen during boot:

sudo umount /Volumes/disk1 /Volumes/disk2
sudo mount -a

From now on Ubuntu will mount the two media partitions during boot.

To read a little more about setting up fstab, read this topic on the Ubuntu Forums: How to fstab by user “bodhi.zazen”.

SaMBa

Now it’s time to actually connect this storage to the network by setting up SaMBa. Most of it was actually set up when we chose to install SaMBa during the OS install. All you have to do now is define what you want to share on the network, who you want to share it with and how much control they get over it.

The only file we need to edit is “smb.conf” which can be found in “/etc/samba/”:

sudo nano /etc/samba/smb.conf

First off i wanted a little security so not just anyone attached to the network could gain access to my files without my approval. Find the line where it says:

# security = user

By uncommenting this line (remove the hashsymbol / # so it reads just “security = user”) you implement an authentication protocol that requires anyone requesting access to the SaMBa shares to supply a login and password tied to an active user on the NAS.

Next i defined a share

[MyShare]
comment = My Share
path = /Volumes/disk1/
browseable = yes
guest ok = no
readonly = no
create mask = 0755
directory mask = 0755

In the above example i define a share that is visible to the network as “MyShare”. While “comment”, “path”, “guest ok” and “read only” are self-explanatory, “browseable” and “create mask” / “directory mask” need a little extra explanation. “Browseable” makes the share visible to guests viewing the shares on the NAS, it is however inaccesible until a user logs in with a valid username and password combination. “Create Mask” and “Directory Mask” simply defines some very basic rights that are automatically applied to all files and folders a logged in user makes in that particular share.

Once you have defined all the shares you need all you need to do is restart the SaMBa (smbd) and Network Message Block daemons (nmbd) to activate the new shares and broadcast them to the network:

sudo restart smbd && sudo restart nmbd

End of part 2

Congrats, you now have a working NAS. In the next post we’ll set the NAS up as a media server.

About these ads

2 thoughts on “NAS Part 2: Setting up Ubuntu Server 12.10

    • Hi Josh, part 3 has been in the making for quite some time as i’ve constantly been updating it for the ever changing requirements. In fact, i’m actually drafting a new post about getting the most life out of the USB thumbdrive at this very second. I’m trying to get both out in the next two weeks so stay tuned =)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s