My Raspberry Pi Server Setup

Under construction! This is more just so that i dont forget how to set up my server should it fail. but its here for anyone else that may want it. This is under construction and will have lots of spelling mistakes as i am writing it on my phone!

The Initial Setup

Things needed:

  • A Raspberry Pi
  • 4GiB SD Card or higher
  • A screen and keyboard

Download the latest Rasparian image from here:

Download Win32 Disk Imager from here: and install.

Open Win32 Disk Imager and set the Image File to the Rasparian image and the Device to the SD card you are going to install Rasparian to. Click Write. It will take a while.

Once finished plug the SD card into the Pi and boot up by plugging it into the power, screen and keyboard.

You will be greeted by a settup screen. Click on Expand Filesystem to use the entire SD card.

It is also good practice to change the default password via Change User Password.

Then goto Advanced and goto Hostname and change as required.

Then go back into Advanced and click on SSH and enable it so that we can access it headless (remotely).

Then hit finished and reboot.

Then update the libarys via the command line:
sudo apt-get update
sudo apt-get upgrade
sudo reboot

Now we are going to give it a static IP Address so that we can easilly access it by SSH.

From the command line run:

ifconfig and copy any network settings you need.

sudo nano /etc/network/interfaces

Now edit this line iface eth0 inet dhcp

'auto eth0
# allow-hotplug eth0

iface eth0 inet static
address 192.168.X.X
network 192.168.X.0
broadcast 192.168.X.255
gateway 192.168.X.X'

Where X equals the IP addresses you wish to use.

Typical setting are:

'iface eth0 inet static

Although these will be dependant on your network settings.

sudo reboot

You can now remotly access your pi via SSH from another device by using the static IP Address that you have just assigned.

Install Midnight Commander

Midnight Commander is a gui file browser for command line.

sudo apt-get install mc

To run type mc

Well that was easy

Mount a USB HDD

If its formatted to NTFS then run sudo apt-get install ntfs-3g to install the driver.

If its formmated to FAT or FAT32 then it wont need a driver installing.

Then run sudo blkid and make note of the UUID

Now we need to create a folder in which to mount the USB drive.

sudo mkdir /media/usb-hdd

And change the permissons so that all users can access it:

sudo chmod 775 /media/usb-hdd

Now we will edit fstab to auto mount it at every boot.

sudo nano /etc/fstab

And add the following line:

UUID=XXXX /media/HardDrive vfat defaults,uid=pi,gid=pi 0 0

Where XXXX is the UUID you noted down earlier.

Then test that you can write to the USB disk

mkdir /media/usb-hdd/test

If no errors then it should be all working.

Samba Setup

Okay so time to install Samba

sudo apt-get install samba


sudo apt-get install samba-common-bin

Now we need to edit the config file for the shares.

sudo nano /etc/samba/smb.conf

Edit as required. To add a share add thid to the end:

comment = USB HDD
path = /media/usb-hdd
writeable = Yes
create mask = 0777
directory mask = 0777
browseable = Yes
public = yes

Save and exit.

Then run

sudo service samba restart and sudo testparm -s

And add the pi user

sudo smbpasswd -a pi

MiniDLNA Setup

Install MiniDLNA

sudo apt-get install minidlna

Edit the config file

sudo nano /etc/minidlna.conf

Insure that these lines are updated or added:

# Path to the directory you want scanned for media files

# Path to the directory that should hold the database and album art cache

# Path to the directory that should hold the log file

# Automatic discovery of new files in the media_dir directory

Now create the database directory:

mkdir /home/pi/.minidlna

And changr the permissions so that it can be written to.

chmod 777 /home/pi/.minidlna

Run to start MiniDLNA on boot

sudo update-rc.d minidlna defaults

MiniDLNA will now run on boot and index files in the media directories.

If you need to update the database manually tgen run sudo service minidlna force-reload

Get_iPlayer Settup

As the version of Get_iPlayer in the Raspbarian repos are broken we are going to have to add another repo with tge updated version in thusly:

To install the repository, get-iplayer and its dependencies, paste this line into a terminal window:

wget -O - | sh

To remove get-iplayer and the repository, paste this line into a terminal window:

wget -O - | sh


sudo bash -c "cat > /etc/apt/sources.list.d/ <<EOF
deb wheezy/
deb-src wheezy/

Followed by each line in turn:

sudo apt-get update
sudo apt-get --allow-unauthenticated -y install jonhedgerows-keyring
sudo apt-get update
sudo apt-get install get-iplayer

To manually refresh the feeds run

get_iplayer --refresh --type=all

Useful commands:

get_iplayer --type=radio news
get_iplayer --type=tv news
get_iplayer --type=podcast news

get_iplayer --fields=episode,channel hello
get_iplayer --pid b01sc0wf

get_iplayer --pvr-add=Top_Gear --type=tv "Top Gear"

get_iplayer --prefs-add --type=radio,tv
get_iplayer --get 123 --output "/home/user/tv-files/"

Options File
ag_fulltitle 1
output /media/HardDrive/Media/Video/iPlayerRecordings/

Exim4 Settup


sudo apt-get install exim4
After installing exim4 we need to configure it. This is done by the following command:

sudo dpkg-reconfigure exim4-config
Now you need to answer some questions. Don't worry I'll give you the answers to those questions.

The first screen asks you what type of mail server you need. Select the second option: "mail sent by smarthost; received via SMTP or fetchmail"
The next question asks for the system mail name: Set to same as hostname (raspberrypi)
Now it asks you what IP addresses should be allowed to use the server. Leave as is ( ; ::1)
Other destinations for which mail is accepted: raspberrypi
Machines to relay mail for: Leave blank.
IP address or host name of outgoing smarthost: Enter:
Hide local mail name in outgoing mail: Select: No
Keep number of DNS-queries minimal: Select: No
Delivery method for local mail: Select: "Maildir format in home directory"
Split configuration into small files: Select: No
After answering all these questions exim4 will restart and we're halfway home.

Now you'll have to enter your account details. As root, edit the file /etc/exim4/passwd.client and add the next three lines at the end of the file.
Needless to say that you'll have to change YOU to your Gmail login name, and PASSWORD to your password on all three lines. After that you only have to update and restart exim and you're done! The next two lines will do that for you:

sudo update-exim4.conf
sudo /etc/init.d/exim4 restart

The Final Touches
Some processes, for instance crontabs, can send mails to root or other system users. If you don't want to miss any of them you can setup some aliases. You can do that by editing the file /etc/aliases. Here's what mine looks like:

# /etc/aliases
mailer-daemon: postmaster
postmaster: root
nobody: root
hostmaster: root
usenet: root
news: root
webmaster: root
www: root
ftp: root
abuse: root
noc: root
security: root
root: pi
This tells the system to redirect all mail to root, while mail to root is redirected to the user pi, while mail to user pi is finally redirected to my own mail account. This way all mail will eventually be sent to my own mail account, no matter to what local user the mail was originally sent.

If you are like me, you will probably have more than one Raspberry Pi mailing you some status information. And unless you use different mail accounts for all your RPis it becomes harder and harder to find out which one is mailing you. The next command will setup a new full name (pi @ domotics) for the user name pi, with which you can idintify the source of the e-mail.

sudo chfn -f "pi @ domotics" pi
To test your out going mail simply execute the next command:

mail -s "This is the subject line" root@localhost
Then type the body of the message, this is only a test so anything will do. When you're done typing the body type a dot (.) at the beginning of a new line and hit Enter. The mail should now be sent to root, which is redirected to pi, which is redirected to your normal email address. 
You can also send a mail directly to your own email address if you want to, however that would have skipped the redirections from the test.

Below you see two other ways of sending mail from your RPi. Both methods will send the file body.txt as message body.

mail -s "This is the subject line" < body.txt
cat body.txt | mail -s "This is the subject line"

To fix this error:
IPv6 socket creation failed: Address family not supported by protocol

Edit /etc/exim4/update-exim4.conf.conf
sudo nano /etc/exim4/update-exim4.conf.conf
Remove ::1 from dc_local_interfaces
Save and exit
Delete the paniclog:
sudo rm /var/log/exim4/paniclog
sudo update-exim4.conf
Restart Exim:
sudo service exim4 restart

Cron Settup

And now on to some automation!

Crontab tells scripts when to run and can email you with the output.

To edit it for the current user run crontab -e

and edit as required. mine is #Emails the output to this email address
0 * * * * /usr/bin/get_iplayer --pvr 2>>/tmp/get_iplayer.log #Runs get_iplayer PVR every hour
15 2 * * * /usr/bin/get_iplayer --refresh --type=all #Refreshes get_iplayers librarys everyday at 2.15AM

And for root:

sudo crontab -e #Emails the output to this email address
30 3 * * 2 sudo service minidlna force-reload #Reload the minidlna database on the second day of the week a 3.30AM
30 3 * * 6 sudo service minidlna force-reload #Reload the minidlna database on the sixth day of the week a 3.30AM

Auto Start No IP

Taken from

 Raspberry Pi - run program at start-up

Anyway, I wanted to get my Raspberry Pi to start no-ip dynamic dns service when it started-up, so I wouldn't have to remember to start it every time it was powered up. For details on how to install no-ip on the Pi, see this post.

There are loads of ways of running a command at start-up in Linux but my favoured approach is to create an initialisation script in /etc/init.d and register it using update-rc.d. This way the application is started and stopped automatically when the system boots / shutdowns.

Create script in /etc/init.d sudo nano /etc/init.d/NameOfYourScript

The following is an example based on starting up the no-ip service [/usr/local/bin/noip], but change the name of the script and the command to start and stop it and it would work for any command.

  1. ! /bin/sh
  2. /etc/init.d/noip
  3. Provides: noip
  4. Required-Start: $remote_fs $syslog
  5. Required-Stop: $remote_fs $syslog
  6. Default-Start: 2 3 4 5
  7. Default-Stop: 0 1 6
  8. Short-Description: Simple script to start a program at boot
  9. Description: A simple script from which will start / stop a program a boot / shutdown.
  10. If you want a command to always run, put it here
  11. Carry out specific functions when asked to by the system

case "$1" in

    echo "Starting noip"
    # run application you want to start
    echo "Stopping noip"
    # kill application you want to stop
    killall noip2
    echo "Usage: /etc/init.d/noip {start|stop}"
    exit 1


exit 0

Warning - its important you test your script first and make sure it doesn't need a user to provide a response, press "y" or similar, because you may find it hangs the raspberry pi on boot waiting for a user (who's not there) to do something!

Make script executable sudo chmod 755 /etc/init.d/NameOfYourScript

Test starting the program sudo /etc/init.d/NameOfYourScript start

Test stopping the program sudo /etc/init.d/NameOfYourScript stop

Register script to be run at start-up To register your script to be run at start-up and shutdown, run the following command:

sudo update-rc.d NameOfYourScript defaults

Note - The header at the start is to make the script LSB compliant and provides details about the start up script and you should only need to change the name. If you want to know more about creating LSB scripts for managing services, see

If you ever want to remove the script from start-up, run the following command:

sudo update-rc.d -f NameOfYourScript remove

Print - Search - Log In - Edit - Admin - Log Out - Upload
Page last modified on March 27, 2017, at 10:11 PM
Josh Wright 2011