Skip to content

How to mount external storage drive

Claude Pageau edited this page Apr 5, 2018 · 37 revisions

How to mount external usb storage drives, devices, directory softlinks and more.

Description

Quite often you will need to save image/video files to a NAS, external share or USB attached thumb or Hard Drive. This is important when you are saving a large number of images and/or videos. There is also added security since the system SD card can occasionally fail. This procedure assumes you are familiar with ssh, nano and a few unix command line commands.

How to Install usbmount

sudo apt-get install usbmount 

Note by default, mount points will be created in /media folder eg usb0, usb1 etc. When a usb storage device is inserted, it will mount at the next available mount point starting at usb0. Note default mountpoints can be changed by editing /etc/usbmount/usbmount.conf MOUNTPOINTS= variable

How To Install Additional File System Support

If you need NTFS and/or EXFAT file systems support then install the required support files per commands below. (note latest full jessie should already have ntfs and vfat libraries installed).

sudo apt-get install ntfs-3g
sudo apt-get install exfat-fuse

How To Configure usbmount

sudo nano /etc/usbmount/usbmount.conf

Edit usbmount configuration file similar to below. Note each file system is delimited by a space (no spaces for a specific file system) From an SSH or terminal session

sudo nano /etc/usbmount/usbmount.conf

Edit the following lines as required

ENABLED=1
FILESYSTEMS="vfat ntfs fuseblk ext2 ext3 ext4 hfsplus"
FS_MOUNTOPTIONS="-fstype=ntfs-3g,nls=utf8,umask=007,gid=46 -fstype=fuseblk,nls=utf8,umask=007,gid=46 -fstype=vfat,gid=1000,uid=1000,umask=007 "

ctrl-x y to save changes

For additional usbmount configuration information see
https://raspberrypi.stackexchange.com/questions/41959/automount-various-usb-stick-file-systems-on-jessie-lite

Test usbmount

Insert a usb mass storage device. By default it will mount at /media/usb0-7 0-7 is a sequence number for each usb storage device plugged in. Test if you can write to the device. If not then edit the /etc/usbmount/usbmount.conf file

You can create links from pi-timolo to a one of the mount points per example below

cd ~/pi-timolo/media
ln -s /media/usb0 usb0

How To Prepare A USB Storage Drive

You do not need to change pi-timolo.py code. config.py will need to be edited to point to the drive mount point or a link to the mount point. I normally attach an external usb Hard drive, partition and formated with to ext4 file system using gparted.

sudo apt-get install gparted

This is a gui app so you will need to run from the pi desktop menu, tools. google for additional info on using gparted. You can also use a normal Fat32 formatted drive if you like. Once the drive is read you will need to create a file system mount point for the drive (empty folder). This can be in the /mnt folder but in my case I decided to put it in the /home/pi folder per example below

cd ~
mkdir mnt
mkdir mnt/hd_usb1

How to Create fstab entry

Now create an entry in the /etc/fstab to auto mount your new drive.

sudo nano /etc/fstab

Use nano to add a line in fstab file to mount your hard drive. In my case the line below. This will be different if you are using a fat32 formatted drive. Change parameters to suit your situation. Google if you need more detail.

ext4 sample fstab entry

/dev/sda1     /home/pi/mnt/hd_usb1  ext4 nofail,rw,defaults 0  0

ntfs sample fstab entry

/dev/sda1  /home/pi/mnt/hd_usb1  ntfs-3g nofail,uid=1000,gid=1000,umask=007 0 0

vfat sample fstab entry

/dev/sda1  /home/pi/mnt/hd_usb1  vfat  nofail,auto,user,rw,uid=pi,gid=pi 0 0

Test mount the drive per below and check if it mounts OK. fix any issues. Reboot to verify drive mounts on boot. nofail option will continue booting even if drive is not plugged in. This avoids problems with boot stopping and requiring manual intervention to fix.

mount  /dev/sda1
cd ~/mnt/hd_usb1
mkdir data1
ls

How to Setup Directory Soft Link To Mount Point

Add a soft link to the relevant pi-timolo folder and created a link to the drive. Note change folder_name below to suit your needs.

cd ~/pi-timolo
ln -s /home/pi/mnt/hd_usb1/data1 folder_name
ls -a

Test to make sure the link works and you can write files to the hard drive link that points to the HD mount point. Please note you can change the mount point locations and folder names to suit your needs. Once the mount point is working you can change the pi-timolo config.py to point to the new folder_name folder soft link. Use nano to edit the config.py file and change the motionDir= and/or timelapseDir= entries to point to the appropriate folder link and folder name eg

motionDir=folder_name

This is just a sample guide. If you need more detail just google and you should be able to get more information on mounting storage devices to the raspbian file system.

How to Mount a Network Share

Clone this wiki locally