Linux – Can’t execute a script on a mounted external drive

linuxmountpermissions

The /mnt/ext is mounted to an ext2 filesystem, an external hard drive. For some reason I can't run scripts from there. Please see the session below.

luntain@plato /mnt/ext $ echo "echo success" > k.sh
luntain@plato /mnt/ext $ chmod 777 k.sh
luntain@plato /mnt/ext $ ./k.sh
-bash: ./k.sh: Permission denied
126luntain@plato /mnt/ext $ ll k.sh
-rwxrwxrwx 1 luntain luntain 13 Jan 23 15:08 k.sh*
luntain@plato /mnt/ext $ 

I would love to find out why I see the error.

Best Answer

Probably there was a noexec attribute set when the filesystem was mounted; maybe it is your distribution 'feature'.

To check it you can execute mount that will show mount options in parentheses, and to remove noexec flag you can use mount -o remount,exec /mnt/ext under root.

Also, make sure you place the exec option after the user option, or the system will still mount your drive as noexec.