WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Can't write to USB drive <solved>  (Read 10846 times)

Offline herrMnnn

  • Newbie
  • *
  • Posts: 33
Can't write to USB drive <solved>
« on: May 18, 2012, 10:54:25 PM »
Sorry for all the questions, folks, but TC/Linux has a very steep learning curve and I am worn out from searching...

I am booting version 4.5.2 of Core to a command line.  It was installed onto sda1 (internal flash) using the installer program in CorePlus, selecting text only install, no extensions.

I need to write data to sdb1 (a removable flash drive) from a python script.  I previously had this running under TinyCore but want to run it with just the Core base.

When I try to write to the USB drive I get a permission denied error (either from the script or just with an echo command from the command line).  If I sudo the same command it works fine.

Mount returns:
Code: [Select]
/dev/sdb1 on /mnt/sdb1 type vfat (rw,relatime,fmask=0022,dmask=0022,codepage=cp437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro)
/etc/fstab contains the line:
Code: [Select]
/dev/sdb1       /mnt/sdb1       vfat     noauto,users,exec,umask=000 0 0 # Added by TC
ls -l in the /mnt directory gives me:
Code: [Select]
drwxr-xr-x    4 root     root          1024 May 19 10:51 sda1/
drwxr-xr-x    4 root     root         16384 May 19 12:17 sdb1/

sudo chmod 777 /mnt/sdb1 has no effect on the permissions of the directory.

What do I need to do to get universal access to the usb drive?  I guess I could run the script as root, but that doesn't seem right...

NB The system will be running unattended, so all settings need to survive a reboot after a power failure.






« Last Edit: May 19, 2012, 08:42:18 PM by herrMnnn »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11694
Re: Can't write to USB drive
« Reply #1 on: May 19, 2012, 12:04:56 AM »
Hi herrMnnn
Did you mount it using  sudo mount /dev/sdb1 /mnt/sdb1 ?
Try using  mount /dev/sdb1  instead.

Offline herrMnnn

  • Newbie
  • *
  • Posts: 33
Re: Can't write to USB drive
« Reply #2 on: May 19, 2012, 03:44:15 AM »
Thanks Rich.

It's mounted when I boot, TC appears to be doing it for me at boot time.  The entries in fstab were put there by TC or the installer or something, I haven't edited that file.

here's an example of what I get from the mount command:

Code: [Select]
tc@box:/mnt$ sudo umount /mnt/sdb1
umount: can't umount /mnt/sdb1: Device or resource busy
tc@box:/mnt$ mount /dev/sdb1 /mnt/sdb1
mount: you must be root
tc@box:/mnt$ sudo mount /dev/sdb1 /mnt/sdb1
mount: mounting /dev/sdb1 on /mnt/sdb1 failed: Device or resource busy
tc@box:/mnt$


I'm also a bit confused as to why chmod doesn't affect the permissions for the directory:

Code: [Select]
tc@box:/mnt$ ls -l
total 17
drwxr-xr-x    4 root     root          1024 May 19 10:51 sda1/
drwxr-xr-x    2 root     root         16384 Jan  1  1970 sdb1/
tc@box:/mnt$ sudo chmod 777 /mnt/sdb1
tc@box:/mnt$ ls -l
total 17
drwxr-xr-x    4 root     root          1024 May 19 10:51 sda1/
drwxr-xr-x    2 root     root         16384 Jan  1  1970 sdb1/
tc@box:/mnt$





Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11049
Re: Can't write to USB drive
« Reply #3 on: May 19, 2012, 04:41:36 AM »
You can't set the permissions because it's fat32, no support for permissions in that FS.

Try "sudo remount /mnt/sdb1 -o uid=1001,gid=50". It may need a full umount/mount instead of remount, but try anyway.
The only barriers that can stop you are the ones you create yourself.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11694
Re: Can't write to USB drive
« Reply #4 on: May 19, 2012, 06:51:53 AM »
Hi herrMnnn
Quote
It's mounted when I boot, TC appears to be doing it for me at boot time.
TC won't mount a drive just because it finds it. There's probably a tce or cde directory on it that's
causing that to happen. What does  ls /mnt/sdb1  give you?


Offline herrMnnn

  • Newbie
  • *
  • Posts: 33
Re: Can't write to USB drive
« Reply #5 on: May 19, 2012, 08:41:05 PM »
You can't set the permissions because it's fat32, no support for permissions in that FS.

Try "sudo remount /mnt/sdb1 -o uid=1001,gid=50". It may need a full umount/mount instead of remount, but try anyway.

Hi herrMnnn
Quote
It's mounted when I boot, TC appears to be doing it for me at boot time.
TC won't mount a drive just because it finds it. There's probably a tce or cde directory on it that's
causing that to happen. What does  ls /mnt/sdb1  give you?
Is there a forehead slapping emoticon I can use?   :-[

I must have put a mount command in /opt/bootlocal.sh at some time along the way. I was sure I hadn't but no-one else could have done it so I obviously did.

Adding the uid and gid options as per curaga's post has it all working.

Thanks for being so patient and helpful. I am learning a lot from this forum and just from researching solutions to the problems I seem to create for myself.  I have toyed with Linux several times over the past 10-15 years or so but never stuck with it. Tiny Core however is such an elegant solution that it has encouraged me to persist.

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11049
Re: Can't write to USB drive <solved>
« Reply #6 on: May 20, 2012, 05:11:45 AM »
Haha, "remount" ;) I'm getting old, obviously. Should have been mount -o remount.
The only barriers that can stop you are the ones you create yourself.