Saturday, May 2, 2015

How to build a Raspberry Pi 2 File Server using Raspbian

While the strange configuration of its USB and network ports – which share a single USB 2 channel to the system-on-chip (SoC) – may limit the performance of the Raspberry Pi 2 when acting as a file server, its low cost and minuscule power draw mean it’s still a good choice for anyone who doesn’t need high-speed throughput.

1. Install Raspbian

If you’re already running Raspbian, you can skip this step. If not, the easiest way to get Raspbian running on your Raspberry Pi 2 is via NOOBS. Head towww.raspberrypi.org/ download and download the latest version. Ensure that your micro-SD card is formatted to FAT32 or VFAT – if it’s ExFAT, you’ll need to reformat it – and extract the contents of the NOOBS Zip archive onto it.

Insert the micro-SD card into the slot on the underside of the Raspberry Pi 2, and then connect the Pi to a display, keyboard and network. The display and keyboard are only needed for installation and configuration; once you’ve installed Raspbian and set up your file server, they can be disconnected.

Power up the Pi, and then select Raspbian to install it. This will take a few minutes, after which you’ll be prompted to reboot into Raspbian. Do so, and then exit the configuration screen that appears. Now is also a good time to change the default password, by typing the passwd command at the console.

2. Update and install Samba

A fresh install of Raspbian isn’t going to be running the very latest packages, so run the following command to ensure it’s up to date: sudo apt-get update && sudo aptget upgrade && sudo rpi-update When the updates have finished, reboot with the following command: sudo reboot

Log back in, and type the following command to install Samba: sudo apt-get install samba

Samba is a networking server system designed to be compatible with the Server Message Blocks (SMB) standard on which Windows networking is based. It allows you to share your files to Windows, Linux, OS X and other hosts, without having to mess around with third-party clients.

3. Configure your storage

You’re going to need somewhere to store your files. If that’s an external hard drive, the easiest way to get it up and running is to load the GUI with the startx command. You can then connect your external hard drive – it will be automatically mounted –and make a note of the location, which will be in the format / media/partition name.

It’s fine if the partition name is a string of numbers or hexadecimal digits, which just indicates that the partition was never labelled when it was created.
If you don’t have an external hard drive, and you want to use the Pi’s micro-SD card for storage, create a new directory with the following command:

mkdir ~/FileServer

Note that Linux is case-sensitive; if you use a capital F and capital S, as in this example, you’ll need to always use the same case when you type the directory name later. In either case, to allow anonymous read-write access from your local network – a serious security concern, so be sure you want to do this – you’ll need to change the permissions: sudo chmod 777 path Replacepathwith either /media/ partitionnameor~/FileServer, as appropriate. Without this step, unauthenticated users will be able to read files but not modify or create new ones.

4. Configure Samba

At a terminal – either the console or a terminal window if you’ve loaded the GUI – type the following command:
sudo nano /etc/samba/smb.conf

Scroll to the bottom of the file, then add the following lines:

[storage] comment = Raspberry Pi 2 File Server browseable = yes path = path guest ok= yes read only = no create mask = 0775

Replace path with either the partition location:

/media/partitionname or /home/pi/FileServerif using the SD card.

Save the file with Ctrl-O, then exit with Ctrl-X. Restart Samba to load the new configuration with the following command: sudo /etc/init.d/samba restart

5. Access the file server

To use the Raspberry Pi’s new file-serving capabilities, you’ll need to know its IP address, which you can find with the following command on the Pi: ifconfig | grep inet\ addr Taking the first IP, rather than 127.0.0.1 (a loopback address), load Windows Explorer – or your favourite file manager – and attempt to connect to the server. If you’re prompted for a username and password, use ‘pi’ and whatever password you chose in the first step. When the file-browsing window loading, try dragging and dropping some files onto it. These files will be copied across to the Pi, but be warned: the maximum speed you’ll get from it is around 10MB/sec, so don’t expect ultra-fast file transfers.

6. Tweak the kernel

This step is optional, but if you find your Pi has a tendency to crash or reboot itself during heavy network traffic, you may need to work around a couple of bugs in the firmware. At the terminal, run the following command:

sudo nano /boot/cmdline.txt

At the end of the line, after ‘rootwait’, add the following two entries ensuring that they’re separated by a space and not a new line:

3 4 5 smsc95xx.turbo_mode=N vm.min_ free_kbytes=16536

The first setting disables the network chip’s ‘turbo’ mode, which is known to cause instability, while the second entry helps to prevent memory page allocation errors that can otherwise build up. You can then save with Ctrl-O and exit with Ctrl-X, then reboot the Pi with the following command:

sudo reboot.


Previous Page Next Page Home

Related Posts: