How to enable access to newly installed USB stick ?

Status
Not open for further replies.

anneranch

Active Member
Joined
Mar 16, 2019
Messages
223
Reaction score
43
Credits
2,078
I can use gparted to add / format etc. new USB stick. I used to use "disks" to mount it, but having an issues installing in ....
BUT - when I use C++ IDE to build an new program on this USB I cannot "create directory" .

I must be missing permissions and perhaps ownership...

Is there a SIMPLE way to ENABLE access to newly installed , as far as gparted is concerned, USB stick?

(what silly "security " issue - gparted is password enabled, can format the drive but cannot enable access to it....)


Or is the " chown " command the ONLY way to do it ?
 


Does lsusb see the usb stick?

***The usb stick should show in the file manager, unless the user does not have permission to mount it.***

IF you're trying to create a directory use the mkdir command.


Change ownership:
 
Last edited:
OK, let's forget the chown...
and RE-READ the OP , including the part about gparted
it is the IDE who wants to save the current program
the device , USB in this case in not know until the IDE needs to save it
there is no "mkdir" - it is hidden in IDE...
Yes . lsusb shows it , the ownership is "root"
so
if I am IN the USB disk main folder
mainfolder/ sudo chown ???? to what ??
sudo chown -R root ??? root is alrady the owner ...
can you help me and write exactly the chown options ?

Thanks
 
Dude, you're sounding a tad aggressive there. I know how frustratrating it is when people don't get what you're saying, but they're using their free time help and the wording in your second post is obscure at best (the OP is intellegible, though). Chown is unavoidable.

1. Go to Gparted, select your USB, create a new table + partition. "Label" the partition whatever you like. In this example, I'll call it "myusb". Format it to whatever. In this example, I'll use ext4.
2. # mkdir -p /media/removable/myusb/
3. # chown 1000:1000 /media/removable/myusb
4. # nano /etc/fstab
5. Enter the following below the other entries:
Code:
LABEL="myusb"	/media/removable/myusb/	ext4	defaults,user,exec,auto,rw	0	0
Now save and exit (ctr+o then ctrl+x).
6. Unplug your USB stick and plug it in again. It should work fine. Should show up in any file browser, including in-app. This will persist across reboots.

5-10 minutes of work.

Footnotes:
- "defaults" option includes most, but it's good to be explicit since 1% of the time I've encountered odd behavior.
- If you don't like nano, run a GUI text editor as root.
- If there's still any permisions problem, "# chown -R 1000:1000 /media/removable/myusb && chmod -R +x /media/removable/myusb" while USB is plugged in. You only have to do that once. It's unlikely you will. Just another 1% quirk I noticed.
- The reason you could not create a directory is probably because IIRC, external devices are noexec by default.
 
Last edited:
Nice one, @Fanboi :)

@anneranch

Just for purposes of clarity, @Fanboi 's steps 2 through 4 above - the # means you are Root, that is, you have used eg

sudo -i

or

sudo -su

to become root. Other than that, you would preface each of the commands with

sudo

To exit the Root environment, type and enter

exit

You have said

I used to use "disks" to mount it, but...

which might indicate you are in a GNOME DE (desktop environment) but you have not stated what distro you are actually using, and the the version and DE. This is always the best idea, as some steps may vary.

We haven't the time to go wandering through your previous posts to find what you are using. My crystal ball is in at the shop for a service.

Please understand we are trying to help you to help us to help you.

Cheers

Chris Turner
wizardfromoz
 
I really appreciate all your contributions, with an exception of comment on my "attitude" and other comment which IMHO belong to social media and not in forum like this.

There is no need starting with " turn the power on..." but it would be nice to comment / explain stuff.

From my perspective
I know this about the USB from standard "properties"

/media/qy

volume "DISK_C"

I can open the "file" "in terminal"

qy@qy-desktop:/media/qy/DISK_C$

and this is where I would change the ownership

qy@qy-desktop:/media/qy/DISK_C$ ls -l
total 16
drwx------ 2 root root 16384 Sep 12 09:13 lost+found
qy@qy-desktop:/media/qy/DISK_C$


and that is what I am asking - what EXACT options I should use

qy@qy-desktop:/media/qy/DISK_C$ sudo chown -R ????????

It somebody write the options for me - that would be great and then I can muddle thru fstab....

Or maybe get a discussion going why IDE cannot change the ownership of "external device " such as USB.

Cheers
 
i'm not sure you even need to have user permissions, directly on the stick .
fstab is usually for fixed internal drives ; personally i wouldn't add a usb stick to that - but each to their own

So let me explain.. I have an SD card slot in my laptop ; when i want to create a timeshift snapshot i pop in one of my SD cards that is formatted to ext4 . Timeshift is evoked with sudo permissions , which means whats written to it has root permissions.

If i run :
Code:
fdisk -l
Disk /dev/sdb: 29.72 GiB, 31914983424 bytes, 62333952 sectors
Disk model: SD/MMC/MS PRO
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: 0x337a2ad8


Device     Boot Start      End  Sectors  Size Id Type
/dev/sdb1        2048 62332927 62330880 29.7G 83 Linux


So the SD card (itself ) is coming up as /dev/sdb
Theres a partition table of dos type - thats ok
and then there is a partition /dev/sdb1 thats the one i want to mount and play with.
Thats also the one that Timeshift writes to and like yours is formated to a linux file system ext4 in my case .

It did auto mount, but i unmounted and then mounted it manually.

Now the default place on my Arch where usb sticks and sd cards get mounted is /run/media
Inside that there was already a dir called andrew.

I intended to mount the partition /dev/sdb1 to /run/media/andrew/sdcard

but there wasn't a directory called sdcard so I made one.

Code:
cd /run/media/andrew
sudo mkdir sdcard
sudo chmod 775 sdcard -R
//here i decide to give dir called "sdcard" permissions of 775

Now i'm going to mount the partition /dev/sdb1 of the SD card ( /dev/sdb) at /run/media/andrew/sdcard

Code:
sudo mount   /dev/sdb1  /run/media/andrew/sdcard
//that mounted no problem

now i change directory and go have alook:

Code:
[andrew@darkstar:~]$ cd /run/media/andrew/sdcard                          (09-13 17:49)
[andrew@darkstar:andrew/sdcard]$ ls -l                                    (09-13 17:49)
total 20
drwx------ 2 root root 16384 Jun 22 13:42 lost+found/
drwxr-xr-x 9 root root  4096 Sep 10 12:56 timeshift/
[andrew@darkstar:andrew/sdcard]$                                          (09-13 17:49)

if you look at the image you can see i can now navigate to /run/media/andrew/sdcard and ls- l shows root ownership and permissions

If i wanted to write to the files I think i would do it on the mount

i.e sudo chown andrew: users /run/media/andrew/sdcard

// in the above andrew will be the owner users will be the group that andrew might belong to; you need to find out which group , you as a user belong. I set myself up when i installed Arch slightly different. Then if i want to set permissions :

Code:
sudo chmod 775 /run/media/andrew/sdcard  -R

Now thats going to work while its mounted- not a whole solution but might help
 

Attachments

  • run-media-andrew-sdcard.png
    run-media-andrew-sdcard.png
    29.8 KB · Views: 197
Last edited:
i'm not sure you even need to have user permissions, directly on the stick .
 
i'm not sure you even need to have user permissions, directly on the stick .
That's just a paste from the previous post from @captain-sensible. I dunno if that's a joke or trying to emphasize something, but you seem to want a solution that works your way. That's not going to happen unless whatever bug is causing the situation you described is patched. If. So, for now you have multiple solutions now. Just follow them. The fstab file is very useful for removable storage that you regularly use because it ensures the media is always mounted at the same, human readable, point. That makes is useful for things like backup programs or having a mobile workspace.


I really appreciate all your contributions, with an exception of comment on my "attitude" and other comment which IMHO belong to social media and not in forum like this.

There is no need starting with " turn the power on..." but it would be nice to comment / explain stuff.

From my perspective
I know this about the USB from standard "properties"

/media/qy

volume "DISK_C"

I can open the "file" "in terminal"

qy@qy-desktop:/media/qy/DISK_C$

and this is where I would change the ownership

qy@qy-desktop:/media/qy/DISK_C$ ls -l
total 16
drwx------ 2 root root 16384 Sep 12 09:13 lost+found
qy@qy-desktop:/media/qy/DISK_C$


and that is what I am asking - what EXACT options I should use

qy@qy-desktop:/media/qy/DISK_C$ sudo chown -R ????????

It somebody write the options for me - that would be great and then I can muddle thru fstab....

Or maybe get a discussion going why IDE cannot change the ownership of "external device " such as USB.

Cheers
IDK what you mean by "write the options for me". I gave you the line to add to /etc/fstab.

Unless you want to know what to add to "sudo chown -R ????????". Based on the output, your partition is "media/qy/DISK_C$/" and it seems empty. May I suggest renaming the mountpoint and removing the "$". Anyway, to answer the question:
Code:
sudo chown -R qy:qy '/media/qy'
OR
Code:
sudo chown -R 1000:1000 '/media/qy'
If you are the only user.
But this is temporary, and you may still possibly have to make it executable to all (a+x). This change may revert ownership next time you remove and re-insert the drive. That's why I suggested using fstab. Don't worry with lost+found, it's filesystem-level and contains fragments and dereferenced stuff (IIRC it is specific to EXT2-4, but I may be wrong there).
Anyway, if "echo > test.file" works from the terminal as a regular user in the flashstick's root directory, then you have write access, so IDK why there's is a problem without more info...

Tell us what IDE you are coding in and what DE (most specifically file manager) you are using. They have quirks, for example, Thunar asks for root password for unmounting all internal disks, even user-mountable ones, yet it doesn't when mounting. There are many quirks like this. That's why fstab is simply easier. It makes the entire system conform. Anyway, info. And if someone's suggestion works or you figure it out, please mark this as solved.
 
Status
Not open for further replies.

Staff online

Members online


Latest posts

Top