Cannot change ownership on some USB sticks?

I use a couple of USB sticks to move stuff around from my ancient XP box to the new 18.04 box & I needed to edit a text file while the stick was used in the Linux box. (FAT32 formatted stick.)

Ooops. No deal. Root is the owner and that...seems to be the end of it.
Tried to alter this as admin, sudo commands, etc but no dice.

Tried chown & chmod & a few other ways to change ownership & perms - but all were failures.

I did a disk check on the stick under windows & it came back 100% clean - so if this is a dirty bit problem I don't know where it comes from or how to clear it.

If anyone can further educate me about somehow changing the perms without re-formatting the stick, I will hugely appreciate the help !!

Thanks.

if the stick for some reason is mounted Read-Only, no dice.
dmesg | grep sdX, where X is the stick and you might see if it is mounted RO.

sd 8:0:0:0: [sdb] 15974400 512-byte logical blocks: (8.18 GB/7.62 GiB)
sd 8:0:0:0: [sdb] Write Protect is off

Thanks for replying to my query...and:
Wow.
That description is of a very end-of-the-road & totally unsolvable sort of thing.

dmesg | grep sdb shows the stick in question & write protect is off.

It strikes me as absurd that there is absolutely NO way to reverse this arbitrary ownership setting !!!

Hello computerguy

You could re-format the usb-stick to NTFS and try again - if it works it works. :slightly_smiling_face:

Accessing the stick by destroying its contents 1st ?!?

To me, this resembles the idea of opening some food - throwing the food in the trash - then eating the wrappings instead.

I am not a goat, so I'll pass on this type of non-solution, thanks.
(Actually it more reminds me of the windows users who solve all their problems by reinstalling the OS...over & over again.)

I'd really appreciate a more Linux-like, actual solution to the problem itself, please ?!?

I might have had USB sticks that have done this to me once, but it was long ago, I can't really remember what happened to them... :thinking:

What does the error say exactly? It is pretty unusual since FAT32 has no permission system at all. If the drive is mounted as read-only or the file manager "thinks" it is (for some reason) then try:

sudo mount -o remount,rw /dev/sdb1 /mnt

Or try starting the file manager as root, to see if you can actually write files as the superuser:

sudo caja

If it works as root, then it's possible this particular drive needs to be mounted with the mount command with an option so your user ID (usually 1000) is the "owner" to read/write files. Not sure off top of my head what that command is.


Perhaps check GParted to see details of the partition table and if has any flags set. If you've got another working USB drive to compare, that'll help for cross comparison.

Also, when you unplug it from the Windows XP box, make sure you "eject" it first, since it might be mounting on Ubuntu as read-only as a precaution.


I know you don't wish to format it, but there is a chance there's an issue with how this drive was originally formatted. The last resort may well be to copy the files, create a new msdos partition table (MBR) using GParted which will destroy data on the drive and proceed to create a new FAT32 partition and place your files back. Generally, the drive will then work on both Windows and Ubuntu.

1 Like

Try this:
sudo cd /media/name-of-drive

sudo chown yourusername:yourusername

This will preserve your data.

Thanks for your kind & thoughtful replies folks !!
I have actually searched extensively, found & tried most all of what has been suggested here EXCEPT for reformatting & killing off my data.

I will find where I've copied what I've done & the error itself in a bit & share that, but in the meantime I wonder this & hope someone may clarify it for me, please:
Is there a big difference between issuing commands via sudo vs. enabling root login & taking actions that way directly ??
(I ask because when I tried to take ownership of the drive that I most needed to use via commands with sudo - it remained as owned by root no matter what.)

It also occurs to me to ask this:
Is there a way to force 'foreign' USB sticks to always mount with all permissions granted or as property of the user's group rather than being property of root ??

Thanks again.

OK, when using Caja as superuser & trying to change owner - it responds:
The owner could not be changed.
Error setting owner: Operation not permitted.

Trying to change group brings:
The group could not be changed.
You do not have the permissions necessary...blah, blah, blah.

Trying again this way:
sudo chown yourusername:yourusername

Brings only=>
Operation not permitted.

I've definitely tried all variations of chown & chmod & most bring either that same response, or just return to the command prompt.

In Gparted, device sdb1 has added -'-part1' after its lengthy name & the only flag shown is LBA.
It has only the full 32GB of it as a single partition.

Does any of the above help to clarify this persistent annoyance a bit ??
Thanks.

Changing the permissions with those commands will not help, since FAT32 has no permissions to begin with. It seems likely the auto mount is causing it to be read-only.

Are you able to write to the media as root? Like, create a folder from Caja (as superuser)?

Only one of my old 4 USB drives had an LBA flag set - but it seems like a legacy thing:

lba - [MS-DOS] This flag is used by DOS, Windows 9x, and Windows ME and tells the system to use Linear Mode (Logical Block Addressing).

-- https://www.linux.org/threads/gparted-partition-and-filesystem-flags.11640/


It might be worth sharing the output of these commands so we know more about this particular USB drive:

mount | grep 'sdb'
sudo fdisk -l /dev/sdb
One of mine outputs this...

/dev/sdd1 on /media/luke/128MB USB type vfat (rw,nosuid,nodev,relatime,uid=1000,gid=1000,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,showexec,utf8,flush,errors=remount-ro,uhelper=udisks2)

Disk /dev/sdd: 126 MiB, 132120064 bytes, 258047 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xab2595bb

Device     Boot Start    End Sectors  Size Id Type
/dev/sdd1  *       32 258046  258015  126M  b W95 FAT32

Try this: Find out the UID and GID of your user account:

id

Usually for a system with one user, this is 1000. Unmount the drive first, then mount with your ID as the owner:

sudo umount /dev/sdb1
sudo mount -t vfat /dev/sdb1 /mnt -o rw,uid=xxxx,gid=xxxx

Running commands as sudo usually provides that application with superuser privileges in context of your user - this can be damaging to permissions on your home directory if used improperly. Enabling root login is considered dangerous since the session has full access to EVERYTHING on the computer... one bad command and the system could be broken.

1 Like

Thanks for your very thorough & thoughtful reply Lah7 !!!

If the auto mount is causing it to be read-only - how might I change that, please ??

Oddly, sometimes I have been able to write to the media as from Caja as superuser, yes - but not reliably.

I don't have any idea why a USB drive will have the LBA flag set - unless it has to do with that stick possibly having been used previously for a SystemBack SBLive boot medium ??
(It was cleaned & re-formatted after that though...)

I clearly remember building PCs with 'large' HDDs back in the day & having to set the lba up manually - why it is appearing here - no clue.

I will get the output from the suggested commands a bit later on as I cannot do so ATM - thanks for the suggestions !!

When I asked this=>

Is there a big difference between issuing commands via sudo vs. enabling root login & taking actions that way directly ??

It was intended exactly as asked.
Mostly aimed at why a command made with sudo could be lacking in authority as I've seen too many times since this one adventure began.

I know that root logins are considered dangerous, and also why - but since I am a guy who builds & fixes 'em - I also make sure that I do not break 'em !!

Again - my sincere thanks for the wonderful replies here.

The Disks application can update /etc/fstab by choosing the partition and clicking the cogs → Edit Mount Options...

image

And set the options accordingly:

image

Although, this method stops the USB drive "auto-mounting" as soon as you plug it in, so you'll need to open Disks (or the terminal) to mount the drive. It will use these options though.

I muddled my thoughts -- but the simple answer is - it's the same in terms of being granted privileges. The difference being "sudo" generally inherits your environment variables (e.g. home directory) too.

2 Likes

OK, this has been quite the frustrating educational experience for me - and it is time to finish with this seemingly unsolvable problem.

I transferred the ~500MB of needed data to an 8GB stick that has no access problems, and then...

Used the Disk utility to mess with the errant 32GB stick.
Deleted & re-created it (as user) with FAT32 & no matter what it still belonged to root...period.
Did the same thing with primary partition & NTFS as well - BUT:
When I created an extended space & an NTFS partition inside that - I was able to change all the permissions without hesitation.
Ejected, gave it a minute & re-mounted - all good.

No idea what this may be caused by - but it IS a tiresome & annoying problem.

For the user to NOT have control over their own media - to be denied permission to make changes to it - this is lots more serious than some small thing which one must adjust to.

Also, there should be able to be a sort of 'everyone' group that USB media can be assigned to by default if desired that allows 100% access to whomever has the stick in their hand & wants to use it.

I know some folks have extreme security paranoia - but for me, and others whom I help out, we do not fear having invaders show up just to mess with the stuff on our PCs & USB media - and if some villain IS going to do that, then they are likely armed & will overpower us anyhow, so what is the use of making this into a nuisance ??

I really don't want to have to keep an actual XP box around just to have full access to my own USB sticks !!

Thanks for your time, energy and attention here.

1 Like

This scenario hasn't been common in my experience. Likely if it's just that one USB drive that's problematic, it could be on its way out (signs of hardware failure) or it needs wiping and starting fresh.

I'd highly recommend using GParted as mentioned earlier to create a new partition table. It's very possible the way it was originally formatted (especially as it was done by an old system) just doesn't play nice with a modern OS.

That would make sense since NTFS has a permissions system. FAT32 doesn't and attempts to change the owner/group doesn't make sense from the system's viewpoint.

Thanks again.
The USB drive that was problematic was actually bought new under 2 months ago.
Sure, it could be h/w failure already & now that it was wiped it seems OK.

I do use GParted as well as the Disk utility & at some points in this adventure had been alternating back & forth between them to see what each could do about it & what may have been different.

My top thought regarding this whole thing & moving forward is just that I want to be able to plug in whichever stick I need to use & have it mount as accessible without having to beat my head against the wall.

So...I'll be watching carefully to see which of my dozen sticks in use are fine & if/when any are not fine.

Thanks again.

1 Like

I have exactly the same super annoying problem with a number of USB sticks. Completely agree with you that this should not be such a problem!

Welcome here Michiel_perdeck !!

This, among the many other 'paper cut' sorts of unresolved goofy stuff continues to be a real, genuine PITA.

Even using exFAT doesn't work alot of the times.

Another USB related 'sore' for me happened when I plugged in an Android device to transfer some files;
It came up just fine, copied the files just fine - and when safely removed (via the pop-up banner) - it deleted several hundred files from that same directory for no apparent reason.

What continues to surprise me about this and the other stuff is that it seems to just be ignored as if it doesn't matter to anyone except for the very few vocal members;
Of course this is far better than the snark-a-thons that used to happen whenever anyone who was seen as a newbie asked about Linux stuff.

As an old before-DOS guy, I am not allergic to using the CLI - but at the same time I am also old enough that remembering every single nuance of required caps & other syntax often has me re-typing a command 7 times before getting it right !!!

This (for me) highlights the goodness in having stuff that JUST WORKS... like USB sticks, for example.

So I'll keep watching & a'wishin & a'hopin that some of my unanswered queries may finally get answered with working solutions...sigh.

Certainly not saying this is your problem but a USB stick being new does not mean it cannot be problematic. As the prices have came down, to me so has the quality. I bought 3 PNY USB drives that wrote extremely slow and that would freeze every time I tried to write large files to them, and need to be reformatted. I use them to play music in my vehicle, and when I shut off the engine they would lose formatting. They all destroyed themselves in a matter or weeks. I then tried Lexar and it took forever to write to them. I now pretty much stick to Scandisk. I never have trouble with them and they read and write very fast. I can buy a 32 G for $ 6 bucks.

I had exact issues (slow, freezes, failures) with PNY and certain type (nano form-factor) of SanDisk altough my use case is distro testing instead of music storage.

pavlos_kairis and lah7 have some good pointers. I had failures on both use cases. On one case, a 128G USB failed in less than 3 months and the error was write-protect got set to ON i.e., had become read-only. All the online/youtube expert tips didn't work. On the other hand, I had issues with USBs when they were removed without properly ejecting or 'safely remove'ing them. I either plugged back the USB to Windows and did 'safely remove' or had to reformat.

FAT32 volumes should not give permission errors. I tried to copy some files from /etc and /usr to my USB and after transfer their permissions had set to my username and I was able to edit them.

I know none of my rant helps either OP or anybody having similar issues. Just sharing my experience. I think we should still treat it as specific (USB) issue rather than systemic issue.

No, your rant just proves the point a new USB drive is not always a good, trouble free USB drive.