The example situation:
- Wish to execute a bash script at
/var/foobah/myscript.sh - But
/var/has been mounted usingnoexecvia/etc/fstab. - How to solve? Using bind mounts.
Firstly, create a directory to hold script(s), located somewhere that has exec rights, then create the target directory on noexec partition:
$ mkdir --parents /opt/magnetik/foobah
$ touch /opt/magnetik/foobah/myscript.sh
$ chmod u+x /opt/magnetik/foobah/myscript.sh
$ mkdir /var/foobahNow add following line to /etc/fstab:
#
/opt/magnetik/foobah /var/foobah none bind
Finally, remount and confirm change:
$ mount -a
$ mountDone!