Raspberry Pi – how to attach a USB drive

  linux, raspberry-pi

create directory mydrive, which is where we’ll mount the attached drive

sudo mkdir /mnt/mydrive

change permissions

sudo chown -R pi:pi /mnt/mydrive
sudo chmod -R 775 /mnt/mydrive/

look up the block id of the drive

sudo blkid
/dev/mmcblk0p1: SEC_TYPE="msdos" LABEL="boot" UUID="2D2D-CD16" TYPE="vfat" PARTUUID="eea0d6a7-01"
/dev/mmcblk0p2: UUID="2f840c69-cecb-4b10-87e4-01b9d28c231c" TYPE="ext4" PARTUUID="eea0d6a7-02"
/dev/mmcblk0: PTUUID="eea0d6a7" PTTYPE="dos"
/dev/sda1: LABEL="500g02" UUID="D4BE5EA9BE5E83C0" TYPE="ntfs" PARTUUID="e7f2080e-01"

Look for your drive as sda1 or similar, (not for mmc…, that’s the memory card).

If it’s not there, you need to debug the issue, maybe you don’t have +5VDC power attached.

Copy the UUID of your drive, ex: for my /dev/sda1 drive, the UUID is: “D4BE5EA9BE5E83C0” and the type is “ntfs”

 install ntfs-3g

sudo apt-get install ntfs-3g

edit the fstab file

sudo nano /etc/fstab

at the bottom of the file, add your drive’s UUID and type, such as “ntfs-3g”. You can use “ntfs-3g” even if “sudo blkid” tells you that your drive is simply “ntfs”

UUID=D4BE5EA9BE5E83C0 /mnt/mydrive ntfs-3g      uid=pi,gid=pi,umask=007 0       0

Save the fstab file, exit the editor

Check that it’s not yet mounted

ls -la /mnt/mydrive

tell the system to automount. When you reboot this will be mounted automatically. 

sudo mount -a

check that it’s now mounted

ls -la /mnt/mydrive