how-to-permanently-mount-an-ntfs-external-hard-drive-to-a-linux-server How to Permanently Mount an NTFS External Hard Drive to a Linux Server

How to Permanently Mount an NTFS External Hard Drive to a Linux Server


by Lonnie Lee Best

External hard drives are typically partitioned with Microsoft Windows compatible file systems. Other operating system such as BSD, Linux, and Mac, contain software that allows them to both read and write to these drives. Usually, all you have to do is plug in the external drive and it automatically mounts so you can begin using it.

In the Linux world, Ubuntu Linux for example, does a good job auto-mounting your typically external or thumb drive. However, this is usually only true for the desktop versions of a particular Linux distribution. Server editions, especially ones without a desktop, do not auto-mount external hard drives.

In this article, I will show you how to permanently mount one of these typical, store-bought, ntfs, external hard drives in a manner that you can rely upon; meaning in a manner that survives a reboot and in manner where you can always be sure it will be this exact external hard drive (in the case that you have multiple external hard drives connected) that gets mounted to a particular path (or said another way: mount-point).

As mentioned previously, these drive usually come with a windows style partitioning. Although you could repartition the drive to have a Linux file system, there are some reasons you may want to just keep the windows style partitions. I my case, I intend for the external hard drive to be used as an off-site backup for an on-site backup server that is backing up windows machines. If it ever became necessary to use this off-site backup, it would be nice if the external hard drive was already on a file system that Microsoft Windows supported. This way, I could just unmount the external hard drive and take it on-site and hook it up directly to the windows machines. If it were on a Linux file system, this might slow me down during an emergency restore situation; it might require me to transfer the files to a windows file system before I could restore them. The larger the backup, the longer that would take.

Let’s Get Started

On an Ubuntu Linux server, install ntfs-3g to facilitate the mounting of ntfs partitions:

sudo apt-get install ntfs-3g

Now plug in the external drive, and discover it’s UUID using this command:

sudo blkid

Here’s an example what my external hard drive looks like to sudo blkid:
/dev/sdc1: LABEL="Seagate Backup Plus Drive" UUID="4E61ACB38747DB37" TYPE="ntfs"

You need to copy and paste the UUID somewhere, because we will need that later.

Now you need to make folder where you want the drive to be mounted. Since we are intending for this thing to mounted all the time, this folder would be best placed inside the /mnt folder. So we can create our mount-point folder like this:

mkdir /mnt/MountPointName

You can replace “MountPointName” with a more appropriate name for your situation. This is an arbitrary choice.

Next, we want to make the folder immutable. This prevents data being written to your root file system in the event that the drive (we will later mount here) somehow becomes unmounted. Here’s the command to make this mount-point folder immutable:

chattr +i /mnt/MountPointName

Each time your system boots, we want this drive to mount automatically. To do this, we will need to add an entry into the fstab file. Here’s how you can open that file:

sudo nano /etc/fstab

At the bottom of this text file, you will be adding a line that looks similar to this:

/dev/disk/by-uuid/xxxxxxxxxxxxxxxxx/ /mnt/MountPointName ntfs-3g defaults,auto,uid=xxxxxxx,gid=xxxxx,umask=xxx 0 0

Your browser might not show it, but this is to be entered as one whole line. Everywhere you see X’s, you are going to have to replace them with specific information for your own circumstances. So copy and paste that line into an editor like gedit, and I will advise you on what to replace the Xs with.

The first grouping of Xs, needs to be replaced with the UUID that I instructed you to take note of earlier. Each drive has a unique id, and by specifying this here, we are ensuring that this exact drive (in case you have multiple external hard drives) always gets mounted to this exact mount-point folder.

The second thing you need to replace is where it says “MountPointName”, this should instead be the name you chose earlier when you created you mount-point folder.

Next replace the Xs for the user id (uid=). For this, ask yourself which user on your system would best be considered “owner” of this external hard drive in terms of their ability to access it. Most people put “0″ (zero without quotes) here, to represent root (the administrator’s username). However, no matter what you put, root can always access it anyway. So, if you intend for this drive to only be used by one particular user, you should get that user’s id to put here. You can find a user’s id with this command:

id -u USERNAME

Replace “USERNAME” with the actual user-name you have in mind.

The next group of Xs is for the group id (gid=). If you do not intend for a group of users to be using this external hard drive, you can just put “0″ (zero without quotes) for the group id. If you do intend for a particular grouping of users to be able to access this external hard drive (assuming your have already created that group, added those users to the group, and know the group’s name), you’d find the group id like this:

getent group groupName | cut -d: -f3

Replace “groupName” above, with the actual group name.

If you haven’t already created the group, you can create a group like this:

groupadd groupName

Again, replace “groupName” with the name of the group you’re creating.

And, if you don’t know how to add users to that group, it can be done like this:

usermod -a -G groupName userName

Replace “groupName” and “userName”, with the actual group and user.

The last group of Xs is for the umask (umask=xxx). Earlier, you specified an owner (uid=) and a group (gid=). The umask will be be three numbers, each number will be a number 0 through 7, and here’s what the numbers 0-7 mean:

0 : read, write and execute
1 : read and write
2 : read and execute
3 : read only
4 : write and execute
5 : write only
6 : execute only
7 : no permissions

Of the 3 numbers you’ll specify, the first one will represent the owner’s permission for the external hard drive (the owner you specified via uid=). The second number will represent the group’s permissions when accessing the external hard drive. The third and last number, will represent all other users who are not the owner and do not belong to the group you specified.

So, for example, if you want only the owner to be able to access the file system of this external hard drive, you’d put 077 as the umask. If you wanted both the owner and the group to have full access you’d put 007 as the umask. If you wanted only the owner to have full access,but allow any one to at least read it (but not modify it), you could put 033. With these examples, and the key above, you should be able to come up with the umask that best meets your own needs.

So let’s look at that line again, now that you know what “all the stuff you need to replace” means:
/dev/disk/by-uuid/xxxxxxxxxxxxxxxxx/ /mnt/MountPointName ntfs-3g defaults,auto,uid=xxxxxxx,gid=xxxxx,umask=xxx 0 0

Now that you have this line modified, in your note pad, go back to the terminal. Remember, previously, you ran this command to open the fstab file:
sudo nano /etc/fstab

Use your arrow keys to get underneath the last line in this file. Once there, right-click and paste the fstab entry you’ve built. Then, hit ctrl-o to save. Last, hit ctrl-x, to return to the command prompt.

Now, every time you boot this server with this drive plugged in, it should mount the drive at the mount-point you specified.

However, there is no need to reboot right now. Simply enter this command:

sudo mount -a

Now this ntfs external hard drive should be mounted and stay mounted.

However, once I had a particular ntfs drive that would not stay mounted despite all of this! Here’s the workaround I settled for: Since my backups were scheduled to occur at times “on the hour”, I schedule a cron job that would ensure this flaky drive was freshly mounted five minutes before each hour.

sudo crontab -e

The first time you do this command you’ll get this at the command prompt:

Select an editor. To change later, run 'select-editor'.
1. /bin/nano <---- easiest
2. /usr/bin/vim.tiny

Just select one, and the add this to the bottom of the file that nano displays:

55 * * * * mount -a

After this, hit ctrl-o to save and then ctrl-x to exit.

Most drives stay mounted fine without these additional steps, but sometimes you get a drive that won't cooperate, and these final steps allowed me to at least ensure that these uncooperative drives would be mounted at the times I needed them to be.



Tell others about
this page:

facebook twitter reddit google+

About the Author

Lonnie Best has been using the internet since 1993, and has been making web pages since 1995. visit: www.lonniebest.com



Comments? Questions? Email Here

© HowtoAdvice.com

Next
How to Advice .com
Charity
  1. Uncensored Trump
  2. Addiction Recovery
  3. Hospice Foundation
  4. Flat Earth Awareness
  5. Oil Painting Prints
Send us Feedback about HowtoAdvice.com
NextPrevious