Robert Cudmore    archive    tags    search    software


Mounting a USB drive at boot

I have a Fat32 formatted USB drive and I want to have it mounted when the Raspberry Pi boots. To do this I add an entry to my fstab file using the UUID of the drive and some permission.

Get a list of your USB devices to check if your USB drive is available

lsusb

Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 004: ID 13fe:5200 Kingston Technology Company Inc.
Bus 001 Device 005: ID 0bda:8176 Realtek Semiconductor Corp. RTL8188CUS 802.11n WLAN Adapter

Make a directory to mount your drive/volume into

sudo mkdir /home/pi/crap

Find the UUID of your drive

sudo blkid

/dev/mmcblk0p1: SEC_TYPE="msdos" LABEL="boot" UUID="2654-BFC0" TYPE="vfat"
/dev/mmcblk0p2: UUID="548da502-ebde-45c0-9ab2-de5e2431ee0b" TYPE="ext4"
/dev/sda1: LABEL="CRAP" UUID="7CCD-19F2" TYPE="vfat"

This tells me that my usb drive is in the device list at /dev/sda1, has the label ‘crap’, a UUID of ’7CCD-19F2′, and is formatted as VFAT (e.g. FAT32).

Edit your /etc/fstab file by appending a line for your dive

sudo pico /etc/fstab

proc            /proc           proc    defaults          0       0
/dev/mmcblk0p1  /boot           vfat    defaults          0       2
/dev/mmcblk0p2  /               ext4    defaults,noatime  0       1
UUID=7CCD-19F2 /home/pi/crap    vfat    rw,umask=0      0       0
# a swapfile is not a swap partition, so no using swapon|off from here on, use $

Here, on the line starting with UUID, I have mounted a device using its UUID=7CCD-19F2 into a folder /home/pi/crap. This is a Fat32 formatted drive (vfat) and everybody has read-write permissions (rw,umask=0). This recipe will not work for other types of formatted drives (Ext3, NTFS, etc).

Remount Your drives and check the drive is mounted

sudo mount -a

‘ls’ should show /video/ in blue to indicate it is mounted

Important. When you make the directory where a drive will be mounted it MUST be done with ‘sudo mkdir /home/pi/crap’. You need ‘sudo’ so fstab can mount it on boot, the final permissions of this mounted drive are set in the drives fstab line. In this case, ‘rw,umask=0′.

Linux Commands

To Do

This will return an empty string if /home/pi/video is NOT mounted.

Tags: linux, raspberry

©2017. Robert Cudmore.