####[ How-Do-I Documents ]######################################
Sub : User mount of devices HDI #006
How-Do-I mount devices as an user on a stand-alone system ?
################################################################
1 Introduction.
1.1 This is applicable for stand-alone workstations and
laptops. For any system on a network this is NOT TO BE
DONE for security considerations.
1.2 Normally, under *nix/ Linux, devices are mounted with
root privileges, as a consequence:
o You need to su to root (or log in as root) to access
devices, inclusive of removable media.
o Write access is normally not available, which may be
quite bothersome for removable media like floppies
and pen drives.
2 Why this HDI has been written
2.1 This HDI documents the process of how devices can be
mounted as any user by just some tweaking of the file
/etc/fstab.
3. Getting to do the thing
3.1 The file /etc/fstab is read at boot time by the init
process, and all partitions and devices are mounted
as per the settings there. For details of all options
available check man pages for fstab and mount.
3.2 A typical /etc/fstab would look something like this.
The example below is of a dual boot system with Win-
XP on hda1, and Linux on hda2, with separate parti-
tions for /home and /var in extended logicals, and
hda3 committed to a 32-bit vfat/ DOS partition where
data maybe shared between Windows and Linux. Since XP
is loaded on hda1 on a NTFS partition, it is being
ignored in fstab, write access to NTFS still being in
alpha.
/dev/hda1 /win-c ignore defaults 0 0
/dev/hda2 / ext3 defaults 1 1
/dev/hda3 /win-d vfat noauto,user 0 0
/dev/hda5 /home ext3 defaults 1 2
/dev/hda6 /var ext3 defaults 1 2
/dev/hda7 swap swap defaults 0 0
/dev/cdrom /mnt/cdrom iso9660 noauto,user,ro 0 0
/dev/fd0 /mnt/floppy auto noauto,user 0 0
/dev/sda1 /mnt/pen vfat noauto,user 0 0
proc /proc proc defaults 0 0
3.3 Please note that three devices, the CDROM, floppy and
the pen drive (all removable media) have their mount
points under /mnt which should pre-exist. Permissions
of 755 are adequate for regular use.
3.4 The file fstab contains descriptive information about
the various file systems. /etc/fstab is only read by
programs, and not written; it maintained manually by
the system administrator (which for a stand-alone box
would be you). Here is a brief description for each of
the fields:
3.4.1 The first field, describes the block special device or
remote filesystem to be mounted. (They are there under
your /dev directory).
3.4.2 The second field, describes the mount point for the
filesystem. These have to be created beforehand.
3.4.3 The third field, describes the type of the filesystem.
Linux supports lots of filesystem types (man mount for
further details). A 'ignore' statement in the third
field causes the line to be ignored. This is useful to
show disk partitions which are currently unused/ used
but would not be mounted.
3.4.4 The fourth field, describes the mount options associa-
ted with the filesystem. Of mention would be:
defaults ... mount at boot time as default
noauto ... do not mount when "mount -a" is given
(e.g. at boot time)
user ... allow a user to mount
owner ... allow device owner to mount
3.4.5 The fifth field, is used for these filesystems by the
dump command to determine which filesystems need to be
dumped. Please note, we have explicitly stated that
all removable media do not need dumping, and therefore
set to ZERO. Same for vfat partition. The rest are set
to ONE (dumping enabled).
3.4.6 The sixth field, is used by the fsck program to check
the order in which filesystem checks are done at each
reboot. The root filesystem should be specified with a
value of 1, and other filesystems should be set to 2.
If set to ZERO, fsck is not carried out (for non Linux
file systems and removable media).
4 Explaining sample /etc/fstab shown above
4.1 The example /etc/fstab is thus fully explained. The
things that we have done so far are:
a) At boot time loaded all Linux partitions and have
ignored the NTFS partition (hda1).
b) We have kept the Windows D drive (which is a vfat
partition at hda3) mountable by user but it is not
being mounted by default at boot.
c) We have kept all removable media user mountable.
4.2 In short, to have any file system mounted by an user,
set "user" and "noauto" in the fourth field. Features
of dump and fsck may also be turned off for remove-
able media, and non-linux file systems.
5 Mount(ing)/ umount(ing) as an user
5.1 This is absolutely straight forward. At the shell
prompt, merely suffix the 'mount point' (and not the
device) to mount or umount commands:
$ mount /mnt/win-d
$ mount /mnt/pen
$ umount /mnt/floppy ... etc.
If you are too lazy to do this much, you may write a
script to automate this too ! A script called 'mnt'
is linked in the scripts section of this site.
5.2 We have thus achieved two goals with this:
o The user can mount a device
o It is mounted with UID:GID of the user, and the
user, therefore, also has write access.
################################################################
6 Kudos and Brickbats
6.1 This document is released under GNU/ GPL license. You are
free to use and distribute this without any encumbrances
6.2 Any kudos and brickbats should be directed at:
USM Bish
15 Nov 2004