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?
1 Answer
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
-
3Note 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
-
-
3You may have to install
udftools
as it is not installed in Ubuntu 22.04 by default. Nov 30, 2022 at 21:12
ext4
.