For those wondering if they could get rid of all the external hard drives and cables lying around, or find a way to use that ancient CPU or laptop gathering dust in a cupboard, a Linux server could be the answer. Servers are incredibly useful even at home. This article demonstrates how to set up a home server for media streaming and back-ups

Sumit Pandey


What are servers, and why do I need one? A server is often just a computer that stores your data and serves it to other computers on the network. In a household scenario, it can be hidden away in a corner of your room—a target for all your device backups, and source for all your media to your devices. Specifically, such a set-up is called network-attached storage (NAS).

3EF_pic

There are a lot of out-of-the-box solutions to create a NAS, but most of them are very expensive or don’t even come close to the kind of customisability that Ubuntu Linux can provide. Ubuntu is one of the best and the easiest to install and use flavours of Linux, and that is why we are using it for our NAS box.

Explore Circuits and Projects Explore Videos and Tutorials

So what do you need to get started? There are different versions of Ubuntu available, and most should work fine for our purposes, but in this article we will follow the easiest method of installation. This is what you will need:

1. A PC/laptop with a minimum of 512 MB of RAM and a 1GHz processor, and a minimum of 5GB free space for your server. It is recommended that you set up your server close to your router, so you can use a wired (Ethernet) connection instead of Wi-Fi—that is much faster.

2. An Ubuntu live CD, downloaded from the Ubuntu website. We will be using the Desktop version rather than the Server version, since it’s easier to configure and set up. You could alternately burn the image to a USB flash drive as well, if your soon-to-be server machine does not have a CD drive. Links to help you do this are given at the end of the article.

3. Hard drives to store your media/back-ups. You don’t need to get new hard disks for this; we will be sharing the content on your existing disks. You could always plug in more storage if you plan on buying new hard disks.

Setting up Ubuntu
Before beginning the installation, make sure you back up any existing data on your soon-to-be server, and that you have at least 5 GB of free space. To begin, insert the CD/USB flash drive into your server machine and boot it up. If your machine is not set to boot from a CD/USB, you may need to press F12 to enter a one-time boot menu and select CD/USB, or you could change the boot device priority in the BIOS settings (but make sure you change it back if you are going to use external disks for storage—which is the likely scenario if you are using an old laptop for your server, like I am). Your system’s start-up screen will tell you how to enter the BIOS set-up screen.

Fig. 1: Sharing options
Fig. 1: Sharing options

After booting into Ubuntu, select the Install Ubuntu option and follow the onscreen instructions to set up a dual-boot or single-boot system, based on your preferences. Also, make sure you select log in automatically when you are creating a user account, so that you have a single-button power-up sequence, which doesn’t need any action from you during start-up.

READ
Electronic Heart

The server set-up
At this point, I assume you have Ubuntu set up successfully and are booted into it. Now for the server set-up, plug in your external drives if you haven’t already, and click Ubuntu Dash (the button with Ubuntu logo) and search for Terminal. Ubuntu has built-in support for NTFS, so your drives should ideally work out-of-the-box. If you are configuring new drives, you can format them as ext4 for better Linux compatibility. Ubuntu supports HFS-formatted disks (the native format on Macintosh computers) as well, as long as journaling is disabled on them; but for the purposes of this article, let us assume your disks are formatted as NTFS or ext4.

Step 1. Mount-points: In the terminal, run the following commands as explained below:

 

sudo mkdir /path/to/mountpoint
sudo chown userName /path/to/mount
point

Replace /path/to/mountpoint with a folder in which you would like to mount your hard disk. For example:

 

sudo mkdir /media/BackupDisk
sudo chown sumit /media/BackupDisk

sudo mkdir /media/MovieDisk
sudo chown sumit /media/MovieDisk

Enter your password when you are prompted for it. Repeat the commands for each hard disk you have connected to the system.

Step 2. Auto-mounting: Next, run the following command in the terminal:

sudo blkid

This command should result in an output that looks something like what follows:

 

/dev/sda1: TYPE=”ntfs”
UUID=”A0F0582EF0580CC2”
/dev/sda2: UUID=”8c2da865-13f4-47a2-
9c92-2f31738469e8”
SEC_TYPE=”ext2” TYPE=”ext3”
/dev/sda3: TYPE=”swap”
UUID=”5641913f-9bcc-
4d8a-8bcb-ddfc3159e70f”
/dev/sda5: UUID=”FAB008D6B0089AF1”
TYPE=”ntfs”

Basically, what we are trying to do here is to make sure your disks mount automatically every time you boot up your server. The fstab or file systems table is a configuration file in Linux systems that lists connected disks and partitions and their initialisation/mounting information. This information is used by the mount tool to mount your disks/partitions. So we need to start adding entries for each hard disk into the /etc/fstab file. We could use GUI tools, but those would add the disks using their device file names (/dev/sdX). This leads to problems in some cases, when the system renames these device files, causing errors while mounting disks. That is where Universal Unique Identifier (UUID) comes to the rescue. UUID enables you to uniquely identify your disk; and it does not change with every reboot, like the device files do. UUID is conceptually similar to the MAC address for a network card.

Fig. 2: Install Samba
Fig. 2: Install Samba
Fig. 3: Add permissions
Fig. 3: Add permissions

In the terminal, run sudo gedit /etc/fstab to open a text editor window (like Notepad on Windows). Add an entry to the end of the file in the following format, for each of your connected disks’ partitions:

 

UUID=Your-UUID /path/to/mountpoint
fs-type defaults 0 0

You will need to copy the UUID from the list generated by the blkid command. Here /path/to/mountpoint is the address to the directories you created in Step 1. For example:

 

UUID=A0F0582EF0580CC2 /media/Backup
Disk ntfs defaults 0 0
UUID=FAB008D6B0089AF1 /media/
MovieDisk ntfs defaults 0 0

Now save and close this file. You should be able to see all your disks in the left-hand sidebar of your file explorer (Nautilus). However, these disks are not mounted yet. You can click them individually to mount them in the folder you have entered in your fstab file (/media/ in our case). The next time you boot up your machine, this should happen automatically.

READ
SHADOW ALARM

Sharing your drives on the network
Now that the basic set-up is out of the way, and your disks are usable by the server, you need to get down to some actual ‘serving’. You need to share the connected disks on the network.

Sharing with Windows/Mac
In the terminal, run ‘gksudo nautilus’; this starts up the Ubuntu file manager with root permissions. The difference between sudo (which we used earlier) and gksudo is that sudo is used to run command-line applications as the root while gksudo is used to launch GUI applications as the root. It is pretty similar to ‘Run as administrator’ command in Windows. Right-click each drive in the left sidebar and click ‘Properties’ and select ‘Share.’ Select ‘Share this folder’ check box in the window that comes up (Fig. 1). The first time you do this, Ubuntu should ask you to install the Windows file sharing service Samba (Fig. 2). Install whatever it asks you to, and then restart the session when prompted.

Start Nautilus from the terminal as the root again. Go back to ‘Share’ properties panel for a disk, give it a name, and select ‘Allow others to create and delete files in this folder’ option. Choose ‘Add the permissions automatically’ button on being prompted (Fig. 3). Click ‘Create share.’ Repeat these steps for all your drives.

Finally, we need to set up a password for all the shares you have set up. You can do this by running the following command in the terminal:

 

sudo smbpasswd -a userName

Replace userName with your Ubuntu username (which you created during installation), and then type and confirm a password for the share. Your password can be anything and is not necessarily your Ubuntu user account password. However, the username needs to be a valid Ubuntu user, otherwise this command will fail. Once you enter your share credentials, you should be able to see all your shared disks. You can also right-click the share and select ‘Map network drive’ to assign a drive letter to the share. This will also give it a place in Windows Explorer allowing quick and easy access.

Setting up back-ups
One of the most common and important uses for a NAS box is networked back-ups. With your newly set-up NAS box, this is going to be extremely simple, provided you have Windows 7 Professional or a higher version. To set things up, just open ‘Start’ menu on Windows, and type ‘backup’ to get to the Windows ‘Backup and Restore’ utility. Click ‘Set Up Backup’ and then ‘Save on network’ button. Proceed to enter the path to your NAS box manually, or browse to discover the server. Choose your back-up settings and set a schedule for your back-ups. I would recommend you connect your computer over Ethernet while the back-up is in progress, to speed things up. If you do not have Windows Professional, you can use an Open Source tool called ‘Create Synchronicity’ for creating back-up images for your system.

For the Mac only
But what if all the computers in your house run the Mac OS, and you want to create a wireless Time Machine-based back-up solution for all your computers? Then it’s time for a little more terminal magic. First of all, you need to install Avahi, which implements Apple’s Bonjour protocol, and Netatalk, an Open Source implementation of the AppleTalk protocol that you will be using to share your drives with your Macintosh computers. Run the following commands in the terminal to download and install these services on your Linux system:

READ
Pencell Charge Indicator

 

sudo apt-get install avahi-daemon
sudo apt-get install netatalk

Next, edit the configuration files to enable support for the latest version of Time Machine running on Lion or Mountain Lion. In the terminal, run:

sudo gedit /etc/netatalk/afpd.conf

Add the following line at the end of the file, and then save and close the file:

 

– -tcp -noddp -uamlist uam_guest.
so,uams_dhx2_passwd.so
-nosavepassword

Next, edit the AppleVolumes file to share your drives using AFP (Apple Filing Protocol)—run the following command in the terminal:

 

sudo gedit /etc/netatalk/
AppleVolumes.default

Comment out the ~/ “Home Directory” entry at the end of the file by adding a ‘hash’ in front of it. Then add the following command below the commented line:

 

/path/to/mountedTimeMachine
“UbuntuCapsule” cnidscheme:
dbd options:usedots,upriv,
tm allow:userName

Here /path/to/mountedTimeMachine is the address to the mount directories you created in Step 1, and userName is your Ubuntu username. Select the one you wish to be used as a Time Machine back-up. Next, add an entry for each disk below the Time Machine entry, to share your remaining drives over AFP as well. The entry will be in the following format:

 

/path/to/mountedMovieDisk
“MediaCapsule” cnidscheme:dbd
options:usedots,upriv allow:userName

Make sure you have only one disk marked as the Time Machine back-up volume (specified by ‘tm’ in the options). After you have added entries for all your disks, save this file and restart Netatalk with sudo service netatalk restart.

On your Mac, you can open up Finder, where your Ubuntu server should be visible in the left panel. Click it, and authenticate with your username and password. All your shared disks should be visible under the server, including your Time Machine disk. Your Time Machine disk should also show up under Time Machine now, under the available disks. Select the disk and start backing up; it’s as simple as that! You can select the same disk as a back-up destination for multiple Macs. Again, I would strongly recommend that you do the first full back-up over Ethernet. Time Machine does incremental back-ups subsequently, which should not be as large as the first one; those could be done over Wi-Fi, if desired.

6F1_LinksYour media and back-up server is up and running now, and you can disconnect your display from it. Now that it is set up, there is a whole world of other things you can do with it. For starters, you could connect and share your printer over the network, so all your computers can access it—and there’s one less item to clutter your workspace. You could also set up a Plex server to share and serve data to devices like your phone and tablet as well. Just start playing around with and exploring the wealth of free and Open Source software available for Ubuntu, and you will be amazed at how handy your home server can turn out to be!


Reproduced from January 2013 Issue of Open Source For You published by EFY Group. The author is an interaction designer and a ‘maker of things,’ who loves playing with code and hacking away at technology in his free time

LEAVE A REPLY