Introduction: Using a USB External Hard Drive With Your Raspberry Pi
In many cases SD capacity is not enough. Luckily Raspberry Pi can easily be connected to external USB hard drives. Follow the steps in this section, and you will soon have a lot more storage connected to your Raspberry Pi.
Step 1: Experimental Hardware Devices
Experimental hardware devices:
This experiment requires the following hardware:
- Raspberry Pi board.
- USB External hard drive.
This experiment requires the following software:
It is recommended that any USB external hard drive that you choose should be powered by an external power supply rather being powered by the USB port. In the past I have had bad experiences trying to power USB external hard drives from the Raspberry Pi USB port. Sometimes the Raspberry Pi was not even able to find the hard drive.
- Please plug the external hard drive into the Raspberry Pi USB connector.
Step 2: Make Sure That Your Raspberry Pi Software Is Up to Date
following commands to make sure your Raspberry Pi has the latest software.
$sudo apt-get update $sudo apt-get upgrade
This will update all the installed software on your Raspberry Pi.
Step 3: Verify That Your Raspberry Pi Is Able to Recognize the Hard Drive.
Execute the following command to confirm your
Raspberry Pi recognizes the hard drive that you plugged in.
$sudo fdisk -l
If you do not see it, you can fix it by following these procedures:
1. Reboot the Raspberry Pi
2. Make sure you are using an external power supply for your USB hard drive as the Raspberry PI USB port will probably not have enough power for it.
3. Do not use a USB Hub plug the hard drive directly into the Raspberry Pi.
4. Verify that your Hard drive, USB interface is using USB 2.0. My experience is that Raspberry Pi is unable to use USB 3.0 interfaces.
Step 4: NTFS Hard Drive Compatibility Software Driver Installation
the following command to install this software.
$ sudo apt-get install ntfs-3g
Step 5: Specify the Location Path That You Want to Mount the USB Hard Drive
Execute the following command to create the path you
want to use to mount the hard drive. The name "usbhdd" is for example, it can be whatever you like following Linux naming standards.
$ sudo mkdir /media/usbhdd
Execute the following command to set up the user rights for your hard drive path.
$ sudo chown pi:pi /media/usbhdd
Execute the following command to mount the hard drive so that you can use it. Specify // media / usbhdd path, using the name that you set up previously.
$ sudo mount -t vfat -o uid=pi,gid=pi /dev/sda1 /media/usbhdd
If an error message appears as in figure 5-3 this means there is a problem is the file format, make sure your hard drive is using the FAT32 format. If you want to format the hard drive in the Raspberry Pi, you can see the next chapter "Format HDD" for instructions. You can also plug the external hard drive into your favorite Windows PC and format it with the FAT32 format as well.
Step 6: Hard Drive Confirm Access
Now that we have defined a path and mounted the hard
drive, you can use this path and access information on the USB hard drive.
$ cd /media/usbhdd
If you want to remove the USB hard drive execute the
same instructions but substitute the unmout command for the mount command as show below.
$ sudo umount /media/usbhdd
Step 7: Set to Automatically Mount When the System Starts
It is a lot of trouble to have to mount the drive
Every time you want to use it so lets have the system automatically mount it when the system reboots.
As we are going to update one of the system Let's back up the file fstab configuration file before updating it by executing the following command.
$ sudo cp /etc/fstab /etc/fstab.backup
To accomplish what we need we have to obtain the UUID of the external hard drive. Executing the following command will this and a great deal more information as well.
So in my example you will see /dev/sda1: LABEL = "HD256G" UUID = "1599-18FA" TYPE = "vfat". The information that we need is UUID = "1599-18FA" and TYPE = "vfat". Your results will probably be different so you need to substitute your information when we edit the fstab file.
So now lets edit the fstab file by executing the following command.
$ sudo nano /etc/fstab
We will add a line in this file to describe the hard drive. Your UUID will be unique, so please update with your data. They of vfat probably will be same and everything else will be same.
UUID="1599-18FA" /media/usbhdd vfat rw,defaults 0 0
You can also use auto instead of vfat or ext3 to automatically have the system determine the hard disk format type. So then the line would like the following.
UUID="1599-18FA" /medusbia/hdd auto rw,defaults 0 0
Step 9: Test the Change for Auto Mount
This change can be tested quickly by executing the
Following command. If the /etc/fstab file is incorrect you will see an error message as indicated below.
$ sudo mount -a
To fix this go back and verify all the instructions
Have been correctly following and the text you entered is correct. After everything has been fixed and you have tested successfully, you can reboot your Raspberry Pi by executing the following command.
$ sudo reboot
Step 10: Final Testing
After reboot and after you Login to your Raspberry
Pi, you can verify success by executing the following command and you test accessing the external hard drive.
$ cd /media/usbhdd
We have a be nice policy.
Please be positive and constructive.