{"id":409,"date":"2011-03-30T14:17:56","date_gmt":"2011-03-30T20:17:56","guid":{"rendered":"http:\/\/www.cavanaugh.pro\/sean\/?p=409"},"modified":"2011-03-30T14:17:56","modified_gmt":"2011-03-30T20:17:56","slug":"how-to-mount-a-windows-samba-share-with-freebsd-automatically","status":"publish","type":"post","link":"https:\/\/www.cavanaugh.pro\/sean\/how-to-mount-a-windows-samba-share-with-freebsd-automatically\/","title":{"rendered":"How to mount a Windows samba share with FreeBSD automatically"},"content":{"rendered":"<p>A problem at work the other day was every time our virtual machine cluster went down we had a bunch of virtual <a href=\"http:\/\/www.freebsd.org\/\">FreeBSD<\/a> boxes that had to be manually connected one by one to our windows share to offload reports.  I wanted to make this happen automatically on boot since it was always the same window samba share.<\/p>\n<p>1) You need to add a line to your fstab file located in \/etc\/fstab<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n\/\/USERNAME@SERVER\/Mount_Folder \/blah smbfs rw,noauto 0 0\r\n<\/pre>\n<p>2) create a file called .nsmbrc located here \/root\/.nsmbrc<br \/>\nand add your credentials like the example file states in \/usr\/share\/examples\/smbfs\/dot.nsmbrc (discovered by doing a &#8220;man smbfs&#8221;)<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n&#x5B;SERVER]\r\naddr=x.x.x.x\r\n\r\n&#x5B;SERVER:USERNAME]\r\npassword=xxxx\r\n<\/pre>\n<p>3) finally we need to create a script that runs this on boot, fortunately someone has already done this on the FreeBSD project<br \/>\nthe file is located here: <a href=\"http:\/\/www.freebsd.org\/cgi\/cvsweb.cgi\/src\/contrib\/smbfs\/examples\/smbfs.sh.sample\">http:\/\/www.freebsd.org\/cgi\/cvsweb.cgi\/src\/contrib\/smbfs\/examples\/smbfs.sh.sample<\/a>.  This file simply parses through your fstab and mounts each one (fairly easy to figure out, especially if you know <a href=\"http:\/\/www.thegeekstuff.com\/2010\/01\/awk-introduction-tutorial-7-awk-print-examples\/\">awk<\/a>)<\/p>\n<p>you need to put the file in \/usr\/local\/etc\/rc.d\/ and give the file executable permissions<\/p>\n<p>here is the code<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n#!\/bin\/sh\r\n#\r\n# $Id: smbfs.sh.sample,v 1.3 2001\/01\/13 04:50:36 bp Exp $\r\n#\r\n# Location: \/usr\/local\/etc\/rc.d\/smbfs.sh\r\n#\r\n# Simple script to mount smbfs file systems at startup.\r\n# It assumes that all mount points described in fstab file and password\r\n# entries listed in \/root\/.nsmbrc file. See mount_smbfs(8) for details.\r\n#\r\n\r\nmount=&quot;\/sbin\/mount -o -N&quot;\r\numount=\/sbin\/umount\r\nHOME=\/root; export HOME\r\nvols=`awk -- '\/^\\\/.*&#x5B;&#x5B;:space:]]+smbfs&#x5B;&#x5B;:space:]]+\/ { print $2 }' \/etc\/fstab`\r\n\r\ncase &quot;$1&quot; in\r\nstart)\r\n\techo -n &quot;smbfs: &quot;\r\n\tfor vol in ${vols}; do\r\n\t\t$mount $vol\r\n\t\techo -n &quot;$vol &quot;\r\n\tdone\r\n\t;;\r\nstop)\r\n\techo -n &quot;unmounting smbfs mount points: &quot;\r\n\tfor vol in ${vols}; do\r\n\t\t$umount $vol\r\n\t\techo -n &quot;$vol &quot;\r\n\tdone\r\n\t;;\r\n*)\r\n\techo &quot;Usage: `basename $0` {start|stop}&quot; &gt;&amp;2\r\n\texit 64\r\nesac\r\n\r\necho &quot;Done&quot;\r\n<\/pre>\n<p>4) Now when you reboot you should be good to go!<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n#reboot\r\n<\/pre>\n<p>Notes:<br \/>\n1) the SERVER name is entirely dependent on the .nsmbrc file, my server did not have its name in DNS so it was confusing me that it wanted a server name for this config file&#8230;I was previously using the IP address of my server and it kept confusing it, I am sure there are other ways to fix this by just using the IP but this was a simple fix.<\/p>\n<p>2) I read from a couple places that the username had to be capitalized in the .nsmbrc (just like the server), what I found out that the username for samba shares is not case-sensitive so just go ahead and capitalize it (for me it was ADMINISTRATOR versus what I was trying Administrator)<\/p>\n<p>So basically make sure the SERVER and USERNAME is the .nsmbrc and fstab file match exactly and are both capitalized.  Someone comment if they know another way around this.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A problem at work the other day was every time our virtual machine cluster went down we had a bunch of virtual FreeBSD boxes that had to be manually connected one by one to our windows share to offload reports. I wanted to make this happen automatically on boot since it was always the same &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.cavanaugh.pro\/sean\/how-to-mount-a-windows-samba-share-with-freebsd-automatically\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to mount a Windows samba share with FreeBSD automatically&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-409","post","type-post","status-publish","format-standard","hentry","category-geek"],"_links":{"self":[{"href":"https:\/\/www.cavanaugh.pro\/sean\/wp-json\/wp\/v2\/posts\/409","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cavanaugh.pro\/sean\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cavanaugh.pro\/sean\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cavanaugh.pro\/sean\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cavanaugh.pro\/sean\/wp-json\/wp\/v2\/comments?post=409"}],"version-history":[{"count":2,"href":"https:\/\/www.cavanaugh.pro\/sean\/wp-json\/wp\/v2\/posts\/409\/revisions"}],"predecessor-version":[{"id":411,"href":"https:\/\/www.cavanaugh.pro\/sean\/wp-json\/wp\/v2\/posts\/409\/revisions\/411"}],"wp:attachment":[{"href":"https:\/\/www.cavanaugh.pro\/sean\/wp-json\/wp\/v2\/media?parent=409"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cavanaugh.pro\/sean\/wp-json\/wp\/v2\/categories?post=409"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cavanaugh.pro\/sean\/wp-json\/wp\/v2\/tags?post=409"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}