Ubuntu Server Setup (NAS Migration and Samba)

RAID Migration

Before anything else I needed to make sure that the RAID5 array from my previous setup was still intact and that it could be migrated to the new system. Luckily the brains behind mdadm obviously had my situation in mind and this turned out to be far less painful than I imagined.

It is possible for mdadm to rebuild it’s config files just using the information stored on the disks themselves but as I really didn’t want to loose any of my data I decided to build the config file myself, using the same config data as last time.

With this in mind the last thing I did before the old OS fully died was to make a remote copy of the /etc/mdadm/mdadm.conf file.

After installing mdadm with the command:

sudo apt-get install mdadm

I opened up /etc/mdadm/mdadm.conf and added in the the line beginning with ARRAY from the backed up version. Then checked the array’s status using

mdadm --detail /dev/md127

Luckily all was well, the array blocks were still intact and mdadm confirmed that there were no drive errors, awesome!

I added the following line to /etc/fstab to mount the array as the /home directory on startup:

/dev/md127 /home ntfs defaults 0 0

But it turns out that I had forgotten what file system I used for the array and typed ntfs out of habit, oops! I used blkid /dev/md127 to find out the file system of the unmounted drive and it reported back as ext4, which made sense, so the fstab record was duly updated:

/dev/md127 /home ext4 defaults 0 0

I then mounted the array using sudo mount -a and did some digging around to make sure the files were indeed where they should be, everything was spot on. Time for a brew!

Samba Shares

I do remember the fun and games I had last time trying to setup the permissions with Samba. It was easy to get the shares on the network but a right pain to get all the permissions working.

For the moment the server will only be accessible from my local network which is behind a firewall, so I don’t really need to worry about overly complicated security measures, just a setup that allows full access to the NAS.

There doesn’t seem to be one definitive configuration example out there for a NAS which I find a little strange because I would imagine it is quite a common setup. Either way after much trial and error this is what worked for me.

Open up the /etc/samba/smb.conf file and, leaving most of the default config settings in place, I just updated the line:

security = user

to be:

security = share

so that all Samba shares no longer require a active Unix account on the server to be accessed. This means that anyone on the network can access them – which is what I need for a NAS.

Then I added the following share definition to the bottom of the file:

[nas]
    comment = NAS
    path = /home/nas
    browsable = yes
    guest ok = yes

That gives access to everyone on the network but does not allow editing of files/folders. Handy to remember but not enough for our purposes here so we need to add a few more parameters:

[nas]
    comment = NAS
    path = /home/nas
    browsable = yes
    guest ok = yes
    writeable = yes
    create mask = 0775
    directory mask = 0775
    force user = yourusername

These extra parameters make the share writeable, and make sure that any files (create mask) or folders (directory mask) are created with the required permissions and not the defaults, which may not be suitable for a NAS.

Lastly the force user parameter should be set to whatever user has read/write permissions for the directory given in path (in my case /home/nas). Preferably you should not put root as the user here so you may need to change the permissions settings for your shared files.

Once all that is done restart the Samba service:

sudo service smbd restart

and you are good to go. A quick check via my Windows machine confirms all directories are available and I can read/write both files and directories. Good times!

Next up: Installing the Media Server and SubVersion. You guessed it – the kettle is on…

Ubuntu Server Setup (Overview)
Ubuntu Server Setup (OS Install)
Ubuntu Server Setup (Media Server and SVN)