FreeBSD and Samba: Automounting
Samba is available on most Unix platforms, and it integrates Windows network shares into Unix machines as virtual file systems (smbfs) and provides a way for crisp interplay between the two platforms. However, FreeBSD also provides an elegant way to automount samba filesystems, and this mini howto details how you can set that up. It's short, and I don't go into details on how you can set up a samba server, just how to get client access working fast.
Install FreeBSD, get familiar with the ports collection, and be sure that your network is working correctly, and that you can ping both to and from your Windows box.
- Switch to root (su) and stay as root till this howto completes.
To get samba installed, use the ports collection (/usr/ports/net/samba3, not /usr/ports/net/samba) and make && make install it. Installation should be smooth since the samba sources should already be present on your system (if you decided to install package sources when you installed FreeBSD). Choose default options for everything.
-
Now, cp over the samba config file (smb.conf) from /usr/local/etc/, using this:
cp /usr/local/etc/smb.conf.default /usr/local/etc/smb.conf
...and edit it. You should have to change the default workspace name, and edit the shares accordingly if you want to set up shares on your FreeBSD box. That's beyond the scope of this howto. You can comment out everything in the share definitions section if you don't want the server functionality of samba.
-
To load Windows shares, you can use the mount_smbfs command in FreeBSD. In fact, you should try it out now...
mount_smbfs //USERNAME@COMPUTERNAME/SHARENAME /path/to/mnt/location
USERNAME is a valid Windows username for which you've already set up authentication on your Windows box. If you've set it to "anybody" on your Windows end, you can use any valid username here. COMPUTERNAME is the Windows computer name (system applet in the control panel) and SHARENAME is the text in the "Share As.." textbox in the property applet for a particular share. Spell everything in CAPS (except the bsd mount location).
The /path/to/mnt/location is any valid unix directory. Having a location in /mnt in the format /mnt/<computername>/share is appropriate.
You'll be prompted for your windows password. If that command works, you're set, move down to the next step. If it doesn't, you've gone wrong somewhere, and this howto can't help you, ciao!
-
If mount_smbfs works.. you can go about automating the process (this is sweet FreeBSD mantra). Edit the /etc/fstab file and add the following line(s) to it.
//USERNAME@COMPUTERNAME/SHARENAME /path/to/share/location smbfs rw,noauto 0 0
Repeat those lines for each share you have. This is for easier un/mounting.
-
Edit the /etc/nsmb.conf (notice the n) file, and add the following lines to it...
[COMPUTERNAME]
addr=XX.XX.XX.XX
[COMPUTERNAME:USERNAME]
password=XXXXX
...for every user you have. This is to validate your account. You'll be wise to chmod the file 600 (owned by root) since it contains plain-text passwords.
-
Now, you've got to make it mount a smb filesystem at startup. To do this, use this shell-script and place it in /usr/local/etc/rc.d/ (name it something descriptive... mine is <computername>-mount.sh) ...
! /bin/sh
case "$1" in
start)
echo
echo -n "Mounting //<computername>/<sharename>: "
mount /mnt/<computername>/<sharename>
echo "Done."
;;
stop)
echo
echo -n "Unmounting //<computername>/<sharename>: "
umount /mnt/seven/vishnu
echo "Done."
;;
ecase
Chmod the file executable... 700 will do.
-
Now.. reboot. Everything should go off fine. You should be automounted into the windows share. If something doesn't go according to plan... try posting a comment here, I'll help.
Known caveats:
-
Mounting more than one share consecutively doesn't work. For example, in the shell script above, if I use more than one mount/umount combination, FreeBSD hangs on the next boot. I suspect this is because the netsmb_dev kernel driver hasn't finished loading completely and hangs on so many consecutive demands... but I haven't investigated this, because for my purposes, this is not needed. You might solve this problem with a simple delay between mount commands. Feel free to explore.
You have to be root to mount filesystems in FreeBSD, or to copy over files across the share. I have not yet found a workaround for this. Keep su handy, that helps.
|