20

I'm trying to install a portable app onto my USB drive such that it is compatible with both Ubuntu and Windows (specifically, a program called eToys). Support is already built into the app for both operating systems - there's etoys.sh for Ubuntu and etoys.exe for Windows. I decided to install onto a FAT drive since that can be read from both systems. This works fine for Windows, but for some reason I cannot execute etoys.sh on Ubuntu.

The problem is not with the file - when the whole folder is copied to the local hard drive, the app works great in Ubuntu. But when I try to execute it from the USB, it opens the file in a text editor.

I then tried to run it from a terminal, but I got the message Permission denied.

I've had the same problem with other executables as well.

Is there an easy way to execute things from a USB stick?

Braiam
  • 69,112

10 Answers10

24

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
    
8

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.

muru
  • 207,228
6

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
3

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.

Virgile
  • 261
3

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.

2

You can use umask=000 mode:

umount /dev/sdb1
mount -o umask=000 -t vfat /dev/sdb1 /media/sdb1

Source: wiki.linuxquestions.org, section "Mount options for fat" in mount(8).

pevik
  • 483
0

On Windows volumes, it is most often possible to simply rename shell scripts, 'shell.sh', as 'shell.sh.bat' so that the executable nature from one environment's volume file system (Windows) is in inferred in the other (Linux).

Once renamed, nothing special needs to be done on reboots.

Only if live system immediate use is needed, is it usually required to re-register the file and its volume, with a simple remounting, when this rename or an edit to the file content itself is made.

This remount can be done two ways, either:

  1. For a removable/USB volume simply eject it and reinsert it, otherwise turn the system off and then back on (ie. a reboot, which "kills" the "live" system).

or

  1. Use commands to umount and mount (naively, i.e. as "usual") the volume.
Kevin Bowen
  • 20,055
  • 57
  • 82
  • 84
ekim
  • 1
0

Try this, but I'm not sure it will work:

  1. Open the USB stick in the file manager
  2. Right click inside the window and select 'open in terminal'
  3. Type in the terminal window the following: sudo chmod +x etoys.sh
  4. Try to execute the file or by double clicking it or by typing the following in the same terminal window: ./etoys.sh
Nmath
  • 12,664
0

So I found a much simpler (and safer solution).

Use gparted to format the USB FAT32 and then us Partition=>Manage Flags to set the following flags: boot, lba

MrSteve
  • 109
-1

If the syntax is bash...

bash yourscript