1

I have a shell script I want to make executable on an SD card. I have changed the folder permissions to my user/group. no problems there. when I issue the command chmod a+x script.sh then check the permissions with ls -al the permissions are read only. I have tried sudo chmod +x script.sh and a variety of other chmod commands, yet the file remains read only. I tried marking the script executable, and copying it to the SD card. cp -p script.sh /media/a/4C00-1447/cosmo when I check the permissions, the script is back to being read only. I don't understand what is happening here. None of these commands return any errors. how can I put an executable script on my sd card?

3
  • What is the file system on the SD card?
    – Hi-Angel
    Nov 30, 2022 at 18:27
  • Fat32 is the Filesystem
    – j0h
    Nov 30, 2022 at 19:08
  • 2
    The Fat32 does not support the Linux permissions you are trying to change. You will need to format the SD card to ext4.
    – user68186
    Nov 30, 2022 at 19:25

1 Answer 1

4

The FAT32 you're using on your SD-card does not support changing unix file permissions. All files will have exactly one permissions mask, which can be set when mounting FAT32 with umask= mount option. For example

 λ sudo mount /tmp/testfile mnt -o umask=000
 λ ll mnt/foo
-rwxrwxrwx 1 root root 0 ноя 30 23:40 mnt/foo

There is a workaround: format your SD-card as UDF filesystem (note that upon formatting your SD card you will lose any data previously stored on it). It is supported by most existing operating systems including Windows and Mac OS, and it also supports changing unix permissions of files, see:

 λ truncate -s 50M /tmp/testfile && mkfs.udf /tmp/testfile
 […]
 λ sudo mount testfile /tmp/mnt
 λ sudo chown -R $(id -u):$(id -g) /tmp/mnt/
 λ touch /tmp/mnt/foo
 λ ll /tmp/mnt/foo
-rw-r--r-- 1 constantine constantine 0 ноя 30 23:49 /tmp/mnt/foo
 λ chmod +x /tmp/mnt/foo
 λ ll /tmp/mnt/foo
-rwxr-xr-x 1 constantine constantine 0 ноя 30 23:49 /tmp/mnt/foo
3
  • 3
    Note that formatting the card will remove everything on the card currently so if you do this you have to be careful. Also, if the SD card is not going to be used anywhere else, ext4 is still the most recommended for use with Linux.
    – Thomas Ward
    Nov 30, 2022 at 20:54
  • Good point, added a note about it
    – Hi-Angel
    Nov 30, 2022 at 20:57
  • 3
    You may have to install udftools as it is not installed in Ubuntu 22.04 by default.
    – user68186
    Nov 30, 2022 at 21:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.