Daily Archives: May 17, 2015

Configuring the USB drive

Although the raspberry pi has an 8GB micro SD card, we want to connect an external USB hard drive and use that as main drive for our files. This is both because 8GB are not a lot when we want to store media, but also because SD cards are not the most reliable storage media and we want to reduce the possibility of losing all our stuff.

You can see all drives connected to the server by entering

sudo fdisk -l

This will show the sdcard (/dev/mmblk0pX) with multiple partitions and the USB drive (/dev/sda1). We want to change the settings such that the USB drive is automatically mounted on /home. This will mean that all user data will be stored on the hard drive.

The fstab file contains the mount points for all drives. Back it up before making any changes:

 sudo cp /etc/fstab /etc/fstab.$(date +%Y-%m-%d) 

and then enter the following line:

/dev/sda1       /media/home     ext4    defaults        0       1

and mount the drive in that folder:

sudo mkdir /media/home
sudo mount -a

We're copying everything to the new drive:

sudo rsync -aXS /home /media
sudo diff -r /home /media/home 

The second command compares the two folders and makes sure the copy was successfull. We can now open /etc/fstab again and modify the mount point from /moedia/home to /home. To be on the safe side, it's best to back up the old home folder just in case:

 cd / && sudo mv /home /old_home && sudo mkdir /home 

After that, we only need to remount all drives:

sudo mount -a

and the hard drive shold be mounted in the home folder. If you are convinced that everything went well, just deleted the /old_home folder.
 

Setting up a static local IP

By default, any computer on the local network gets assigned a new (local) IP address everytime they connect to the system. We can check the local IP address by typing

ifconfig

In my case, the local address is 192.168.0.8. Since we will want to connect to the server from other computers on the network without changing the target IP address every time, we can assign a static IP address to the server.

This is done by changing the DHCP settings in your router. Usually, the router settings can be changed through a web interface, in my case this can be reached by typing 192.168.0.1 into a web browser. Set up DHCP reservation such that the server always gets assigned the same IP address. While we are at it, we'll also set up port forwarding to make the server available for SSH outside the network and forward por 22 (the SSH port) to 192.168.0.8.