19

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?

1

10 Answers 10

23

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
    
11
  • Thanks much! The second cheat is certainly an option, and I'll keep that in mind. Alternately, is there another file system I could use that would work with both Windows and Ubuntu and let me execute files? Jan 25, 2011 at 2:01
  • You could use ext2 or ext3, but you need to install a small utility on Windows to get it working.
    – user9521
    Jan 25, 2011 at 10:52
  • One more question about this - I decided to go with the option of creating a script on the hard drive and it works great. But I also want to have scripts for programs that are not .sh files - for example, Portable Chromium, which is type "executable (application/x-executable)". Using sh doesn't work, and ./Chromium still gives permission denied. Is there another command to use for this? Jan 26, 2011 at 16:42
  • Humm, I guess you could just cheat: before executing chromium, you can chmod it to make it executable. Since the chmod command will be called every time, it doesn't matter anymore that the permissions are not carried on the next time you insert the USB drive
    – user9521
    Jan 26, 2011 at 16:54
  • 1
    More complete list of workarounds for different program types (besides sh) May 23, 2019 at 17:25
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.

2
  • 1
    Should I set this in fstab? Jan 26, 2011 at 2:24
  • @Bonsi Scott There is no mode= option for vfat, see mount(8).
    – pevik
    Nov 22, 2016 at 21:58
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
0
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.

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).

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

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.
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
-1

If the syntax is bash...

bash yourscript

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .