I have some shared folders in my network that I would like to have mounted in my Raspberry Pi 2 once it boots. I have edited my /etc/fstab and if I manually run mount -a, I manage to have access to them. I have found different solutions around the internet, but none seems to be working for me.As a quick solution, I have created a script that mounts those volumes (with mount -a) and added it to my .bashrc; so when I connect via ssh with that user, I get access to them.I have tried adding this script to /etc/network/if-up.d/ but it does not seem to be working. Why is this not working? Which is a better way to do it?P.S.: I am using an osmc version of Raspbian (I am not sure if this is just Raspbian with an osmc service or a different distro). So when I run uname -a, I get:Linux osmc 4.2.1-1-osmc #1 SMP PREEMPT Wed Sep 23 17:57:49 UTC 2015 armv7l GNU/Linux
Mounting a network volume once Wifi is set up
boot;mount;networking
Sometimes, figuring out why the mechanisms that are supposed to work don't work is more work than just doing what you need to do some other more bulletproof way.You want to mount a shared folder at boot, but obviously you have to wait until the network is up (note that networking and the network is up tend to be distinctly different things WRT boot services).  The canonical way to do this is obviously via ifup or a boot service with a dependency on a service that is supposed to establish the network connection (again, distinct from networking).  But we've already decided these mechanisms aren't reliable in this case for whatever reason. To come up with a more bulletproof method, we need to reduce this task to its most basic elements, and resort to using shell tools to deal with these elements in a basic, fundamental way.  This could start by coming up with some kind of test to determine if the network is up, and waiting until this test succeeds.Or we could skip that test and just test the result of mount itself, which will fail if the network share is unavailable.#!/bin/bash                                                                          exec &> /var/log/mountshare.log                                                      gap=3                                                                                attempts=40                                                                           while [ $attempts -gt 0 ]; do                                                            mount -v /foo /bar                                                                      if [ $? -eq 0 ]; then break; fi                                                       attempts=$(($attempts - 1))                                                          sleep $gap                                                                       doneTo explain:exec &> /var/log/mountshare.log redirects all output from this script to a file, overwriting any previous version.  This is a bashism, which is why the shebang line isn't simply #!/bin/sh.  However, using bash on a normal linux system is usually a safe bet.The value of gap and attempts mean this will be tried every three seconds for two minutes -- plenty of time.  You could set gap down to one if you like.  This is an incredibly minor task that could actually run forever at one second intervals without impairing the system.The mount line is specific (obviously you need to customize this).  Since you know exactly what you want to do, it is preferable to mount -a and ensures our test is more bulletproof.  If you have a listing in fstab, you should be able to use one argument (the device path or other identifier), but again, using a complete, specific command is easy and better fulfills that bulletproof criteria.The test, if [ $? -eq 0 ] checks the exit status of mount.  When it succeeds, it returns 0; when it fails, it returns some other value.  Note that mount will spit an error in that case, and this output will end up in the log file.  Since we used -v, it will also produce a message when the call succeeds.The next two lines decrement the counter (attempts) and add a sleep.  The sleep is very very important.  Do not do this without a sleep.  Without that, this goes from being an an incredibly minor task that could actually run forever to something that is going to hog a lot of processor time.To use this, put it in, e.g., /usr/local/bin.  Ensure it is owned root.root (sudo chown root:root mountmyshare.sh) and executable (chmod 755 mountmyshare.sh).  You could put it anywhere if you don't want it in $PATH since we are going to use an absolute, bulletproof path to invoke it anyway.Then at the top of /etc/rc.local:/usr/local/bin/mountmyshare.sh &The & is critical; it forks this into the background. I've said put it at the top in case you have other stuff there that may screw this up.  This won't screw up anything else.While /etc/rc.local is sort of a legacy mechanism, it is still run at the end of the boot sequence on all reasonably normal linux systems as far as I am aware.