[Ubuntu] How to mount the external hard drive permanently
I will introduce this topic with a real example. The scenario is that I have two external NTFS hard drives. I want them to behave like the partition on Windows, like D drive, E drive something. However, every time when the Ubuntu is rebooted, those two hard drives are mounted to the path /media/<username>/<label name>
and they are read-only.
I wrote a temporary solution for the above issue, but it stil requires to execute the command every time when PC boots. This post will give a one-go solution.
Before trying the solution, make sure that the hard drives are unmounted. The solution is
sudo mkdir /media/windows1
sudo mkdir /media/windows2
sudo vi /etc/fstab
# Configure the mount record, see below
sudo mount -a
There is a file /etc/fstab
which is responsible for maintaining the mounting partition on Ubuntu. It looks like below.
cat /etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point> <type> <options> <dump> <pass>
# / was on /dev/nvme0n1p2 during installation
UUID=34987fb7-46e7-4a74-a63e-ee73fb7e033d / ext4 errors=remount-ro 0 1
# /boot/efi was on /dev/nvme0n1p1 during installation
UUID=2142-6826 /boot/efi vfat umask=0077 0 1
/swapfile none swap sw 0 0
For solving this issue at once, we need to add the records of two hard drives including UUID, mount point and other information.
Take the NTFS hard drive as an example, we can simply add the below line at the end of the file for each hard drive:
/dev/hda2 /media/windows ntfs-3g defaults,locale=en_US.utf8 0 0
The first parameter /dev/hda2
is the /dev location, but it also can be UUID, or LABEL. You can simply find the UUID and LABEL of the hard drive with sudo blkid
. And it will show the output like below:
/dev/hda1: LABEL="InternalStorage" UUID="F9F4FD4FD4FE101C" TYPE="ntfs" PARTUUID="c53b3b2a-01"
So, the record can be like
UUID=F9F4FD4FD4FE101C /media/windows ntfs-3g defaults,locale=en_US.utf8 0 0
# or
LABEL=InternalStorage /media/windows ntfs-3g defaults,locale=en_US.utf8 0 0
The second parameter /media/windows
is the mount point. In my case, I have to create two directories under /media
. Let’s say
mkdir /media/windows1
mkdir /media/windows2
For the other parameters, we can leave it as it is. It is totally fine. Or you can dive /etc/fstab
configuration deeper into Ubuntu Fstab explanation
At the end, my fstab configuration might look like
/dev/hda1 /media/windows1 ntfs-3g defaults,locale=en_US.utf8 0 0
/dev/hdb2 /media/windows2 ntfs-3g defaults,locale=en_US.utf8 0 0
To make the changes effect immediately, we can run sudo mount -a
If this post helped you to solve a problem or provided you with new insights, please upvote it and share your experience in the comments below. Your comments can help others who may be facing similar challenges. Thank you!