Strog
January 18th, 2005, 14:18
I mounted my usb pen drive manually and decided it was time to automount cdrom/floppy/etc. again. I had it setup on my FreeBSD 4.1.1 play box years ago and haven't really touched it since. I discovered it was pretty easy to setup mounts in fstab with noauto and really hadn't gotten around to messing with it since. A quick google search gave me a couple good links to start with from the FreeBSD Handbook (http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/network-nfs.html#AEN33422) and Daemon News (http://www.daemonnews.org/200202/automounting.html). The Daemon News article was aimed at FreeBSD 4.x but it's close enough.
Automounter uses your fstab so I was halfway since I already had my devices in place with noauto set on them. These are the physical mount points. We are going to use another path for the dynamic. I'm using /floppy, /cdrom and /usb for my dynamic mounts but you can use whatever suits you.
/dev/fd0 /mnt/floppy msdosfs rw,noauto 0 0
/dev/acd0 /mnt/cdrom cd9660 ro,noauto 0 0
/dev/da0s1 /mnt/usb msdosfs rw,noauto 0 0
Add the following to your /etc/rc.conf. The default for the flags should be fine for now. You can tweak the timeout and other things later. Reboot or manually start these.
portmap_enable=YES
amd_enable=YES
We need to create a map file to set paths and options for autmount to use. Edit your /etc/amd.map
/defaults type:=host;fs:=${autodir}/${rhost};rhost:=${key}
* opts:=rw,grpid,resvport,vers=3,proto=udp,nosuid,no dev
localhost type:=auto;fs:=${map};pref:=${key}/
localhost/cdrom type:=program;fs:=/mnt/cdrom;\
mount:="/sbin/mount mount /mnt/cdrom";\
unmount:="/sbin/umount umount /mnt/cdrom"
localhost/floppy type:=program;fs:=/mnt/floppy;\
mount:="/sbin/mount mount /mnt/floppy";\
unmount:="/sbin/umount umount /mnt/floppy"
localhost/usb type:=program;fs:=/mnt/usb;\
mount:="/sbin/mount mount /mnt/usb";\
unmount:="/sbin/umount umount /mnt/usb"
Automount uses the dynamic path of /host/locahost/* for local mounts and then we'll symlink it to where we want from there. I removed my existing /cdrom since I need to symlink it. Don't create /host or /net since AMD will dynamically create these for local and network mount points respectively. We need to create /.amd_mnt for automounter to use and our mount points.
mkdir /.amd_mnt
ln -s /host/localhost/floppy /floppy
ln -s /host/localhost/cdrom /cdrom
ln -s /host/localhost/usb /usb
I did a cd /usb and /cdrom as a user and there's all my files. I did a mount a few minutes later and saw that both were unmounted. I like not needing to setup sudo to let my user mount/unmount these drives. The default idle time before automatically unmounting is 120 seconds (2 minutes) and that's perfect for the removable media I'm using. You may want to tweak that in the amd flags if you have other needs or are using it to mount network shares too. I did play with having AMD mount some SMB shares but it was being a pain with the passwords. I decided that I didn't really need these to mount and umount automatically as I usally just mount them and leave them mounted. NFS mounts are fairly straightforward using AMD too since it's really using NFS as the mechanism to make it work.
There's a lot more options using amd.conf (http://www.freebsd.org/cgi/man.cgi?query=amd.conf&sektion=5) and other amd (http://www.freebsd.org/cgi/man.cgi?query=amd&sektion=8) options. I like the example on Daemon News with using AMD to automatically unmount a spooler on a noisy drive and spin it down via camcontrol in a script. There's a lot of cool things you could do with this. I'm definitely going to have to play more with AMD but it's nice to have my removable media working nicely right now. :silly:
Automounter uses your fstab so I was halfway since I already had my devices in place with noauto set on them. These are the physical mount points. We are going to use another path for the dynamic. I'm using /floppy, /cdrom and /usb for my dynamic mounts but you can use whatever suits you.
/dev/fd0 /mnt/floppy msdosfs rw,noauto 0 0
/dev/acd0 /mnt/cdrom cd9660 ro,noauto 0 0
/dev/da0s1 /mnt/usb msdosfs rw,noauto 0 0
Add the following to your /etc/rc.conf. The default for the flags should be fine for now. You can tweak the timeout and other things later. Reboot or manually start these.
portmap_enable=YES
amd_enable=YES
We need to create a map file to set paths and options for autmount to use. Edit your /etc/amd.map
/defaults type:=host;fs:=${autodir}/${rhost};rhost:=${key}
* opts:=rw,grpid,resvport,vers=3,proto=udp,nosuid,no dev
localhost type:=auto;fs:=${map};pref:=${key}/
localhost/cdrom type:=program;fs:=/mnt/cdrom;\
mount:="/sbin/mount mount /mnt/cdrom";\
unmount:="/sbin/umount umount /mnt/cdrom"
localhost/floppy type:=program;fs:=/mnt/floppy;\
mount:="/sbin/mount mount /mnt/floppy";\
unmount:="/sbin/umount umount /mnt/floppy"
localhost/usb type:=program;fs:=/mnt/usb;\
mount:="/sbin/mount mount /mnt/usb";\
unmount:="/sbin/umount umount /mnt/usb"
Automount uses the dynamic path of /host/locahost/* for local mounts and then we'll symlink it to where we want from there. I removed my existing /cdrom since I need to symlink it. Don't create /host or /net since AMD will dynamically create these for local and network mount points respectively. We need to create /.amd_mnt for automounter to use and our mount points.
mkdir /.amd_mnt
ln -s /host/localhost/floppy /floppy
ln -s /host/localhost/cdrom /cdrom
ln -s /host/localhost/usb /usb
I did a cd /usb and /cdrom as a user and there's all my files. I did a mount a few minutes later and saw that both were unmounted. I like not needing to setup sudo to let my user mount/unmount these drives. The default idle time before automatically unmounting is 120 seconds (2 minutes) and that's perfect for the removable media I'm using. You may want to tweak that in the amd flags if you have other needs or are using it to mount network shares too. I did play with having AMD mount some SMB shares but it was being a pain with the passwords. I decided that I didn't really need these to mount and umount automatically as I usally just mount them and leave them mounted. NFS mounts are fairly straightforward using AMD too since it's really using NFS as the mechanism to make it work.
There's a lot more options using amd.conf (http://www.freebsd.org/cgi/man.cgi?query=amd.conf&sektion=5) and other amd (http://www.freebsd.org/cgi/man.cgi?query=amd&sektion=8) options. I like the example on Daemon News with using AMD to automatically unmount a spooler on a noisy drive and spin it down via camcontrol in a script. There's a lot of cool things you could do with this. I'm definitely going to have to play more with AMD but it's nice to have my removable media working nicely right now. :silly: