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.