4

Ubuntu 18.04 - Installed Zsh and Oh-My-Zsh from here.

Given the following

echo '#!/bin/bash\n\nls ~;' >> myscript.sh
chmod 755 ./myscript.sh
./myscript.sh

Executed in my home folder, all goes as expected and it lists files in my home folder

output omitted for brevity -- it worked and listed files as the script intended

Executed in a secondary drive I get the output listed below (my fstab config is listed lower in this question).

╭─user@host /media/user/raw/scripts
╰─$ echo '#!/bin/bash\n\nls ~;' >> myscript.sh
╭─user@host /media/user/raw/scripts  
╰─$ chmod 755 ./myscript.sh
╭─user@host /media/user/raw/scripts  
╰─$ ./myscript.sh 
zsh: permission denied: ./myscript.sh

My /etc/fstab

╭─user@host /media/user/raw/scripts  
╰─$ cat /etc/fstab                                                                130 ↵
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/sdb2 during installation
UUID=<<some_uuid>> /               ext4    errors=remount-ro 0       1
# /boot/efi was on /dev/sdb1 during installation
UUID=<<some_uuid>>  /boot/efi       vfat    umask=0077      0       1
/swapfile                                 none            swap    sw              0       0
/dev/disk/by-uuid/<<some_uuid>> /media/user/raw auto user,rw,nofail,x-gvfs-show 0 0

Since this executes fine in my home folder and not on this mounted drive, I'm thinking the issue is somewhere within the fstab configuration. Any ideas?

rogodeter
  • 460
  • 9
  • 19
  • I tried the same in bash and the result was the same (bash: ./myscript.sh: Permission denied). It appears to be an issue with how I've mounted that particular disk, not with the interpreter – rogodeter Jul 08 '18 at 17:24
  • [Can't execute a script on a mounted external drive](https://superuser.com/q/99635/173513), [How do I execute a file from a FAT USB drive?](https://askubuntu.com/q/23128), etc. – jww Jul 09 '18 at 14:18

1 Answers1

8

You are implicitly specifying noexec, which means that no files on the device will be executable.

Here's man mount:

user

Allow an ordinary user to mount the filesystem. The name of the mounting user is written to the mtab file (or to the private libmount file in /run/mount on systems without a regular mtab) so that this same user can unmount the filesystem again. This option implies the options noexec, nosuid, and nodev (unless overridden by subsequent options, as in the option line user,exec,dev,suid).

The same paragraph also suggests the fix: use the user,exec to re-enable execution in a user mountable fs.

Community
  • 1
  • 1
that other guy
  • 116,971
  • 11
  • 170
  • 194
  • You're right. That was the problem. I read the man page too, but stopped at "Allow an ordinary user to mount the filesystem", not realizing user was a macro option. Thanks for your help @that other guy! – rogodeter Jul 08 '18 at 17:49
  • Can you provide any more detail? I can't execute in a mounted drive, but I don't understand how to go about changing the user,exec flags... – Jason Silver Apr 10 '22 at 21:40
  • OP had declared the mount and options in `/etc/fstab` so that's where they'd change it – that other guy Apr 10 '22 at 22:18