Tero Karvinen - Articles - Downloads - Courses - Contact

Mounttero - Technical details

This document describes technical details and manual configuration of mounttero. If you installed the rpm, it did all this configuration automatically and you don’t need manual configuration. The scripts below contain some latest and greatest version 0.5 improvements that have not made it to rpm yet, namely more usb partitions.

© 2004-2005 Tero Karvinen http://www.iki.fi/karvinen

Create the directories used by the automounter. The directory is the one mentioned in

/etc/auto.master

:

# mkdir -p /mnt/auto/autofs

Create auto.master to tell autofs daemon that /mnt/auto/autofs directory is handled according to auto.tero.

# /etc/auto.master
# mountpoint		map	options	# see also: man 8 autofs
/mnt/auto/autofs	/etc/auto.tero  --timeout=4

List the actual mountpoints and devices in the automounter map

# /etc/auto.tero 
# http://iki.fi/karvinen/linux/doc/automatic-mounting-autofs.html
# mountpoint_key options location_device # man 5 autofs
cdrom	-fstype=auto,ro,nosuid,nodev,user	:/dev/cdrom
cdrom1	-fstype=auto,ro,nosuid,nodev,user	:/dev/cdrom1
usb		-fstype=auto,nosuid,nodev,noexec,user,gid=100,umask=000	:/dev/sda1
# second and third partitions in usb device:
usb2	-fstype=auto,nosuid,nodev,noexec,user,gid=100,umask=000 :dev/sda2
usb3	-fstype=auto,nosuid,nodev,noexec,user,gid=100,umask=000 :dev/sda3
floppy	-fstype=auto,nosuid,nodev,noexec,user,gid=100,umask=000 :/dev/fd0

hda1            -fstype=auto,nosuid,nodev,user  :/dev/hda1
hda2            -fstype=auto,nosuid,nodev,user  :/dev/hda2
hda3            -fstype=auto,nosuid,nodev,user  :/dev/hda3
hda4            -fstype=auto,nosuid,nodev,user  :/dev/hda4

hdb1            -fstype=auto,nosuid,nodev,user  :/dev/hdb1
hdb2            -fstype=auto,nosuid,nodev,user  :/dev/hdb2
hdb3            -fstype=auto,nosuid,nodev,user  :/dev/hdb3
hdb4            -fstype=auto,nosuid,nodev,user  :/dev/hdb4

hdc1            -fstype=auto,nosuid,nodev,user  :/dev/hdc1
hdc2            -fstype=auto,nosuid,nodev,user  :/dev/hdc2
hdc3            -fstype=auto,nosuid,nodev,user  :/dev/hdc3
hdc4            -fstype=auto,nosuid,nodev,user  :/dev/hdc4

hdd1            -fstype=auto,nosuid,nodev,user  :/dev/hdd1
hdd2            -fstype=auto,nosuid,nodev,user  :/dev/hdd2
hdd3            -fstype=auto,nosuid,nodev,user  :/dev/hdd3
hdd4            -fstype=auto,nosuid,nodev,user  :/dev/hdd4

# Serial ATA (SATA) disks are IDE emulated in Linux 2.6
hde1            -fstype=auto,nosuid,nodev,user  :/dev/hde1
hde2            -fstype=auto,nosuid,nodev,user  :/dev/hde2
hde3            -fstype=auto,nosuid,nodev,user  :/dev/hde3
hde4            -fstype=auto,nosuid,nodev,user  :/dev/hde4

# (c) 2003, 2004-05-29, 2004-09-19 Tero.Karvinen atta iki.fi
# /etc/init.d/autofs restart

Now drives are automatically mounted when you try to access them. You can test it by inserting a cdrom, and

cd /mnt/auto/autofs/cdrom

. The CDROM is automatically mounted, and

ls

should show you contents of the cd. When you cd to another directory, such as home directory (

cd

), CDROM is umounted in four seconds and the eject button in the drive starts working.

To see which drives are mountable (have discs in drive), you can create symlinks (similar to shortcuts) to the mountpoints. You can create the symlinks manually for each drive, for example

	# cd /mnt/auto/<br />
	# ln -s autofs/cdrom cdrom

Or, if you are lazy, you can use this script

#!/bin/sh

# autotero.sh - automatically create symlinks for auto.tero autofs map.
# (c) 2004-05-29 Tero.Karvinen atta iki.fi, http://www.iki.fi/karvinen
# http://www.iki.fi/karvinen/linux/doc/automatic-mounting-autofs.html

MNT="/mnt/"

if [ -z $MAP ]; then
        MAP=`cat /etc/auto.master |gawk '/^[^#]/{print }'`
fi

if [ "0" != "$id" ]; then
        echo "Warning: You are currently not root. Try -t for test in current dir."
fi

if [ "-t" == "" ]; then
                echo "Testing only, directories and symlinks will be created to current dir"
                MNT=`pwd`
fi

cd $MNT
mkdir -p auto/  # for symlinks
cd auto
mkdir -p autofs # mountpoint 

# Create drives mentioned in auto.tero
MOUNTPOINTS=`cat $MAP|gawk '/^[^#]/{print }'`
for MPOINT in $MOUNTPOINTS
do
        echo $MPOINT
        ln -s autofs/$MPOINT $MPOINT
done
# autotero.sh

Now

ls /mnt/auto

shows unmountable devices as red, broken symlinks and mountable devices with normal colors. If you use tab to complete filenames, it only offers you mountable drives. For example,

cd /mnt/auto/c&lt;tab&gt;

fills the name to cdrom1 if cdrom0 does not have a disc inside.

If you don’t like copy-pasting, you can <a href=”http://iki.fi/karvinen/linux/doc/automatic-mounting-autofs-files“>dowload the scripts</a>. A beta quality RPM is available.

Well done, now you can enjoy moveable media without mounting them by hand.

Last modified: 2005-11-07. Permanent url: http://www.iki.fi/karvinen/mounttero_technical_details.html

Tero Karvinen www.iki.fi/karvinen - Top - Validate HTML - Validate CSS