Using a Raspberry Pi in a hard way, you quickly feel the necessity of additional storage. Memory cards are not really cheaper and often give corrupted data after a lot of reading and writing sessions. So, the best thing is to re-use old HD with external USB case. If you’re setting up a Samba sharing server, a Monero daemon or a Torrent downloader, your Raspberry Pi needs some external storage. It also should be already mounted and ready for access at startup.
How to prevent to manually mount the drive every single session
To have a USB drive mounted on your Raspberry Pi every time you boot it, just do the following simple steps.
First you must plug it in, and then switch the Pi. It should boot up as normal, so log in to Raspian as usual and digit in a terminal (or a remote terminal if you connect to the Pi through an ssh tunnel):
pi@raspberrypi:~ $ sudo blkid
Look at the terminal answer and take note of the external hard drive (in my case /dev/sda1):
/dev/mmcblk0p1: LABEL="boot" UUID="CDD4-B453" TYPE="vfat" PARTUUID="a146d1c0-01"
/dev/mmcblk0p2: LABEL="rootfs" UUID="72bfc10d-73ec-4d9e-a54a-1cc507ee7ed2" TYPE="ext4" PARTUUID="a146d1c0-02"
/dev/sda1: LABEL="BLOCK" UUID="1f8276a9-66f2-43b8-972f-1ff416f3db10" TYPE="ext4" PARTUUID="45b8e6d5-01"
/dev/mmcblk0: PTUUID="a146d1c0" PTTYPE="dos"
Create a location for the external drive mount point:
pi@raspberrypi:~ $ sudo mkdir /mnt/exthd
Give to it right permissions:
pi@raspberrypi:~ $ sudo chmod 770 /mnt/exthd
Mount the drive and check if it is working:
pi@raspberrypi:~ $ sudo mount /dev/sda1 /mnt/exthd
pi@raspberrypi:~ $ ls /mnt/exthd
Take a backup of current fstab and then edit it to do external drive auto-mounting:
pi@raspberrypi:~ $ sudo cp /etc/fstab /etc/fstab.backup
pi@raspberrypi:~ $ sudo vi /etc/fstab
Add the correct mount information in the fstab file (remember to replace the UUID with your own) and write the following at the bottom of the file:
UUID=1f8276a9-66f2-43b8-972f-1ff416f3db10 /mnt/exthd ext4 defaults 0 0
Save the fstab file and exit from editor.
+++ Take a look: vfat for Microsoft FAT32 file system and ext4 for the Linux native ext4 file system +++
Finally, reboot the system to make effective the auto-mounting:
pi@raspberrypi:~ $ sudo reboot