Raspberry Pi

How to connect/mount the harddrive with the Raspberry Pi 4

Sometimes we have to transfer data from some portable hard drive to the Raspberry Pi, mostly when we connect the hard drive with Raspberry Pi, it will mount automatically and we can use the hard drive. But in case, if it does not automount, then we can use the terminal to mount the hard drive using a few simple commands.

The connection of the hard drive is similar to the connection of the USB with Raspberry Pi. In this write-up, we will learn the procedure to mount the hard drive with Raspberry Pi.

How to mount the hard drive with Raspberry Pi

There are two ways to mount the hard drive with the Raspberry Pi either by manually or automatically, we will discuss both the methods in detail but before proceeding towards it, we will update the repository of the Raspberry Pi using the command:

$ sudo apt update

How to mount the hard drive manually with the Raspberry Pi

To mount the hard drive with the Raspberry Pi, first we have to find out the UUID details and location of the device, for this purpose, we will run the following command:

$ sudo blkid

The UUID of the hard drive which is labeled with the name “WD Unlocker” is “550e29b200000000” and the location of the hard drive is /dev/sr0. After this, we will make a directory of “MyHardDisk” in the media folder using the command:

$ sudo mkdir /media/MyHardDisk

The above directory is made to mount the hard drive in it, so we will change the access permissions of the newly created directory so that it can be accessed by the Pi user of the Raspberry Pi using the command:

$ sudo chown -R pi:pi /media/MyHardDisk

Now we will mount the harddrive by using its location that is “/dev/sr0” and the directory path “/media/MyHardDisk” where it is supposed to be mounted:

$ sudo mount /dev/sr0 /media/MyHardDisk -o uid=pi, gid=pi

We can see the mounted Hard drive on the desktop:

To unmount the Hard drive, we have to run the following command:

$ sudo umount /media/MyHardDisk

We can confirm from the desktop that the hard drive has been unmounted:

How to mount the hard drive automatically on the Raspberry Pi

In the above-discussed method, we have to mount the hard drive every time the Raspberry Pi has been started, so another way to mount the hard drive is by automatic method, it will mount automatically when the Hard Drive is inserted in the Raspberry Pi. For this purpose, we have to first open the file of fstab using a nano editor:

$ sudo nano /etc/fstab

Type the following line in the file and change the UUID according to your unique UUID of the hard drive:

$ UUID=550e29b200000000 /media/myHardDisk vfat auto,nofail,noatime,users,rw,uid=pi,gid=pi 0 0

Save the file by using the shortcut key of CTRL+S, then exit the editor and reboot the Raspberry Pi using the command:

$ reboot

When the system is restarted, you can see the mounted hard drive on the desktop screen of Raspberry Pi.

Conclusion

The hard drive has a large storage capacity as compared to the USB so it is used to back up the data of the system as well as it has a longer life and high speed. By default, the hard drive can be mounted with the Raspberry Pi automatically but sometimes it does not mount automatically. In this write-up, we have explored the methods to mount the hard drive with the Raspberry Pi both manually as well as automatically.

About the author

Hammad Zahid

I'm an Engineering graduate and my passion for IT has brought me to Linux. Now here I'm learning and sharing my knowledge with the world.