Skip to content

Instantly share code, notes, and snippets.

@magnetikonline
Last active January 14, 2018 03:39
Show Gist options
  • Save magnetikonline/c419743a395d26d9854d to your computer and use it in GitHub Desktop.
Save magnetikonline/c419743a395d26d9854d to your computer and use it in GitHub Desktop.
Enable execute of bash scripts on a partition mounted with noexec.

Enable execute on partition mounted with noexec

The example situation:

  • Wish to execute a bash script at /var/foobah/myscript.sh
  • But /var/ has been mounted using noexec via /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/foobah

Now add following line to /etc/fstab:

#
/opt/magnetik/foobah /var/foobah none bind

Finally, remount and confirm change:

$ mount -a
$ mount

Done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment