WAKap
Posts: 5
Joined: Mon Sep 08, 2014 6:47 pm

Can't make a file executable

Mon Sep 08, 2014 7:44 pm

I am working on a C++ project using Code::Blocks. If I create a "hello world" executable in the /home/pi/bin/Debug tree all is good. However, I want to create it on a USB thumb drive. The path is "/media/8879-6109/bin/Debug/". My executable "test2" is created with "-rwxr-xr-x" when I create it in my home tree but -rw-r--r-- when I put it on my thumb drive. "/media" is drwxr-xr-x owned by root. 8879-6109,bin, and Debug are all drwx------ and owned by pi and I am logged in as pi. If I run "sudo chmod -v +x test2" it says "mode of 'test2' changed from 0644 (rw-r--r--) to 0755 (rwx-r-xr-x)" but if I do an "ls -l" it still shows permission as "rw-r--r--". If I copy the executable from my home tree to the thumb drive tree the executable permissions are lost.

Any guidance would be appreciated.

User avatar
DougieLawson
Posts: 39126
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Can't make a file executable

Mon Sep 08, 2014 8:06 pm

USB sticks with FAT/FAT16/FAT32 filesystems don't support Unix file permissions. To get things on any FAT filesystem executable you'll need to change the umask values when you mount it.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

User avatar
socialdefect
Posts: 110
Joined: Mon Jun 25, 2012 9:02 pm
Location: Tilburg, the Netherlands
Contact: Website

Re: Can't make a file executable

Mon Sep 08, 2014 10:47 pm

Does a FAT filesystem need permissions to execute files??? Doesn't sound like Microsoft to me...

On my Pi I can create a script on /boot and execute without making any changes. If you fail to execute something; what exactly are you trying to execute and how?
== If it's not broke... I'm not done fixing it! ==

User avatar
DougieLawson
Posts: 39126
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Can't make a file executable

Mon Sep 08, 2014 11:31 pm

Unix needs an execute permission to run something. Strange foreign objects from FAT drives can't be executed by default without changing the umask value when the drive is mounted. That's a security feechur.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

WAKap
Posts: 5
Joined: Mon Sep 08, 2014 6:47 pm

Re: Can't make a file executable

Wed Sep 10, 2014 6:33 pm

Thank you, Dougie. The RPi is automatically mounting the USB stick boot-time. Rather than umount-ing and then mount-ing with the umask that I'm looking for and (heaven-willing) getting all the other parameters correct, do you know of a way for me to get the automated mount to include execute permission? Thank you again for your help.

User avatar
DougieLawson
Posts: 39126
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Can't make a file executable

Wed Sep 10, 2014 7:11 pm

It depends how it's mounted. If it's done with a line in /etc/fstab you can override the default options in there. Have a look at what you're getting by default with the mount command (with no operands it displays currently mounted filesystems).

Code: Select all

/dev/sda1 /media/usb      vfat    auto,user,rw,uid=pi,gid=pi,umask=0222      0 0

man mount
man 5 fstab
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

WAKap
Posts: 5
Joined: Mon Sep 08, 2014 6:47 pm

Re: Can't make a file executable

Fri Sep 12, 2014 7:08 pm

Thank you again Dougie. I had looked at /etc/fstab and that didn't seem to be what was mounting the volume, but I should have included a copy of it, so here it is.

proc /proc proc defaults 0 0
/dev/mmcblk0p5 /boot vfat defaults 0 2
/dev/mmcblk0p6 / ext4 defaults,noatime 0 1
# a swapfile is not a swap partition, so no using swapon|off from here on, use dphys-swapfile swap[on|off] for that

Correct me if I'm wrong but given that the only vfat entry has a block special device link of /dev/mmcblk0p5 and a mount point of /boot I figured that this couldn't be the thing causing the file system to be mounted.

Executing "mount -l" gives me the following information concerning the device of interest but there didn't seem to me to be any indication as to what was triggering the mount:

/dev/sda1 on /media/8879-6109 type vfat (rw,nosuid,nodev,relatime,uid=1000,gid=1000,fmask=0022,dmask=0077,codepage=437,iocharset=ascii,shortname=mixed,showexec,utf8,flush,errors=remount-ro,uhelper=udisks)

Given that there are lots of explanations online of how to mount a USB drive under linux and that I didn't install anything special to make the USB flash drive work, but just plugged it into my USB hub, it seems like this is something specific to the pi.

I like having this as a vfat volume because it makes it so easy for me to back up my information to my pc and thence to my NAS.

Any other directions you can point me?

User avatar
DougieLawson
Posts: 39126
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Can't make a file executable

Fri Sep 12, 2014 7:15 pm

You must have an automounter program installed somewhere. It likely has a config with umask and other stuff.

https://wiki.debian.org/AutoFs is the likely candidate if you're running Raspbian.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

WAKap
Posts: 5
Joined: Mon Sep 08, 2014 6:47 pm

Re: Can't make a file executable

Sat Sep 13, 2014 1:53 pm

Dougie, I am indeed running Raspbian. I read through the AutoFs link and, of course, felt like I'd gone down the rabbit hole following links to links as one does when working on these Linux problems. Ultimately udev has only two rules files, neither of which contain anything that I think would impact my problem. Just for fun I changed the modes from 0666 to 0777 anyway,but it didn't help. I did find one thing that surprised me though. The volume doesn't get mounted boot-time. It doesn't get mounted until I run startx. If that means anything to you, or anyone else for that matter, it would hold great interest for me. For the moment, though, it gives me a new path to follow. Thank you yet again.

User avatar
DougieLawson
Posts: 39126
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Can't make a file executable

Sat Sep 13, 2014 8:59 pm

If you have permission bits of 0755 then you'd use a FMASK of 0022 (0777 masked with 0022 equals 0755 (don't worry about that leading octet)). Also you'll need to mount with the exec option explicitly set (a Linux mount of a FAT/VFAT/EXFAT drive should default to noexec for security reasons).

The other option is to reformat the USB stick as ext4 then it will "just work" on Linux, but will completely fail to work on Windows.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

User avatar
jojopi
Posts: 3271
Joined: Tue Oct 11, 2011 8:38 pm

Re: Can't make a file executable

Sat Sep 13, 2014 9:23 pm

autofs is configuration-based, kernel-assisted, on-demand automounting. What GUIs do instead is opportunistic mounting of every device they see (which either patronises or annoys the user).

In LXDE, the responsible component is pcmanfm. That is the file manager, and also the process that draws the desktop icons above the root window. Last time I checked, pcmanfm did not offer a way to set default mount options, but will honour an /etc/fstab entry if you can predict the device and mount point it will use.

The other option is to disable it (File Manager: Edit→Preferences→Volume Management) and then configure any of the non-GUI methods.

You do not really need execute permission on non-directories. To interpret a script you can use "bash ./script.sh" or "python ./script.py", and to launch a dynamic executable "/lib/ld-linux.so.3 ./binary".

If you are doing development in an non-native filesystem, however, sooner or later you will run into more serious limitations such as the lack of hard and symbolic links or accurate timestamps. Consider switching to ext4.

WAKap
Posts: 5
Joined: Mon Sep 08, 2014 6:47 pm

Re: Can't make a file executable

Sun Sep 14, 2014 6:26 pm

Thank you dougie and jojopi. I have thrown in the towel, and moved my working directory to the sd card and everything is working fine. I will back up my source files to the thumb drive and then figure out the easiest way to get it over to my NAS. I very much appreciate your help and guidance. In spite of not being able to get it to work quite how I want I learned a lot.

User avatar
DougieLawson
Posts: 39126
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Can't make a file executable

Sun Sep 14, 2014 11:21 pm

My Zyxel NAS includes network file system (NFS) support, so I can simply mount the NAS drive on any of my Linux systems.

http://zyxel.nas-central.org/wiki/NFS_and_Samba/CIFS
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Return to “Beginners”