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?

Braiam
  • 67,791
  • 32
  • 179
  • 269
  • 3
    Related question here: http://askubuntu.com/questions/23108/trying-to-make-file-executable-on-usb-but-the-permission-doesnt-stick – luri Jan 25 '11 at 00:31

10 Answers10

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
    
  • 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?

    – Derek Redfern Jan 25 '11 at 02:01
  • You could use ext2 or ext3, but you need to install a small utility on Windows to get it working. –  Jan 25 '11 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? – Derek Redfern Jan 26 '11 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 –  Jan 26 '11 at 16:54
  • I thought you couldn't chmod on FAT at all though since it doesn't support Unix permissions. – Derek Redfern Jan 26 '11 at 17:08
  • IIRC you can, it just won't last. This has to be tested, though, I might be completely wrong, but I don't have a Linux system here to test it myself. –  Jan 26 '11 at 17:09
  • Here's the script I'm running: cd /media/PORTABLEAPP/xtogo/ chmod a+x Chromium ./Chromium

    Output: ./script: line 3: ./Chromium: Permission denied

    – Derek Redfern Jan 26 '11 at 17:12
  • The ultimate issue is not with fat32, but rather with how a linux typically treats such a volume. It could just as easily have been configured to assume that lack of full permission bits = everything is allowed, though it should be easy to see why that is not usually the default. – Chris Stratton Apr 23 '14 at 03:57
  • That works for shell scripts. But what about executing plain linux binaries from a FAT32 a.k.a. vfat filesystem ? how to "cheat" that ? – Axel Werner May 04 '19 at 09:00
  • 1
    More complete list of workarounds for different program types (besides sh) – sondra.kinsey May 23 '19 at 17:25
  • for the permission denied can you try source /full/path/Chromium using #!/bin/bash instead of sh? – Vass Jul 29 '22 at 00:54
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
  • 197,895
  • 55
  • 485
  • 740
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
  • 453
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
  • 19,615
  • 55
  • 79
  • 83
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,333
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