Mount a HDD on Linux permanently

Mount HDD
2 minutes read

I Hope you have installed a linux machine and now wondering how to add an external Hard Disk Drive. Let us start her by explaining the steps which can help you to achieve this successfully.

This would work on any linux machine, even on the big commercial servers. However, for my demonstration i have used a Raspberry pi with an external Seagate Hard Disk Drive.

If you are not aware of Raspberry Pi, then please check the blog “What is Raspberry Pi ?” and then to install OS(Raspbian) on Raspberry Pi check the blog “Starting/Booting Raspberry Pi“. You may also purchase a new Raspberry Pi(Purchase single unit or full package[recommended]) from amazon.

Mounting a Hard Drive

Check USB ports

Let us check if out Hard drive is connected to our USB port.

lsusb
_usb
List USB

Make a directory

Next we have to determine on which folder we are going to mount out Hard Drive. Let us create that folder by entering the following command.

sudo mkdir /media/nas
make_directory
Making Directory

List Drives

Let us get the Hard Drive partition name to mount on the above folder. The following command will list down all the partitions of all the disks attached to it.

sudo fdisk -l
List Drives
Listing Drives

Mount Drive

Now let us mount our Hard Disk Drive onto our created folder.

sudo mount /dev/sda1 /media/nas
Mount_Drive
Mount

Congratulations your Hard Disk Drive has been mounted onto your system. However you would notice that when you restart your system the mount link vanished and again you have to give the above mount command. To eradicate this issue let us make a permanent entry into the fdisk file.

Mount the HDD permanently

We will open up the fdisk file and make a permanent entry to auto-mount our hard drive upon boot.

Note:- Be very cautious for this step because any mistake will lead to non-bootable system.

Get the UUID

First let us find out the UUID (Universally Unique Identifier). This is unique for your Hard Drive, hence by using this there will not be any chances of error.

sudo blkid
UUID
Fetch UUID

We know that our drive is /dev/sda1 therefore please note down this corresponding UUID and the type of partition  for this Hard Disk Drive as we require this information to fill in the fstab file.

Make an entry in fstab file

Open the fstab file and make an entry in the following format.

sudo nano /etc/fstab

#<UUID> <mounting folder> <format type> defalts 0 0

UUID=7b48c2e0-8d9d-4bf3-9575-3d2145eb6fb2  /media/nas ext4 defaults 0 0
fstab file
fstab file

Now check by rebooting your server. It will mount itself automatically. You have successfully install your hard drive onto your server.

One Reply to “Mount a HDD on Linux permanently”

  1. Lovely blog! I am loving it!! Will be back later to read some more. I am bookmarking your feeds also

Leave a Reply