Auto Mounting Drives in Ubuntu

If you are using Ubuntu in dual mode with Windows you must be having a few partition that are NTFS. By default these NTFS drives are not auto mounted. So while you have the partitions, you won’t be able to access them if you don’t mount it.

As you already may know that in Ubuntu (and Linux in general) there are no drives. Combine it with the fact that the root directory starts from a forward slash (/). Every drive in Linux is ‘mounted‘. So when you insert a DVD disk the content of the disk may be mounted to a directory /media/username/DvdLabel. Here DvdLabel is the name of the mounted directory which was taken from the label of the disk.

Similarly if you have a partition with the label, say, Documents when you click the Documents partition, it is then that the Documents partition (or drive) is mounted to /media/Documents.

By default Ubuntu doesn’t mount the partitions when it starts. You have to click the partition in Nautilus (or Files, the file explorer) once so that it can be mounted. This can be irritating since when an application starts which requires a partition they will result in error. Eg, if you have set dropbox to sync to files to Documents drive or Transmission to download files to Multimedia drive.

You can make these NTFS drives automount with Ubuntu by various method as described in this page. But its a long and complicated read. So here is the method explained simply.

Find out Label and UUID

First you need to know the exact Labels and UUID of the drives. Consider UUID (Universally Unique Identifier) as a unique identifier for the drive which will never change (unless you format the drive, re-partition it, or manually change it). To know the Label and UUID you need to use the command blkid command. This command when used with sudo will give you a list of all the partitions along with its Label and UUID. Like below:

vyom@VyomNix:~$ sudo blkid
[sudo] password for vyom: 
/dev/sr0: LABEL="Alpha_0515" TYPE="udf" 
/dev/sda1: UUID="30986b83-1234-4eeb-a30a-482223df145f" TYPE="ext4" 
/dev/sda2: LABEL="WinServer" UUID="3F1234AB1233423C" TYPE="ntfs" 
/dev/sda3: LABEL="Recovery" UUID="A12345E12345AF1B" TYPE="ntfs" 
/dev/sda4: UUID="0659-9A568" TYPE="vfat" 
/dev/sda6: UUID="b1234321-ad5f-4ddd-89ac-eed1234c56c7" TYPE="swap" 
/dev/sda7: LABEL="Digital" UUID="33FA6E12GA6DF687" TYPE="ntfs" 
/dev/sda9: LABEL="Entertainment" UUID="123FHE3E3N98BF65" TYPE="ntfs" 
/dev/sda10: LABEL="Documents" UUID="37MME50B21B7C65B" TYPE="ntfs" 
/dev/sda11: LABEL="Spare1" UUID="654EF123456CAF7E" TYPE="ntfs" 
/dev/sda12: LABEL="Spare2" UUID="68D774EB5DBFPOOI" TYPE="ntfs" 
vyom@VyomNix:~$

Edit the fstab file

Now we need to edit the /etc/fstab file. Before doing so its a good idea to make a copy of the file. Below I have used the Terminal to first copy and then open the file in gedit text editor:

sudo cp /etc/fstab /etc/fstab.bak
sudo gedit /etc/fstab

Once the file opens you can see that few partitions (Ubuntu partition and swap) must already be having entries. You can add the entries for NTFS drives at the end of this file. Here is what my file looked like after I added the entries.

# /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/sda1 during installation
UUID=30986b83-1234-4eeb-a30a-482223df145f /               ext4    errors=remount-ro 0       1
# /boot/efi was on /dev/sda4 during installation
UUID=0659-9A568  /boot/efi       vfat    defaults        0       1
# swap was on /dev/sda6 during installation
UUID=b1234321-ad5f-4ddd-89ac-eed1234c56c7 none            swap    sw              0       0

#These lines added later

#Mounting WinServer which was /dev/sda2 BUT in Read-Only mode
UUID=3F1234AB1233423C  /media/WinServer  ntfs  defaults,umask=222  0 0

#Mounting Digital which was /dev/sda7 in Read-Write mode
UUID=33FA6E12GA6DF687  /media/Digital  ntfs-3g  defaults,windows_names,locale=en_IN  0 0

#Mounting Entertainment which was /dev/sda9 in Read-Write mode
UUID=123FHE3E3N98BF65  /media/Entertainment  ntfs-3g  defaults,windows_names,locale=en_IN  0 0

#Mounting Documents  which was /dev/sda10 in Read-Write mode
UUID=37MME50B21B7C65B  /media/Documents ntfs-3g  defaults,windows_names,locale=en_IN  0 0

#Mounting Spare1  which was /dev/sda11 in Read-Write mode
UUID=654EF123456CAF7E  /media/Spare1  ntfs-3g  defaults,windows_names,locale=en_IN  0 0

#Mounting Spare1  which was /dev/sda12 in Read-Write mode
UUID=68D774EB5DBFPOOI  /media/Spare2  ntfs-3g  defaults,windows_names,locale=en_IN  0 0

#Making Recovery partition NOT TO MOUNT, since I don't require it  which was /dev/sda3
UUID=A12345E12345AF1B  /mnt/Data  ntfs  noauto,umask=222  0 0

Following points are to be noted here:

1. Lines beginning with # are comments, which are ignored. So you can use it to write your own descriptions or link to this article for future reference.

2. I have taken the UUID of every drive I needed to automount and put that in a separate line along with other parameters (explained below).

3. Second parameter (after UUID) is the path where I want the drive to be mounted. You can choose any name for the directory under /media. I have chosen the label names.

4. The first drive WinServer is mounted as Read-Only by adding the following parameter. This will mount the drive in read-only mode and won’t allow modification of any file in any manner. You can use this to avoid accidental modification of the files of other OS drives. I consider this as one of the most useful feature of using automounting.

ntfs  defaults,umask=222  0 0

5. The second drive Digital is added as Read-Write partition which is like a normal drive, by adding following parameter:

ntfs-3g  defaults,windows_names,locale=en_IN  0 0

6. I have prevented the partition Recovery to mount by adding following parameters. This even prevents it from appearing in Nautilus so you can’t mount it even accidentally.

ntfs  noauto,umask=222  0 0

7. The locale information in my case is en_IN. In your case you can find out the exact locale by locale command in a separate Terminal window, like such:

vyom@VyomNix:~$ locale
LANG=en_IN
Summary and Conclusion

In Ubuntu each disk is mounted to a subdirectory of /media and the name of that subdirectory depends on the label of the disk which is being mounted. You can automount the partitions when Ubuntu boots by adding entries for each partition in file /etc/fstab. For this you would need UUID for the partition which you can get using the blkid command. You can make the partitions mount in Read-Only by specific parameters as explained above. At first this Automounting exercise may seem extra work, but its not considering the freedom that Ubuntu gives you in mounting a drive as per your own requirements.

Leave a Reply