User avatar
Kronix
Posts: 12
Joined: Tue Jun 06, 2023 5:47 pm
Location: Brittany (Bretagne), France

Cannot change file permissions

Tue Jun 06, 2023 5:55 pm

I know how to use a Raspberry Pi, that's not the problem. I am trying to change file perms to execute compiled C code and even after using `sudo chmod -x |filenamehere|`, it still says permissions are denied. I am the only user and superuser on this system (Raspberry Pi 3 Model B) so I don't get it. Also, in pcmanfm, the default file manager, when I try to change the permissions, it does a reload of the folder page and it resets to default. I can provide screen proof, but the video may be slow.

Edit: Talking about +x in the chmod command, not -x
Last edited by Kronix on Tue Jun 06, 2023 8:27 pm, edited 1 time in total.

klricks
Posts: 8812
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA

Re: Cannot change file permissions

Tue Jun 06, 2023 7:28 pm

To change permissions with File Manager (pcmanfm), open a terminal and use sudo.

Code: Select all

sudo pcmanfm
Unless specified otherwise my response is based on the latest and fully updated RPi OS Bullseye w/ Desktop OS.

User avatar
thagrol
Posts: 9902
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK

Re: Cannot change file permissions

Tue Jun 06, 2023 7:46 pm

Kronix wrote:
Tue Jun 06, 2023 5:55 pm
even after using `sudo chmod -x |filenamehere|`, it still says permissions are denied.
Was there a typo in that? It's "+" to add a permission "-" to remove it. sudo chmod -x somefile will remove execute permission not add it.

Assuming, of course, the file is on a file system that supports Linux style owner, group, and permissions.
Knowledge, skills, & experience have value. If you expect to profit from someone's you should expect to pay for them.

All advice given is based on my experience. it worked for me, it may not work for you.
Need help? https://github.com/thagrol/Guides

User avatar
Kronix
Posts: 12
Joined: Tue Jun 06, 2023 5:47 pm
Location: Brittany (Bretagne), France

Re: Cannot change file permissions

Tue Jun 06, 2023 8:04 pm

Right, yes, that was a typo. Just used to - arguments.

User avatar
Kronix
Posts: 12
Joined: Tue Jun 06, 2023 5:47 pm
Location: Brittany (Bretagne), France

Re: Cannot change file permissions

Tue Jun 06, 2023 8:06 pm

klricks wrote:
Tue Jun 06, 2023 7:28 pm
To change permissions with File Manager (pcmanfm), open a terminal and use sudo.

Code: Select all

sudo pcmanfm
Even this doesn't work! It doesn't do the little refresh, however, even though the perms aren't changing.

User avatar
thagrol
Posts: 9902
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK

Re: Cannot change file permissions

Tue Jun 06, 2023 10:21 pm

Three further things to check:
  1. Is the partition containing the file using a file system that doesn't natively support permissions (FAT, NTFS, a remote SMB share, etc.)
  2. Has it been mounted read only?
  3. Has it been mounted with the noexec option?
Knowledge, skills, & experience have value. If you expect to profit from someone's you should expect to pay for them.

All advice given is based on my experience. it worked for me, it may not work for you.
Need help? https://github.com/thagrol/Guides

User avatar
Kronix
Posts: 12
Joined: Tue Jun 06, 2023 5:47 pm
Location: Brittany (Bretagne), France

Re: Cannot change file permissions

Wed Jun 07, 2023 7:31 am

I have checked and it says it's VFAT. (but why tho) It isn't read only, as I put the code on there in the first place, but it may be a file system that doesn't allow perms.

hortimech
Posts: 818
Joined: Wed Apr 08, 2015 5:52 pm

Re: Cannot change file permissions

Wed Jun 07, 2023 8:29 am

Where have you saved the file ? On my rpi's vfat is only used for /boot and vfat isn't a Unix filesystem, so Unix filesystem tools do not work.

User avatar
Kronix
Posts: 12
Joined: Tue Jun 06, 2023 5:47 pm
Location: Brittany (Bretagne), France

Re: Cannot change file permissions

Wed Jun 07, 2023 9:05 am

Well, the file is stored on my 16gb USB drive formatted with vfat in ./Progamming/C/

How can I format the drive?

Edit: Forgot about Imager

User avatar
Kronix
Posts: 12
Joined: Tue Jun 06, 2023 5:47 pm
Location: Brittany (Bretagne), France

Re: Cannot change file permissions

Wed Jun 07, 2023 9:29 am

So I reformatted the drive using Imager (FAT32) after moving my files from it to a safe folder. When I move them back, an error occurs and there are a few files left in the backup folder. Then I find that the drive can no longer be accessed and so I have lost everything (except for a few Spotify application files because I wanted portable Spotify). How is this happening? And why is Linux weird?

hortimech
Posts: 818
Joined: Wed Apr 08, 2015 5:52 pm

Re: Cannot change file permissions

Wed Jun 07, 2023 9:48 am

It sounds like you used another non Unix filesystem 'fat32', you should have used a Unix filesystem such as ext4.
Why your files have disappeared, who knows, we were not there when you did the copy (you did do a copy ?).
Linux isn't weird, it is just different from Windows.

klricks
Posts: 8812
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA

Re: Cannot change file permissions

Wed Jun 07, 2023 2:18 pm

Kronix wrote:
Wed Jun 07, 2023 9:29 am
So I reformatted the drive using Imager (FAT32) after moving my files from it to a safe folder. When I move them back, an error occurs and there are a few files left in the backup folder. Then I find that the drive can no longer be accessed and so I have lost everything (except for a few Spotify application files because I wanted portable Spotify). How is this happening? And why is Linux weird?
Do any of the filenames have mixed CaSe?
In Linux filesystems, file.txt and FILE.txt are 2 different files.
In Windows filesystems (FAT32 etc), file.txt and FILE.txt are treated as the same file. This can lead to loss of files when copying BTDT.

Also I don't think pcmanfm supports auto refresh. You may need to press F5 to refresh.
Unless specified otherwise my response is based on the latest and fully updated RPi OS Bullseye w/ Desktop OS.

User avatar
Kronix
Posts: 12
Joined: Tue Jun 06, 2023 5:47 pm
Location: Brittany (Bretagne), France

Re: Cannot change file permissions

Wed Jun 07, 2023 3:24 pm

Well, I don't think any of the files have mixed case or the same name, but even if it did, it doesn't explain why I can't access the drive. When I use lsusb the drive is there, but anywhere else it's not accessable.

User avatar
thagrol
Posts: 9902
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK

Re: Cannot change file permissions

Wed Jun 07, 2023 8:16 pm

Kronix wrote:
Wed Jun 07, 2023 9:29 am
So I reformatted the drive using Imager (FAT32) after moving my files from it to a safe folder. When I move them back, an error occurs and there are a few files left in the backup folder. Then I find that the drive can no longer be accessed and so I have lost everything (except for a few Spotify application files because I wanted portable Spotify). How is this happening? And why is Linux weird?
FAT32 (and all other varients), exFAT, NTFS and other non linux native filesystems have no support for owner, group, and permissions. What you see is set in the driver, the same for all files, and cannot be changed with chmod or chown. FAT/exFAT don't even have a concept of owner or group and the only permissions it supports are "read only" and "archive".

You have two choices:
  1. Reformat to ext4 or another Linux native file system
  2. Mount it with different options so everything on it has the execute bit set.
For the latter see the output from

Code: Select all

man mount
and the FAT related sections of Using fstab A Beginner's Guide (full disclosure: I wrote that guide)
Knowledge, skills, & experience have value. If you expect to profit from someone's you should expect to pay for them.

All advice given is based on my experience. it worked for me, it may not work for you.
Need help? https://github.com/thagrol/Guides

User avatar
Kronix
Posts: 12
Joined: Tue Jun 06, 2023 5:47 pm
Location: Brittany (Bretagne), France

Re: Cannot change file permissions

Wed Jun 07, 2023 8:51 pm

But how can I detect the USB drive, let alone mount it, if I don't know how? I've tried websites, forums, even AI. No luck. It even isn't showing in Imager! I've tried many things except for physical inspection/potentially reparation, which I don't want to do as i don't have the resources.
The only thing that allows me to know the USB is still working to an extent is that it shows up on

Code: Select all

sudo dmesg
without any errors:

Code: Select all

[ 4677.662375] usb 1-1.4: new high-speed USB device number 8 using dwc_otg
[ 4677.793225] usb 1-1.4: New USB device found, idVendor=1e3d, idProduct=198a, bcdDevice= 1.00
[ 4677.793277] usb 1-1.4: New USB device strings: Mfr=0, Product=0, SerialNumber=0
[ 4677.794312] usb-storage 1-1.4:1.0: USB Mass Storage device detected
[ 4677.795440] scsi host0: usb-storage 1-1.4:1.0
[ 4678.833059] scsi 0:0:0:0: Direct-Access     ChipsBnk Flash Disk       5.00 PQ: 0 ANSI: 2
[ 4678.834196] sd 0:0:0:0: Attached scsi generic sg0 type 0
[ 4678.835154] sd 0:0:0:0: [sda] Media removed, stopped polling
[ 4678.836556] sd 0:0:0:0: [sda] Attached SCSI removable disk
Edit: At least I don't think...

User avatar
thagrol
Posts: 9902
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK

Re: Cannot change file permissions

Wed Jun 07, 2023 10:19 pm

So the OS is recognising your USB drive but may or may not be mounting the partition and you don't know where if it is.

It would appear from your references to pcmanfm you're working in the desktop even if not booting directly to it.

The default behaviour under the RPiOS desktop is to mount all partitions on a drive when it is plugged in unless you have am entry in /etc/fstab for a particular partition. Those are ignored and must be mounted manually.

An unmounted drive cannot be accessed through the normal tools (pcmanfm, ls, cd, etc.)

Automatic mounts by the desktop are to directories in the form /media/<username>/<volumelabel> e.g. /media/pi/mydisc

Things in fstab get mounted wherever fstab says but only automatically during boot. Use

Code: Select all

sudo mount -a
or

Code: Select all

sudo mount /path/to/mountpoint
to mount them after hotplug.

Code: Select all

lsblk
will show you what devices you have, what partitions they contain, if and where they are mounted (nothing in the MOUNTPOINT column means not mounted). Your USB drive should appear at least as sda and sda1. If there is no sda1 (or sda followed by any number) there are no partitions on the drive.
Knowledge, skills, & experience have value. If you expect to profit from someone's you should expect to pay for them.

All advice given is based on my experience. it worked for me, it may not work for you.
Need help? https://github.com/thagrol/Guides

User avatar
Kronix
Posts: 12
Joined: Tue Jun 06, 2023 5:47 pm
Location: Brittany (Bretagne), France

Re: Cannot change file permissions

Wed Jun 07, 2023 10:40 pm

thagrol wrote:
Wed Jun 07, 2023 10:19 pm

Code: Select all

lsblk
will show you what devices you have, what partitions they contain, if and where they are mounted (nothing in the MOUNTPOINT column means not mounted). Your USB drive should appear at least as sda and sda1. If there is no sda1 (or sda followed by any number) there are no partitions on the drive.
So my drive doesn't have any partitions? How does that even work? Can I find the missing partitions and therefore files?

User avatar
thagrol
Posts: 9902
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK

Re: Cannot change file permissions

Wed Jun 07, 2023 11:04 pm

Kronix wrote:
Wed Jun 07, 2023 10:40 pm
thagrol wrote:
Wed Jun 07, 2023 10:19 pm

Code: Select all

lsblk
will show you what devices you have, what partitions they contain, if and where they are mounted (nothing in the MOUNTPOINT column means not mounted). Your USB drive should appear at least as sda and sda1. If there is no sda1 (or sda followed by any number) there are no partitions on the drive.
So my drive doesn't have any partitions? How does that even work? Can I find the missing partitions and therefore files?
I've no idea whether your drive has any partitions. You need to run either lsblk or sudo lsblk with the drive connected and examine the output.
Knowledge, skills, & experience have value. If you expect to profit from someone's you should expect to pay for them.

All advice given is based on my experience. it worked for me, it may not work for you.
Need help? https://github.com/thagrol/Guides

User avatar
FTrevorGowen
Forum Moderator
Forum Moderator
Posts: 7219
Joined: Mon Mar 04, 2013 6:12 pm
Location: Bristol, U.K.

Re: Cannot change file permissions

Wed Jun 07, 2023 11:15 pm

thagrol wrote:
Wed Jun 07, 2023 11:04 pm
Kronix wrote:
Wed Jun 07, 2023 10:40 pm
thagrol wrote:
Wed Jun 07, 2023 10:19 pm

Code: Select all

lsblk
will show you what devices you have, what partitions they contain, if and where they are mounted (nothing in the MOUNTPOINT column means not mounted). Your USB drive should appear at least as sda and sda1. If there is no sda1 (or sda followed by any number) there are no partitions on the drive.
So my drive doesn't have any partitions? How does that even work? Can I find the missing partitions and therefore files?
I've no idea whether your drive has any partitions. You need to run either lsblk or sudo lsblk with the drive connected and examine the output.
I would add that whilst "Imager" may "format" a drive (somewhat "indirectly") that, assuming you mean the Imager tool in Raspberry PiOS, is not its main purpose (which is to write O.S. images, which include "partitions" etc.). One of the main Linux tools for that is GParted which may appear under "System Tools" if it is installed by default. (It's quite a while since I installed legacy "Buster" on the P400 I'm posting from and I'm not sure if I had to install it or not.)
Trev.
Begining to test Bullseye on some older Pi's (an A, B1, 2xB2, B+, P2B, 3xP0, P0W, 2xP3A+, P3B, B+, and a A+) and Pi's with cameras with Buster on the P3B+, some P4B's & P400. See: https://www.cpmspectrepi.uk/raspberry_pi/raspiidx.htm

User avatar
Kronix
Posts: 12
Joined: Tue Jun 06, 2023 5:47 pm
Location: Brittany (Bretagne), France

Re: Cannot change file permissions

Wed Jun 07, 2023 11:37 pm

I have already tried both things, and:
1. When using

Code: Select all

sudo lsblk
, no non-system drives are listed, and
2. GParted doesn't show or list the drive.

Code: Select all

user@raspberrypi:~ $ sudo lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
mmcblk0     179:0    0 29.8G  0 disk 
├─mmcblk0p1 179:1    0  2.2G  0 part 
├─mmcblk0p2 179:2    0  512B  0 part 
├─mmcblk0p5 179:5    0   32M  0 part 
├─mmcblk0p6 179:6    0  256M  0 part /boot
└─mmcblk0p7 179:7    0 27.4G  0 part /
zram1       254:1    0  3.6G  0 disk [SWAP]
zram2       254:2    0  3.6G  0 disk /zram

User avatar
thagrol
Posts: 9902
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK

Re: Cannot change file permissions

Thu Jun 08, 2023 11:08 am

Do you have another computer you can test the drive with? If it works on there try a repartion and reformat.
Knowledge, skills, & experience have value. If you expect to profit from someone's you should expect to pay for them.

All advice given is based on my experience. it worked for me, it may not work for you.
Need help? https://github.com/thagrol/Guides

User avatar
Kronix
Posts: 12
Joined: Tue Jun 06, 2023 5:47 pm
Location: Brittany (Bretagne), France

Re: Cannot change file permissions

Thu Jun 08, 2023 12:13 pm

Before I saw this post, yes, I tried it on two Windows computers: first one couldn't detect it, second one said it had limited connection. I am guessing limited connection means it's not being able to copy files because there isn't enough transfer speed.

Also, I tried troubleshooting the drive on Windows, it said there were no problems detected.

User avatar
Kronix
Posts: 12
Joined: Tue Jun 06, 2023 5:47 pm
Location: Brittany (Bretagne), France

Re: Cannot change file permissions

Fri Jun 09, 2023 8:43 pm

For new people:

To recap, I had problems with file permissions on my USB drive, so I reformatted it to FAT32 with Imager, after moving all of the files from it into a backup folder. I then tried to move the files back, but failed midway and now I can't open my USB or do anything.

Return to “Troubleshooting”