Categories

Archives

Using the Raspberry Pi as a Server for the Home Network – Part 3

Let’s dig right away into the procedure for installing Raspbian on the RPi. I will go very quickly on the general details, as they are very well explained in several other sites. In order to execute the procedure, you will need another computer that you will be using to prepare the SD card and to pre-partition the hard drive you will be using with the RPi.

If you never installed Raspbian before, I suggest you to search for the procedure on the internet, and try to do it at least once, before attempting to do what I am about to describe. A relatively good familiarity with the tool gparted would also be nice. The tool is usually available on any Linux distribution. If you don’t find it, just use you favorite package installer to put in on your system. Gparted is also available under Windows.

Here is what you’ll need:

  1. A Raspbery Pi 2 version B. I strongly suggest to use this RPi, or a newer and more powerful version, if it becomes available when you read this article. You may want to also add a couple of heat sinks, if you plan to keep the RPi server running 24/7. They can be found easily on the internet. Here is a picture of the RPi 2B with heat sinks:rpi2_heatsinks
  2. A power supply for the RPi. Any cell phone charger with micro USB will work, as long as it provides an output current of at least 1.5 A.
  3. An external USB portable hard disk drive. I used a 1 Tb Passport from Western Digital, but any other similar device will work. You can even use an internal hard disk, provided that you buy one of those adapters to go from SATA or PATA to USB. The RPi has a USB 2.0 interface. However, if your HD has USB 3.0, it will still work, although you won’t be able to use the full speed of that interface.
  4. A power supply for the hard disk drive. Do not think to power the HD from the USB port itself, it will not work, because the RPi ports do not provide enough juice to power the HD. In my case, I connected my Passport to the RPi through one of those powered USB hubs. As a bonus, I got a few extra USB ports available on the Pi, in case I need them for future applications.
  5. A computer you can use to prepare the MicroSD card and to partition and format the hard disk drive. I am a Linux guy, so I used my main Linux computer, which runs the Fedora distro. But also Windows works fine, although you’ll have to go through a few more steps to install the tools you need to write on the MicroSD card and to partition the HD.

Once you have everything ready, you can start the installation procedure as follows.

  1. Copy on the MicroSD card the latest version of NOOBS.
  2. Connect the HD to your PC, run gparted (or whatever partitioning tool you are comfortable with), and partition the disk as in the following picture. You can adjust the size of each partition according to your needs. In my case, I even left some unallocated space for future use. Note that all the partitions created on this HD are meant to replace partitions available on the MicroSD card. The reason for the replacement is a matter of both size and reliability. The SD card does not have enough space for the needs of a server. Also, those partitions where the system writes very often will quickly make the SD card inoperable, if we keep using them over and over (see my previous article to know why). Replacing those partitions, with the ones on the HD, will greatly extend the lifetime of the RPi server.
  3. rasp1_gparted_HDExecute the procedure to install Raspbian on the RPi using the NOOBS menu. You will have to connect the RPi to the TV and to a keyboard and mouse to do so. It is also useful to connect the Pi to the network. This will allow for installing the most recent updates to the Raspbian distribution.
  4. Toward the end of the installation, the raspi-config utility will be launched. Use it to do the following:
    • Make sure that the file system is already expanded to the max size of the SD card.
    • Adjust the memory split giving the GPU only 16Mb. Since you will use the RPi as a server, you will mainly work on it through the command line to install and configure the server itself. You will not use the graphical interface, therefore you don’t need much memory assigned to the GPU.
    • Enable ssh, so you will be able to connect remotely to the RPi from another PC in the network.
    • Change the host name to something more meaningful to you. In my case, since I planned to have a number of RPi in my home network, I named this one ‘rasp1’.
    • Shutdown the Raspberry Pi and power it down.
  5. Connect the HD to one of the 4 USB ports of the RPi, attach the network cable and power up the disk, wait a 10-15 seconds, then power up the RPi. This is to make sure that when the RPi completes the initialization, the disk is already spinning and available, otherwise it could not be recognized.
  6. Figure out the IP address currently assigned to the Raspberry Pi by your router. This could be done logging into the router and look for the newest device assigned IP address. Another way would be to scan the IP addresses of your network from a PC, until you find the one you are looking for.
  7. Now, if you have a Linux PC, just fire up a terminal window and ssh to the RPi as follows:
    ssh -X pi@<ip_address_of _the_PI> 
    then enter the password raspberry.
  8. Activate the X forwarding on the PI:
    • sudo vi /etc/ssh/sshd_config
    • add the following line to the end of the file:
      X11Forwarding yes
    • save and close the file
    • restart the ssh deamon:
      sudo service ssh restart
  9. Set the time zone:
    sudo dpkg-reconfigure tzdata
    and follow the appropriate prompts.
  10. It is now time to make the changes for automounting the partitions of the external disk:
    • execute the command
      sudo blkid
      and take a note of the following information for each partition of the external disk. The external disk partitions will most probably be identified by names like /dev/sda1, /dev/sda2, and so forth. Here is an example of the command output: RPi_blkid_screenshot
    • Before mounting the /home partition, we need to save the current contents of /home/pi in some other place so, after mounting the /home partition, we can restore the pi directory in it:
      sudo cp -rp /home/pi /var/.
    • Edit file /etc/fstab (using sudo) and add one line for each of the partitions that we want to automount the next time the system is started at the following mountpoints: /var/www, /home, /tmp, /etc/bind. Each line needs to follow the following syntax (substitute the appropriate values for <UUID>, <mount_point>, and <TYPE>:
      UUID=<UUID>   <mount_point>  <TYPE>  defaults,nofail  0  2
      Here is how they look like in my case:fstab_rasp1_screenshot_1
    • Create the following mount points (the others are there already):
      • sudo mkdir /var/www ; sudo chmod 755 /var/www
      • sudo mkdir /etc/bind ; sudo chmod 755 /etc/bind
    • Reboot the PI:
      sudo reboot
    • Once the PI comes back, make sure all the four partitions are mounted, using the command df:rasp1_df_screenshot_1
    • Now restore the saved contents of the ‘pi’ directory:
      cp -rp /var/pi /home/.
  11. Since I am a Fedora person, I like to have access to the root login, so I can run long sequences of commands without the need to use sudo in front of each one of them. This is your preference, everything will work just fine even if you don’t do it. However, from now on, I will assume I am working from the root login when making changes to the system, so I will omit the prefix sudo in all the commands. If you don’t use the root login, don’t forget to use sudo. In order to add root login, just run the command
    sudo passwd
    and follow the prompts. Once that is done, you can login to the RPi as root, with the password you provided to the above command.
  12. Update the Raspbian software, to make sure you are running the latest version of the software:
    • apt-get update
    • apt-get upgrade
  13. Since we are going to use the Raspberry Pi as a server for the home network, it is better if we give to it a static IP address, rather than having it assigned dynamically by the DHCP server on the router (or any other DHCP server you may have in your network). In the process, also add a few alias IP addresses, so we can have different IP addresses for different servers running on the same system. To do so, edit the file /etc/network/interfaces and modify it as in the following picture (use your IP addresses instead). Make sure the IP addresses you choose are not in the range of the dynamically assignable IP addresses of your DHCP server (i.e. the router)rasp1_network_config_snapshot
  14. Reboot the system one more time.
  15. Create and put in use a swap partition from the external HD:
    • use gparted to verify the name of the device to which the swap partition was assigned. In my case /dev/sda7
    • mkswap /dev/sda7
    • swapon /dev/sda7
    • add the following line to /etc/fstab:
      UUID=<swap_partition_uuid>  none  swap  sw  0  0
  16. Reboot the RPi one last time.

This concludes the setup of the Raspberry Pi to make it work as a server. Next time we will start configuring the actual server applications on it. We will begin with a DNS server, then we will continue by adding a Proxy server, then a WEB server, a SAMBA server and, finally, a DLNA server. All of them can run simultaneously on the RPi 2B keeping the performance at an acceptable level for a home application.

 

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

  

  

  

This site uses Akismet to reduce spam. Learn how your comment data is processed.