Recent

Author Topic: How do you enable Read/Write on USB device on Raspberry PI?  (Read 31326 times)

Awesome Programmer

  • Sr. Member
  • ****
  • Posts: 451
  • Programming is FUN only when it works :)
    • Cool Technology
How do you enable Read/Write on USB device on Raspberry PI?
« on: April 28, 2016, 05:19:25 pm »
I know I really should be asking these Raspberry PI questions on Raspberry PI forum... :D But Lazarus forum is more user friendly and love the layout.

I want my program to use USB stick as a storage for saving files and what not, but Raspberry won't let my program use USB. As I found out that USB is mounted as READ ONLY. So, I searched online for answer. This is what I found about enabling read/write permission on USB device on linux.

Code: Pascal  [Select][+][-]
  1. sudo mount -o remount, rw '/media/usb/'

However, this doesn't seem to work, even though Raspberry PI doesn't complain when I execute the above command on console.

So, how do you tell Raspberry PI to enable read/write permission on USB device?

Thanks,

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1313
Re: How do you enable Read/Write on USB device on Raspberry PI?
« Reply #1 on: April 28, 2016, 05:39:19 pm »
While that would work, there are a few problems with it:

1. It will first UNmount the storage device, which is problematic when files are in use.

2. You have to specify the sudo password. This could be done with a pipe:

echo pwd | sudo mount ...

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: How do you enable Read/Write on USB device on Raspberry PI?
« Reply #2 on: April 28, 2016, 05:59:16 pm »
Seems that you have not made the drive/partition part of the user/group ?

see also here.

Awesome Programmer

  • Sr. Member
  • ****
  • Posts: 451
  • Programming is FUN only when it works :)
    • Cool Technology
Re: How do you enable Read/Write on USB device on Raspberry PI?
« Reply #3 on: April 28, 2016, 09:43:29 pm »
Thank you for the replies, but I am still not able to write to my USB on my Raspberry PI. I tried the following.

Code: Pascal  [Select][+][-]
  1. sudo mount -o remount, rw '/media/usb/'
Initially, I did the above and executed fine, but it didn't work. Then, the following.

Code: Pascal  [Select][+][-]
  1. echo raspberry | sudo mount -o remount, rw '/media/usb/'
Executed fine, but Still No luck... Then I tried the following.

Code: Pascal  [Select][+][-]
  1. echo raspberry | sudo mount -o uid=pi, gid=pi /dev/sda1 /media/usb/
Complained usb is already mounted. So, I unmounted (sudo umount ....). Then, executed line above and worked fine, but usb is still not working.

I looked at my USB properties and this is what it showed for the permissions.

View content : Anyone
Change content: Only Owner
Access content: Anyone
« Last Edit: April 28, 2016, 09:59:42 pm by reltek »

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: How do you enable Read/Write on USB device on Raspberry PI?
« Reply #4 on: April 29, 2016, 06:57:22 am »
And, is user pi owner of the mountpoint ?

see also here.

If that still doesn't help, then the next question would be to ask what filesystem is on the pendrive. But as you haven't expressed that you are able to even read from it...

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1313
Re: How do you enable Read/Write on USB device on Raspberry PI?
« Reply #5 on: April 29, 2016, 09:22:35 am »
What you need to do is mount it in /etc/fstab

mig-31

  • Sr. Member
  • ****
  • Posts: 305
Re: How do you enable Read/Write on USB device on Raspberry PI?
« Reply #6 on: April 29, 2016, 10:29:57 am »
Hi,

you don't provide a file system info of your Flash drive.

I think Linux distrubution for Rasberry Pi behaves as normal Linux distribution for x86/x86-64 and generally Flash drive in modern Linux distribution is mounted with rw permisions to /var/run/disk-ID and any program have access to it.

Usually issues with Flash drive are connected with NTFS file system. For this case, you have should install NTFS-3g driver on your system (kernel driver usually compiled with read-only option). Usually it is better to use file system without user permisions FAT32 or exFAT or ext2 for Flash drive.   
Lazarus 2.2.6 - OpenSuse Leap 15.4, Mageia 8, CentOS 7

Awesome Programmer

  • Sr. Member
  • ****
  • Posts: 451
  • Programming is FUN only when it works :)
    • Cool Technology
Re: How do you enable Read/Write on USB device on Raspberry PI?
« Reply #7 on: April 29, 2016, 03:03:30 pm »
I ran the following command

Code: Pascal  [Select][+][-]
  1. sudo fdisk /dev/sda1 -l

It said, USB filesystem is unknown. Then I ran the following command.

Code: Pascal  [Select][+][-]
  1. sudo blkid

It said, the USB stick has VFAT filesystem.

Owner is root for this USB. I am able to access the files and make changes to the USB but only through SUDO commands like copy, delete or move like the following

Code: Pascal  [Select][+][-]
  1. sudo cp /home/pi/test.gif /media/usb/


Since owner is root for the USB, I decided to start my program from the console instead of from the desktop shortcut doing the follwing

Code: Pascal  [Select][+][-]
  1. sudo ./myprogram
And bunch of errors showed up in the console

Code: Pascal  [Select][+][-]
  1. (myprogram:1417): Gtk-WARNING **: Attempting to store changes into `/root/.local/share/recently-used.xbel', but failed: Failed to create file '/root/.local/share/recently-used.xbel.PNP0GY': No such file or directory
  2.  
  3. (myprogram:1417): Gtk-WARNING **: Attempting to set the permissions of `/root/.local/share/recently-used.xbel', but failed: No such file or directory
  4. TApplication.HandleException Access denied
  5.   Stack trace:
  6.   $00110A70  TSYSTEMDLG__WRITE,  line 176 of Ezsystem.pas
  7.   $00110830  TSYSTEMDLG__OKBTNCLICK,  line 135 of Ezsystem.pas
  8.   $0031C6E4  TCONTROL__CLICK,  line 2711 of ./include/control.inc
  9.   $0034F2F4  TBUTTONCONTROL__CLICK,  line 54 of ./include/buttoncontrol.inc
  10.   $0034FC84  TCUSTOMBUTTON__CLICK,  line 169 of ./include/buttons.inc
  11.   $0033D68C  TCUSTOMBITBTN__CLICK,  line 64 of ./include/bitbtn.inc
  12.   $0034F1BC  TBUTTONCONTROL__WMDEFAULTCLICKED,  line 20 of ./include/buttoncontrol.inc
  13.   $00044B48
  14.   $0030AB38  TWINCONTROL__WNDPROC,  line 5326 of ./include/wincontrol.inc
  15.   $0040CD44  DELIVERMESSAGE,  line 112 of lclmessageglue.pas
  16.   $0041DA64  GTK2WSBUTTON_CLICKED,  line 2435 of gtk2wsstdctrls.pp
  17.   $76969AFC
  18.  

By the way, I just want to let the forum administrators know that I am not asking pure Raspberry PI question on Lazarus forum just because... My program was written using latest FPC and Lazarus... Thanks.
« Last Edit: April 29, 2016, 03:26:57 pm by reltek »

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1313
Re: How do you enable Read/Write on USB device on Raspberry PI?
« Reply #8 on: April 29, 2016, 03:22:31 pm »
There are two good options when you want to mount a drive in a specific way. The first is for drives that you don't remove: add then to /etc/fstab.

If you want to be able to remove the drive while the computer is running, you need to use usbmount, or autofs for older and/or non-Debian Linuxes. Ubuntu is also Debian.

VFAT should be easy.

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: How do you enable Read/Write on USB device on Raspberry PI?
« Reply #9 on: April 29, 2016, 04:19:35 pm »
Since owner is root for the USB, ....
And therein lies your 'problem'.

It is normal for such things to administer groups that are allowed certain access to certain devices. If your user pi does not belong to such a group that is able to read/write or do whatever from/to a particular device, then you'll never gonna get things to work without root access.

Awesome Programmer

  • Sr. Member
  • ****
  • Posts: 451
  • Programming is FUN only when it works :)
    • Cool Technology
Re: How do you enable Read/Write on USB device on Raspberry PI?
« Reply #10 on: April 29, 2016, 05:26:40 pm »
I see... Okay...

So, I added user pi to root group as follows.

Code: Pascal  [Select][+][-]
  1. sudo adduser pi root

Afterward it said user pi is added to the root group. Then, I rebooted Raspberry PI and still no change. I keep getting access denied.

My USB stick doesn't have any write-protect buttons or sliders. It is a straight USB.

mas steindorff

  • Hero Member
  • *****
  • Posts: 533
Re: How do you enable Read/Write on USB device on Raspberry PI?
« Reply #11 on: April 29, 2016, 08:44:46 pm »
does your program work when you login as root?
windows 10 &11, Ubuntu 21+ IDE 3.2.2 general releases

 

TinyPortal © 2005-2018