Whenever I start my distro, be it Ubuntu or Fedora, I have to undergo an
additional step of mounting my drives.
Rather than obvious discomfort of manual mounting when you want to access data, it also has other negatives like –
- Some applications like DC and Clementine save path to download folder / music folder and throw error when these drives are unmounted. This could be avoided if some drives are auto-mounted on boot.
- C: of windows is particularly problematic. Tinkering with this folder in linux may cause errors thrown in Windows. This could be avoided if the C: mounted in a read-only format.
- There are other partitions made by Windows which are not visible in windows but are plain visible in linux such as EFI System, DIAGS and PBR Image etc . These are better left alone as tinkering with them may cause failure in windows boot. This could be avoided if these drives are not visible in the list of drives. , i.e, auto hidden. There is no need to mount these drives anyway.
My system
I have a 1 TB hard disk with Windows 8 dual boot. Besides the partitions created by windows and windows C:, I also have two additional drives (D: and E: in windows) where I keep all my important data. This data should be accessible by both my linux distro and windows.
I. Gather system information
To check the various drives present on your system Use the blkid command.
$ sudo blkid
/dev/sda1: SEC_TYPE="msdos" LABEL="DellUtility" UUID="5450-4444" TYPE="vfat"
/dev/sda2: LABEL="RECOVERY" UUID="6640CCF340CCCB4F" TYPE="ntfs"
/dev/sda3: LABEL="OS" UUID="94C855F4C855D4D8" TYPE="ntfs"
/dev/sda5: LABEL="Data" UUID="CA1224B11224A503" TYPE="ntfs"
/dev/sda6: LABEL="Extra" UUID="92562FB9562F9CCB" TYPE="ntfs"
/dev/sda7: UUID="33df1e45-0b4d-4d11-8971-fb1957776554" TYPE="ext4"
I have a total of 6 partitions present on my hard disk. Recognise the various drives in this output.
We have,
- Windows recovery partition : “Recovery” of type ntfs having UUID : 6640CCF340CCCB4F. It should be hidded on boot.
- “DellUtility” partition of type vfat and UUID : 5450-4444. This is most probably boot related partition and is auto-hidden. So no changes required.
- A ntfs drive labelled “OS” with UUID : 94C855F4C855D4D8. This is the C: of the windows. It should be mounted with read only permissions.
- D: for windows having the label “Data” of type ntfs and UUID : CA1224B11224A503. It should be auto-mounted.
- E: for windows having the label “Extra” of type ntfs and UUID : 92562FB9562F9CCB. It should be auto-mounted.
- The linux ext4 type drive representing the root (“/”) of linux file system.
To help recognise the various drives, one can use the following commands.
1. sudo fdisk -l -u
2. lsblk
Output of lsblk on my system.$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 698.7G 0 disk
├─sda1 8:1 0 39.2M 0 part
├─sda2 8:2 0 13.3G 0 part
├─sda3 8:3 0 106.3G 0 part
├─sda4 8:4 0 1K 0 part
├─sda5 8:5 0 244.1G 0 part
├─sda6 8:6 0 234.9G 0 part
└─sda7 8:7 0 100G 0 part /
sr0 11:0 1 1024M 0 rom
II. Make mount-points
For auto mounting the D: and E: and read-only mount of C:, we need locations to mount them. On manual mounting, the drives are generally present at /media or /run/media.
For auto-mount and read-only mount, we will create folders in /media folder and for hidden drives, we will create folder in /mnt. This is only by convention. Any path can be given.
1. For auto mount of D: named “Data”, we create a folder named /media/data
$ sudo mkdir /media/data
2. For auto mount of E: named “Extra”, we create a folder named /media/extra $ sudo mkdir /media/extra
3. For read only mount of C:, create a folder named /media/os (Name can be anything) $ sudo mkdir /media/os
4. For the other hidden drives, create corresponding folders in /mnt folder. $ sudo mkdir /mnt/recovery
III. Backup and edit the fstab
Now for the final part.
Open /etc/fstab file and edit it using the above details from blkid and locations of folders. The steps are as follows.
1. Backup the fstab file (Should anything fail.) $ sudo cp /etc/fstab /etc/fstab.bkp
2. Open fstab using any editor. I am using nano as an example. $ sudo nano /etc/fstab
This is what I get :
--------------------------------------------------------------------------------------------- # /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).
#
#
# / was on /dev/sda7 during installation
UUID=33df1e45-0b4d-4d11-8971-fb1957776554 / ext4 errors=remount-ro 0 1
---------------------------------------------------------------------------------------------
Comments start with a hash.
The format is as mentioned on the top of default fstab is
1. To add D: and E: to automount on boot, add these line to fstab
UUID=CA1224B11224A503 /media/data ntfs-3g defaults,uid=1000,gid=1000,windows_names,locale=en_US.utf8 0 0
UUID=92562FB9562F9CCB /media/extra ntfs-3g defaults,uid=1000,gid=1000,windows_names,locale=en_US.utf8 0 0
The uid=1000,gid=1000 are important options. They enable trash collection in the auto mounted drives. In absence of this, whenever you try to trash any file, you get the ugly message “Cannot move file to trash, do you want to delete immediately?”.
2. For read-only mount of C:, add the following lines to the fstab
UUID=94C855F4C855D4D8 /media/os ntfs defaults,umask=222 0 0
Here, umask=222 denotes the read-only option. It masks the write bit from permissions and hence no one has any write permission for the C: mounted at /media/os
3. For hiding of drives like the recovery, pbrimage etc, add the following lines to the fstab.
UUID=6640CCF340CCCB4F /mnt/recovery ntfs noauto,umask=222 0 0
noauto along with read-only options are enough for hiding these drives.
Now, if you still want to mount any of the above drives, execute the following command using appropriate path. For ex.
$ sudo mount /mnt/recovery
The final file along with comments are shown here.
---------------------------------------------------------------------------------------------
# /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).
#
#
# / was on /dev/sda7 during installation
UUID=33df1e45-0b4d-4d11-8971-fb1957776554 / ext4 errors=remount-ro 0 1
#Read only mount of C:
UUID=94C855F4C855D4D8 /media/os ntfs defaults,umask=222 0 0
#Disable mounting of Recovery
UUID=6640CCF340CCCB4F /mnt/recovery ntfs noauto,umask=222 0 0
#Mounting D: and F:
UUID=CA1224B11224A503 /media/data ntfs defaults,uid=1000,gid=1000,windows_names,locale=en_US.utf8 0 0
UUID=92562FB9562F9CCB /media/extra ntfs defaults,uid=1000,gid=1000,windows_names,locale=en_US.utf8 0 0
---------------------------------------------------------------------------------------------
4. Finally save the file and exit.
5. Run the following command for the changes made in fstab to be realised.
$ sudo mount -a
Tada.. all the unnecessary drives are hidden and D: is auto mounted. You can crosscheck by restarting.
Enjoy.
If you love GUI-ways, ‘pysdm’ is a handy gui tool that can be used for all the above said things.
Install using the following command.
$ sudo apt-get install pysdm
References