NetBSD: How to use automount daemon ‘amd’ to mount flash cards and cdrom


Due to some weird problem with Hal or PolicyKit in NetBSD, I’m not able to mount any SD card, not even my CDROM. So, one solution, more elegant in my opinion, is to use ‘amd’. In FreeBSD it’s pretty easy. In NetBSD I had to work very hard to do it, but, it’s finished.

Ok, let’s go with the code. First create an ‘/etc/amd.conf’ file with the following lines:

/etc/amd.conf

[ global ]
print_pid = no
unmount_on_exit = yes
restart_mounts = yes
search_path = /etc
dismount_interval = 5
cache_duration  = 5
browsable_dirs = yes
localhost_address = 127.0.0.1
log_file = syslog
#log_file = /var/log/amd
#log_options = all
log_options = error

[ /host ]

map_name = /etc/amd.map

Then the map files:

/etc/amd.map

* opts:=rw,grpid,resvport,vers=3,proto=tcp,nfs_retransmit_counter=10,nosuid,nodev
localhost type:=auto;fs:=${map};pref:=${key}/

localhost/sd0e type:=program;fs:=/mnt/sd0e;\
mount:=”/sbin/mount mount /mnt/sd0e”;\
unmount:=”/sbin/umount umount /mnt/sd0e”

localhost/sd1e type:=program;fs:=/mnt/sd1e;\
mount:=”/sbin/mount mount /mnt/sd1e”;\
unmount:=”/sbin/umount umount /mnt/sd1e”

localhost/cd   type:=program;fs=/mnt/cd;\
mount:=”/sbin/mount mount /mnt/cd”;\
unmount:=”/sbin/umount umount /mnt/cd”

As you can see, ‘/etc/amd.map’ references some mount points that must be appear in ‘/etc/fstab’:

/dev/sd0e       /mnt/sd0e       msdos   rw,noauto,-l,-m=644,-M=755,-u=1000,-g=100
/dev/sd1e       /mnt/sd1e       msdos   rw,noauto,-l,-m=644,-M=755,-u=1000,-g=100
/dev/cd0a       /mnt/cd         cd9660  ro,noauto,-l,-m=644,-M=755,-u=1000,-g=100

Note the user and group id (1000 and 100) are the ids of your user (not root).

I launch ‘amd’ from ‘/etc/rc.conf’:

My pendrive sd0e is mounted in /host/localhost/sd0e. A handy link can be created pointing to that place:

ln -s /host/localhost /media

Or better, creating url links in your desktop (Gnome, XFCE, KDE) pointing to that places:

file:///media/sd0e
file:///host/localhost/sd0e

When you click on that icon (url link) the device will be mounted.

With the default options we have configured, the devices are unmounted 5 seconds after the mount point have been abandoned.

I found this interesting document to learn how to deal with automunt:

http://mail-index.netbsd.org/netbsd-users/2008/10/07/msg002136.html

But I cloned my FreeBSD configuration for mmc:

https://nixbsd.wordpress.com/2010/08/25/freebsd-using-amd-for-the-mmc-card-reader/

Note that /dev/sd0e and /dev/sd1e could not be the devices for your pendrives. Use ‘disklabel’ to find the most suitable device name for your pendrive.

About jjjesss

I'm a guy interested in technology, bsd fan and concerned about the world around.
This entry was posted in BSD, FreeBSD. Bookmark the permalink.

Leave a comment