Using an automounter for networked file systems is a good idea, because the connection to the file system server is only needed on demand. It also eliminates the need to grant mount privilege to normal users. I have set up a DNS-323 NAS in my home network and I want to mount its samba shares from my FreeBSD. I've already done so for my Linux system, with the help of abundant resources about setting up Linux automounter to mount samba shares. Now it comes to the turn of my FreeBSD. Again, I searched the internet for some help, and found that it is much harder to find relevant information. But in the end, I managed to have everything set up. And then, I am writing this page so that (hopefully) the next FreeBSD user who are searching the internet for this can get the answers easier. HOWTOFirst of all, you need to know how to mount a samba share in FreeBSD with the plain mount command. It sounds simple: mount -t smbfs //user@server/share /mount/point . But once you execute this command as root, you will find several things to take care:
Create a file named /etc/amd.conf by root, and write its content like: [global]
auto_dir = /.amd log_file = /var/log/amd.log log_options = error,fatal,warning map_type = file search_path = /etc [/smb] map_name = amd.smb This configuration file tells AMD about its auto mount root dir, log file location and content option, and where to search for its map files. Then the section [/smb] defines a auto mount point /smb, and its corresponding map filename amd.smb. We mentioned the map file amd.smb. It is time to create this file also. Edit the /etc/amd.smb file by root, put the following: share fs:=${autodir}${path};type:=program;mount:="/sbin/mount mount -t smbfs -o rw,-N \\\/\\\/user@server/share ${fs}"; This map file tells AMD that when it needs to auto mount /smb/share, it should execute the program defined by the mount setting. Note, the command line in mount:=... looks a bit weird. Two things need to be taken care of:
With these two files ready, we can then enable AMD. Edit /etc/rc.conf, and add (or modify) the following lines: amd_enable="YES" amd_flags="" The second line is to let AMD start without extra command line options. This will let AMD read /etc/amd.conf for its settings. Otherwise, the default flags in /etc/defaults/rc.conf make AMD ignore /etc/amd.conf . When all file changes are made, start AMD by command: /etc/rc.d/amd start . It will be started right away. Since AMD is enabled in rc.conf, it will start automatically the next time system boots. Then, accessing /smb/share will make AMD execute the mount command to mount it automatically. And if the mount is idle for 5 minutes, AMD automatically unmounts it. ResourcesMore options available in AMD's setting files. The man page of amd and amd.conf contains many of them with explanations. But I found they are inadequate to let a completely new user of AMD set up everything correctly if the file systems to be auto-mounted are not NFS. The AMD developer's web site contains a much more detailed manual: http://www.am-utils.org.Additional thoughtsIt was a lot harder to search for relevant information for FreeBSD's auto mounter, especially if the file system to be mounted is not NFS. I think a primary reason for this is the name of the automounter. "AMD", in most cases, is not what we are discussing here. A second reason is that the development of AMD has been inactive for many years until 2 or 3 years ago it was picked up again with an official maintainer. Actually, the new AMD project is named "am-utils". But FreeBSD's documentation does not make it super clear. I only discovered it by digging into source code and CVS check in messages. |