首页 > 代码库 > Automount configuration in /etc/fstab

Automount configuration in /etc/fstab

Write something like this to automatically mount system drive:

/dev/sda1    /media/win-c    ntfs-3gauto,rw,suid,exec,async,users,locale=zh_CN.UTF-8 0 0

The windows NTFS drive cannot be displayed in “df” command. It should be displayed by using “sudo fdisk -l /dev/sda” command.

1377 AM 09:51:39 The disk path such as /dev/sda1 had better be written as the UUID of that partition, for example,

UUID=A8B06D66B06D3C46       /media/win-c   ntfs-3g auto,rw,suid,exec,async,users,locale=zh_CN.UTF-8 0 0    

All the UUID can be listed by using ls -l /dev/disk/by-uuid/:

total 0 lrwxrwxrwx 1 root root 10 Jul  7 08:50 a34b828f-fded-4ac7-ae9b-b6d722a53479 -> ../../dm-2 lrwxrwxrwx 1 root root 10 Jul  7 08:50 A8B06D66B06D3C46 -> ../../sda2 lrwxrwxrwx 1 root root 10 Jul  7 08:50 bbbdc7a4-e27d-4fd4-815a-318685b3bf70 -> ../../sdb5 lrwxrwxrwx 1 root root 10 Jul  7  2013 c70d26b7-413c-46ff-8e80-ccead0d43965 -> ../../dm-1 lrwxrwxrwx 1 root root 10 Jul  7 08:50 DED06369D06346BD -> ../../sda1 lrwxrwxrwx 1 root root 10 Jul  7  2013 f55427a0-a3c7-48c1-9ebf-8b2570ed4413 -> ../../dm-0 lrwxrwxrwx 1 root root 10 Jul  7 08:50 FE4474AF44746C71 -> ../../sdb1 

The meaning for various options are as follows:

  • ntfs-3g:

  • auto/noauto: auto mount at boot

  • user/nouser: allow any user to manually mount the partition. By default, only super user is allowed to do this. However, if a user mounts a partition, he himself should unmount it.

  • users: if this option is used instead of user, then a user mounts a partition, another user can unmount it. In the manual of mount, it reads:

    users Allow every user to mount and unmount the filesystem. This option implies the options noexec, nosuid, and nodev (unless overridden by subsequent options, as in the option line users,exec,dev,suid).

    From this, we can also see that the order of the options are important.

  • ro: mount the drive as read-only

  • rw: mount the drive as read and write

  • uid, gid: mount as a certain user and group.

  • umask/fmask/dmask: umask is used to mask the permission bits of files and folders. fmask only masks files, while dmask only masks folders.

From the manual of mount:

Mount options for ntfs        iocharset=name               Character set to use when returning file names.  Unlike VFAT, NTFS suppresses names that contain unconvertible characters. Deprecated.        nls=name               New name for the option earlier called iocharset.         utf8   Use UTF-8 for converting file names.        uni_xlate={0|1|2}               For  0  (or  `no‘ or `false‘), do not use escape sequences for unknown Unicode characters.  For 1 (or `yes‘ or `true‘) or 2, use vfat-style               4-byte escape sequences starting with ":". Here 2 give a little-endian encoding and 1 a byteswapped bigendian encoding.        posix=[0|1]               If enabled (posix=1), the filesystem distinguishes between upper and lower case. The 8.3 alias names are presented as hard links instead of               being suppressed. This option is obsolete.        uid=value, gid=value and umask=value               Set the file permission on the filesystem.  The umask value is given in octal.  By default, the files are owned by root and not readable by               somebody else. 

About ntfs-3g:

ntfs-3g is an NTFS driver, which can create, remove, rename, move files, directories, hard links, and streams; it can read and write files, including streams and sparse files; it can handle special files like symbolic links, devices, and FIFOs; moreover it can also read and create transparently compressed files.

It can be written in a /etc/fstab entry like the above. According to its manual, it has its own options. Finally, the ntfs related fstab entries on my computer are:

UUID=A8B06D66B06D3C46       /media/win-c    ntfs-3g auto,rw,suid,nouser,uid=1000,gid=1002,umask=002,noexec,async,locale=zh_CN.UTF-8 0 0 UUID=FE4474AF44746C71       /media/win-d    ntfs-3g auto,rw,suid,nouser,uid=1000,gid=1002,umask=002,noexec,async,locale=zh_CN.UTF-8 0 0