For some reason most people I know associate with removable media floppy disks at first. Once thinking it over they name the CD while talking of DVD as well. And finally they remember the USB stick at their key ring. Other generations might see that differently. However, I follow this sequence for my explanations.
I hate floppy disks, but some people do not stop using them for data transfer. Since my computer (a quite old one) does have a floppy drive, it is a good object for practice. So I start with two entries in the file /etc/auto.master. They will provide two different ways to mount a floppy:
# # /etc/auto.master # /auto /etc/auto.auto --timeout 5 /img /etc/auto.img
Please note that the first column denotes the file tree top level, i.e. the trees start with /auto and /img. Initially we only use /auto.
Most people are grown up with microsoft do like drive letters A and B for floppy. With the following entries in /etc/auto.auto
A -fstype=auto,sync :/dev/fd0 B -fstype=auto,sync :/dev/fd1you obtain the next hierarchy levels /auto/A and /auto/B. If you want to access /A you still need to put a symbolic link
ln -s /auto/A /AThis means you can easily access your floppy in drive A by using /auto/A or /A (B works in the same way). After 5 seconds of inactivity the floppy is umounted and may be removed.
Since I only have one floppy drive in some of my systems and I do have many devices in my auto directory, I prefer more verbose names like floppy instead.
floppy -fstype=auto,sync :/dev/fd0
In this case you need to use the link command
ln -s /auto/floppy /A
I thought of some solution for my amount of floppy discs, but while thinking it occured to me, that I might copy all those images to a single CDROM and do some loop mounts to them. Since I did not want to mount all those images at startup, nor did I want to add another mount entry for each new image, I thought for a better solution.
The alternative of mounting images of floppies assumes a directory, where the images are collected. You can collect the images by a trivial command like (the extension .img is arbitrarily chosen):
dd if=/dev/fd0 of=/floppydir/XXX.img
You sure know that you have to exchange XXX for each floppy you copy by a more verbose string that always differs. In order to access those images I recommend the following /etc/auto.img:
* -fstype=auto,loop,ro :/floppydir/&.img
Whenever you want to access the contents of the file /floppydir/XXX.img you only need to look into /img/XXX. Please note, that I assumed the directory is read-only since it is thought to contain archived material.
USB sticks are quite common and simple to use with most recent Windows systems. There is no reason to make it more complicated with Linux. Here is how I would extend the /etc/auto.auto from the previous example.
floppy -fstype=auto,sync :/dev/fd0 usb1 -fstype=auto,sync :/dev/sda1 usb2 -fstype=auto,sync :/dev/sdb1 usb3 -fstype=auto,sync :/dev/sdc1 usb4 -fstype=auto,sync :/dev/sdd1 usb5 -fstype=auto,sync :/dev/sde1Please note that I assumed you do not have any SCSI disks in your system (then you might need to change /dev/sda1 to /dev/sdb1 or other letters and so on).
The situation for a single USB stick is not complicated. If you got more and you want to use them simultaneously you add more entries which must have different names.
The situation is less trivial if you are using partioned usb devices. You only know the base device, let us say it is /dev/sda. But if you are using different Harddisks (I have two "BlueEye"s: one with a single partition another with 5 partitions.) you easily get confused.
Again I extend the previous configuration master file
# # /etc/auto/master # /auto /etc/auto.auto --timeout 5 /img /etc/auto.img /usb /etc/auto.usb --timeout 10where the /etc/auto.usb is file with this
* -fstype=auto,sync :/dev/sd&which allows me to access the partition /dev/sda1 by using /usb/a1. Some people prefer to get it "more" structured. They need two files. One is /etc/auto.usb
* -fstype=autofs,-Ddisk=& file:/etc/auto.usbsubwhich references the other configuration file /etc/auto.usbsub
* -fstype=auto,sync :/dev/sd${disk}&
This combination lets you access the partition by
/usb/a/1.
As you see it is easy to make things complicated.
Here I stay with the simple solutions.
The most common usage for the automounter is the NFS mount. The reason is obvious, if you look to the following example. There are two machines alpha and beta. alpha exports the directory /one, while beta exports the directory /two. Both machines need both directories and they need the directories on a reliable base, i.e. hard mounted. When one machine goes down, each process on the other machine that accesses the mount freezes. If you now reboot the remaining machine, it does not come up, since it waits for completeing its mounts (in case you made an entry /etc/fstab. Otherwise you have to mount that drive manually after each reboot).
In case both machines go done (e.g. no UPS) you get a race condition. Both machines wait for each other to provide NFS disks, which they will be able only if they have completed their own mounting. If you are looking for relieve, you find it with the automounter.
Most Automounters implement a special map called -hosts. This term is used in /etc/auto.master instead of the indirect map names (the files that are called auto.*). Autofs is different. The entry in /etc/auto.master looks usual:
/net /etc/auto.netbaseThe map resolution is implemented in a transparent way which involves a two-layer configuration, i.e. first layer is the host and the second layer is the exported/imported directory. Practically it does not resolve the directory in the top level configuration file /etc/auto.netbase
* -fstype=autofs,-Dhost=& file:/etc/auto.netsubbut reference the file /etc/auto.netsub.
* ${host}:/&
In that map the host is a given variable, while the directory needs
to be added. The wildcard at the beginning of the line matches any
expression, while it is inserted for the ampersands on the rest of the line.
With the -Dvar=val a value val can be assigned to
a variable var. It will be passed to the terminating map
reference at the end of the line like an exported shell variable.
And substitution works also exactly like shell replacements again.
If you look more closely to the example, you will find many similarities in the structure with the USB disk example.
Using this is very simple. Just type
ls -l /net/alpha/one /net/beta/twoand it works on both hosts (if export isn't restricted to the opposite only). Since the mounts will disappear after the have not been used for a certain time (default is 10 minutes), it might be a good idea to reference them with a symbolic link. You may use the following to obtain to symbolic links
ln -s /net/alpha/one /project/one ln -s /net/beta/two /project/twothat never vanish and can be parsed by any browser. Nevertheless, the file systems are still mounted on demand. Since there is no preview in the automounter controlled directory levels you might want to use
showmount -e betato see the exportlist of beta. If you do not know about the hosts you can ask for filesystems, it might be useful to ping the local subnet broadcast. For a class B network 10.168.0.0 it reads
ping -b 10.168.255.255Please remember that for establishing a NFS mount both sides need to know the otheres hostname symbolically and correct. Otherwise there are many security mechanisms that may inhibit the mount.