How do I execute a file from a FAT USB drive?

Because of limitations of the FA32 file system, you can't.

Now, you can cheat:

  1. either call sh etoys.sh instead of ./etoys.sh
  2. if you want, you can even create another script (that would lie on your hard drive, for example) that simply calls your script on the USB drive:

    #!/bin/bash
    sh /media/USB/etoys.sh
    

Mounting the device with -o mode=<value> should work

mode=value

Set the mode of all files to value & 0777 disregarding the original permissions. Add search permission to directories that have read permission. The value is given in octal.


I actually found a great solution at http://ubuntuforums.org/showthread.php?t=1665289 that fixed the problem.

Basically, it says to run the command

sudo sed -i -e 's|showexec|\x00\x00\x00\x00\x00\x00\x00\x00|g' /usr/lib/udisks/udisks-daemon

and that will prevent disks from auto-mounting with the showexec option.

I don't like to answer my own question, but this worked for me and I hope it helps other people too.

for ubuntu 18.04:

sudo sed -i -e 's|showexec|\x00\x00\x00\x00\x00\x00\x00\x00|g' /usr/lib/udisks2/udisksd

Ultimately, the issue seems to be that udisks mounts the filesystem with the showexec option, preventing any file that don't end in .exe, .bat, or .com to be run.

A related question (how to give custom mount options to udisks) can be found here: How to configure to record data to pendrive instantly? Turns out that you can use udev configuration to do that.

Is setting default mount options for udisks really not possible? proposes another solution based on udisks-glue, but it seems less convincing, as it ultimately rely on udisks, so that it seems that you can add options, but not remove them, and in particular showexec is still there).

In any case, I tend to prefer that to patching a binary file.


None of the solutions shown worked as far as I could tell to get a program I wrote as a Linux terminal program to run in my FAT32 partition, but changing the filename of the program to include .exe extension did work (thanks for the tip), all I did was rename filename to filename.exe for the terminal program I was trying to execute on a FAT32 partition, and then un-mount it, re-mount it and set the disk permissions to allow execution, then go to filename.exe and set its permissions and then the check mark would stick rather than turn back to a minus, and when I set the path and entered ./filename.exe at the terminal prompt the program ran as it should and shows the command line including filename.exe as entered, although the Ubuntu file directory shows the file as MSDOS/Windows it does run as a Linux program.