Linux Know-How provides a collection of introductory texts on often needed Linux skills.


Mounting Drives

You have to edit the file /etc/fstab as root to give the normal users the permission to mount a particular drive. For example I can use the pico text editor to do this:

pico -w /etc/fstab

The option "-w" turns off the long line wrap.

Here is the content of my /etc/fstab:

/dev/hda2 / ext2 defaults 1 1

/dev/hdc3 /home ext2 defaults 1 2

/dev/hdc2 /usr ext2 defaults 1 2

/dev/hdc4 swap swap defaults 0 0

/dev/fd0 /mnt/floppy auto noauto,users,rw 0 0

/dev/cdrom /mnt/cdrom auto noauto,user,ro 0 0

/dev/sda4 /mnt/zipdrive vfat noauto,user,rw,exec 0 0

/dev/hda1 /mnt/dosdrive vfat noauto,user,rw 0 0

none /proc proc defaults 0 0

hacker:/mnt/cdrom /mnt/hacker_cdrom nfs noauto,user,ro 0 0

hacker:/mnt/floppy /mnt/hacker_floppy nfs noauto,user,rw 0 0

hacker:/home /mnt/hacker_home nfs noauto,user,rw 0 0

hacker:/usr /mnt/hacker_usr nfs noauto,user,rw 0 0

Each line contains six space-delimited fields (this means that each line has six entries separated by white space). The first field is the name of the device. The second field is the mountpoint (an existing directory on your Linux system to which the resource will be mounted). The third is file system type. For removable media that may contain file systems of several types, I use the option "auto" to let Linux probe which file system is currently present there. (The order in which they are probed is determined by the content of the file /etc/file systems . You may want to make sure that it specifies "vfat" before "msdos" or the long DOS filenames may be cut short.) The fourth field contains options: "auto" = mount the file system on the system startup; "rw" = read and write allowed; "ro" = read only, "user" = users have the permission to mount this file system (one can also use "users" to allow a user to mount and another user to unmount--otherwise only the user that mounted the file system can unmount it), "exec" execution of programs is permitted from this file system. The number in the field 5 specifies if the file system is to be backed up during a system backup, the number in the field 6 determines if to check up the file system integrity during bootup. The hacker stuff in my /etc/fstab are file systems on another computer (called "hacker") on my home network and it serves here as an example of how to mount network resources. Check man fstab for more info.

For example, if regular (non-root) users have the permission to mount the cdrom (the "user" option is specified), they can mount it using a command like this:

mount /mnt/cdrom

The command which the root uses for mounting (see here) will not work for a regular user because the regular user is restricted by the options in /etc/fstab and therefore s/he cannot specify simultaneously both the device and the mountpoint.

For a regular user to be able to write to a disk or execute a program on it, s/he must also be given the appropriate permission on the "mountpoint" directory. For example, this will give all the users all the permissions (read, write, execute) on the directory /mnt/floppy:

chmod a+rwx /mnt/floppy

Now (also the "rw" option is specified for the floppy in the /etc/fstab) the user will be able to write to a floppy. If the "exec" option was enabled in the /etc/fstab, the user would also be able to execute programs from the floppy.

Please note that the DOS vfat file system doesn't know about the file permissions the way Linux does. Linux manages this during mounting by giving the default file permissions on the mounted file system: the user who mounted the file system will be the owner of all files and will be given the right to write to the file system (if "rw" was specified in /etc/fstab) but other users can only read. If you wanted to change this behaviour, you could use the "umask=" option so that the appropriate line in your /etc/fstab may look like this example:

/dev/sda4 /mnt/zipdrive vfat noauto,users,rw,exec,umask=000 0 0

This gives absolutely everybody all the permissions on your zipdrive (mounting, unmounting, read, write, execute).

To summarize, the file /etc/fstab is the place to keep your defaults on how to mount file systems and what kind of access is allowed for users. You really want to customize it to simplify mounting on your system. Linux default mounting scheme is restrictive so as to be secure, you may want to remove some restrictions when setting up Linux at home.


Last Update: 2010-12-16