User avatar
liudr
Posts: 685
Joined: Sat Jun 01, 2013 12:11 am
Location: Central MN, USA
Contact: Website

How do I access a usb flash drive?

Wed Jul 03, 2013 6:33 pm

I have several flash drivers that I can access on my Debian box but the Debian box is a full PC and I am a noob. If I plug a usb flash drive to my RPI, how do I get access to its file system? I need some hands holding :) Thanks.

I attempted:

Code: Select all

sudo mount /dev/sdb /mnt/usb
Error message:

Code: Select all

mount: mount point /mnt/usb does not exist
In fact that is no sub folder inside mnt or any file at all.

Update: the flash drive is automatically mounted if I startX and I can access it from the GUI or console windows. The drive is mounted to /media/(volume name)
Arduino data loggers, user interface, printed circuit board designer since 2009, RPI 3B 2B 2B Zero Jessie, assembly/C/C++/java/python programmer since the 80's

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

Re: How do I access a usb flash drive?

Wed Jul 03, 2013 7:06 pm

FWIW There's also an article on "manual mounting" in the wiki at http://elinux.org/RPi_Adding_USB_Drives and my "variants on that theme" for multiple drives at http://www.cpmspectrepi.webspace.virgin ... ticks.html .
Trev.
Still running Raspbian Jessie or Stretch on some older Pi's (an A, B1, B2, B+, P2B, 3xP0, P0W, 2xP3A+, P3B+, P3B, B+, A+ and a B2) but Buster on the P4B's. See: https://www.cpmspectrepi.uk/raspberry_pi/raspiidx.htm

Nr90
Posts: 216
Joined: Sat Nov 26, 2011 12:39 pm

Re: How do I access a usb flash drive?

Thu Jul 04, 2013 2:44 am

You need to create a mountpoint first:

Code: Select all

sudo mkdir /mnt/usb
Then you whenever you plug a drive into your RPi you do:

Code: Select all

sudo mount /dev/sdb1 /mnt/usb

User avatar
jackokring
Posts: 816
Joined: Tue Jul 31, 2012 8:27 am
Location: London, UK
Contact: ICQ

Re: How do I access a usb flash drive?

Thu Jul 04, 2013 2:55 am

The option user maybe useful in fstab. Complicated ...

Code: Select all

man mount
Pi[NFA]=B256R0USB CL4SD8GB Raspbian Stock.
Pi[Work]=A+256 CL4SD8GB Raspbian Stock.
My favourite constant 1.65056745028

User avatar
liudr
Posts: 685
Joined: Sat Jun 01, 2013 12:11 am
Location: Central MN, USA
Contact: Website

Re: How do I access a usb flash drive?

Wed Jul 10, 2013 6:11 am

Sorry for not getting back to all of you. The mount didn't work. If I sudo mount then the folder is only accessible to root. If I chmod on it, then I can view files in it with pi account but not any sub folders cause they are still root only.

If I umount it and chmod the USB folder to 777, then a subsequent sudo mount will reset it to 700 so pi can never see anything in it just because root mounts it. What to do? I hate the stupid root?
Arduino data loggers, user interface, printed circuit board designer since 2009, RPI 3B 2B 2B Zero Jessie, assembly/C/C++/java/python programmer since the 80's

smithg400
Posts: 148
Joined: Sat Dec 24, 2011 3:37 pm

Re: How do I access a usb flash drive?

Wed Jul 10, 2013 7:05 am

I'm assuming the flash drive is formatted using a linux filesystem (ext2/3/4 or similar) here, so both the debian box and the raspberry pi have a concept of ownership.

The reason that changing the /mnt/usb folder to 777 doesn't work is that the /mnt/usb folder you created on the sdcard is hidden by the root folder of your flashdrive when it is mounted and it is then the permissions on the directories and files on the flash drive that matter. (If you unmount again you'll see the /mnt/usb on the sdcard again and it will still have 777 permissions).

Who owns the files when the flashdrive is attached to your debian box? And what permissions do they have then? If (for example) the files are owned by your account (say it is called 'user') and the files are only accessible by 'user', then when you put the drive in the Raspberry Pi the user 'pi' isn't the user 'user' and won't be able to access them (actually it doesn't matter what the usernames are - rather the uid that they map to must be the same).

However this is quite easy to fix using a couple of commands:

Code: Select all

sudo chmod -R a+rw /mnt/usb
sudo find /mnt/usb -type d -exec chmod a+x {} \;
The first command will make all files and directories readable and writeable by all users. The second will add the search bit (x) for directories. Should you have any scripts/binaries you may have to add the execute bit (x) to them individually using

Code: Select all

sudo chmod a+x /mnt/usb/path-to-file/filename
An alternate (and maybe better) method would be change the ownership of the files so they are owned by the pi user using

Code: Select all

chown -R pi:pi /mnt/usb
If you want to transfer files back and forth you might want to think about the accounts / permissions on the files / directories more carefully - you can always create a new account on the pi that matches (same uid) the account on the debian box. (or create a pi account on the debian box) and use that.

User avatar
liudr
Posts: 685
Joined: Sat Jun 01, 2013 12:11 am
Location: Central MN, USA
Contact: Website

Re: How do I access a usb flash drive?

Wed Jul 10, 2013 2:32 pm

The flash drive is formatted in FAT32. From some reading I did online, if FAT32 is mounted, then all properties follow the mount point. Maybe that is not correct. I can use this flash drive if I startX or if I use it on my Debian box. No use. Anything chmod I made gets removed after I mount the drive. If I do the chmod -R after I mount the drive, then RPI says operation not supported for every single file, as I suspected the drive is FAT32. I don't know how the lxdr window manager did the mount. Using a flash drive should NOT be this hard.

Has anyone manually mounted a FAT32 drive?
Arduino data loggers, user interface, printed circuit board designer since 2009, RPI 3B 2B 2B Zero Jessie, assembly/C/C++/java/python programmer since the 80's

User avatar
topguy
Posts: 5887
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: How do I access a usb flash drive?

Wed Jul 10, 2013 3:20 pm

liudr wrote:Has anyone manually mounted a FAT32 drive?
Many times. You have to tell mount which "umask" to use for the files when mounting vfat (fat16/23) since the filesystem doesnt support access-restrictions. The output of "mount" will give you the options to use when mounting, you can compare this to what you get from "mount" when its mounted under "/media".

Code: Select all

[email protected] ~ $ sudo mkdir /mnt/usb
[email protected] ~ $ ls -l /mnt/
total 4
drwxr-xr-x 2 root root 4096 Jul 10 15:05 usb
[email protected] ~ $ sudo mount /dev/sda1 /mnt/usb/
[email protected] ~ $ mount 
/dev/root on / type ext4 (rw,noatime,data=ordered)
devtmpfs on /dev type devtmpfs (rw,relatime,size=183620k,nr_inodes=45905,mode=755)
tmpfs on /run type tmpfs (rw,nosuid,noexec,relatime,size=38376k,mode=755)
tmpfs on /run/lock type tmpfs (rw,nosuid,nodev,noexec,relatime,size=5120k)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /run/shm type tmpfs (rw,nosuid,nodev,noexec,relatime,size=76740k)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620)
/dev/mmcblk0p5 on /boot type vfat (rw,relatime,fmask=0022,dmask=0022,codepage=cp437,iocharset=ascii,shortname=mixed,errors=remount-ro)
/dev/sda1 on /mnt/usb type vfat (rw,relatime,fmask=0022,dmask=0022,codepage=cp437,iocharset=ascii,shortname=mixed,errors=remount-ro)
[email protected] ~ $ ls /mnt/usb
<I see all my files >
[email protected] ~ $ touch /mnt/usb/test.txt
touch: cannot touch `/mnt/usb/test.txt': Permission denied
[email protected] ~ $ sudo umount /mnt/usb
[email protected] ~ $ sudo mount /dev/sda1 /mnt/usb/ -o fmask=0000,dmask=0000
[email protected] ~ $ ls -l /mnt/
total 4
drwxrwxrwx 13 root root 4096 Jan  1  1970 usb
[email protected] ~ $ touch /mnt/usb/test.txt
[email protected] ~ $ ls -l /mnt/usb/test.txt 
-rwxrwxrwx 1 root root 0 Jul 10 15:15 /mnt/usb/test.txt

smithg400
Posts: 148
Joined: Sat Dec 24, 2011 3:37 pm

Re: How do I access a usb flash drive?

Wed Jul 10, 2013 3:51 pm

Ah - as I said I'd assumed a linux filesystem if you were using it with your debian machine. As topguy said msdos type filesystems need to be told what user ids and protections to use.

When running a debian graphical desktop manager when you insert a flash drive it makes the userid/groupid of the mount match the userid/groupid of the user logged into the desktop and does something appropriate with the mask setting as well (which controls the permissions you see). When you do it manually on the RasPi with something like:

Code: Select all

sudo mount /dev/sda1 /mnt/usb
it users the userid/groupid match the userid/groupid of the user running the command (root) and the mask match the users umask setting. You can easily override this though. Try this command instead:

Code: Select all

sudo mount -o uid=pi,gid=pi /dev/sda1 /mnt/usb
(You may need to change the /dev/sda1 to fit your drive). This will mount it using the userid/groupid of the user pi.

You can also add options for umask (or fmask/dmask) to modify the protection of the files. Do 'man mount' for details.

User avatar
liudr
Posts: 685
Joined: Sat Jun 01, 2013 12:11 am
Location: Central MN, USA
Contact: Website

Re: How do I access a usb flash drive?

Wed Jul 10, 2013 4:11 pm

Awesome answers (not just solutions but also explanations)! I was able to do the -o uid and pid option to mount as pi. This way pi has exclusive access (which is fine). I will try the fmask and umask as well. This is easier than I thought. Mank thanks.
Arduino data loggers, user interface, printed circuit board designer since 2009, RPI 3B 2B 2B Zero Jessie, assembly/C/C++/java/python programmer since the 80's

User avatar
IgorGanapolsky
Posts: 33
Joined: Sun Apr 10, 2016 8:32 pm

Re: How do I access a usb flash drive?

Fri Aug 12, 2016 4:51 pm

Nr90 wrote:You need to create a mountpoint first:

Code: Select all

sudo mkdir /mnt/usb
Then you whenever you plug a drive into your RPi you do:

Code: Select all

sudo mount /dev/sdb1 /mnt/usb
I get an error:
wrong fs type, bad option, bad superblock on /dev/sda1,
missing codepage or helper program, or other error

SonOfAMotherlessGoat
Posts: 690
Joined: Tue Jun 16, 2015 6:01 am

Re: How do I access a usb flash drive?

Fri Aug 12, 2016 5:16 pm

What filesystem type is the flash drive formatted for? You might need to specify that with a -t option when you call mount if the OS isn't able to recognize the type by the magic number.
Account Inactive

1mpossible
Posts: 1
Joined: Sat Aug 04, 2018 7:28 am

Re: How do I access a usb flash drive?

Sat Aug 04, 2018 7:31 am

topguy wrote:
Wed Jul 10, 2013 3:20 pm
liudr wrote:Has anyone manually mounted a FAT32 drive?
Many times. You have to tell mount which "umask" to use for the files when mounting vfat (fat16/23) since the filesystem doesnt support access-restrictions. The output of "mount" will give you the options to use when mounting, you can compare this to what you get from "mount" when its mounted under "/media".

Code: Select all

[email protected] ~ $ sudo mkdir /mnt/usb
[email protected] ~ $ ls -l /mnt/
total 4
drwxr-xr-x 2 root root 4096 Jul 10 15:05 usb
[email protected] ~ $ sudo mount /dev/sda1 /mnt/usb/
[email protected] ~ $ mount 
/dev/root on / type ext4 (rw,noatime,data=ordered)
devtmpfs on /dev type devtmpfs (rw,relatime,size=183620k,nr_inodes=45905,mode=755)
tmpfs on /run type tmpfs (rw,nosuid,noexec,relatime,size=38376k,mode=755)
tmpfs on /run/lock type tmpfs (rw,nosuid,nodev,noexec,relatime,size=5120k)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /run/shm type tmpfs (rw,nosuid,nodev,noexec,relatime,size=76740k)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620)
/dev/mmcblk0p5 on /boot type vfat (rw,relatime,fmask=0022,dmask=0022,codepage=cp437,iocharset=ascii,shortname=mixed,errors=remount-ro)
/dev/sda1 on /mnt/usb type vfat (rw,relatime,fmask=0022,dmask=0022,codepage=cp437,iocharset=ascii,shortname=mixed,errors=remount-ro)
[email protected] ~ $ ls /mnt/usb
<I see all my files >
[email protected] ~ $ touch /mnt/usb/test.txt
touch: cannot touch `/mnt/usb/test.txt': Permission denied
[email protected] ~ $ sudo umount /mnt/usb
[email protected] ~ $ sudo mount /dev/sda1 /mnt/usb/ -o fmask=0000,dmask=0000
[email protected] ~ $ ls -l /mnt/
total 4
drwxrwxrwx 13 root root 4096 Jan  1  1970 usb
[email protected] ~ $ touch /mnt/usb/test.txt
[email protected] ~ $ ls -l /mnt/usb/test.txt 
-rwxrwxrwx 1 root root 0 Jul 10 15:15 /mnt/usb/test.txt
Thank You So Much

LTolledo
Posts: 2009
Joined: Sat Mar 17, 2018 7:29 am
Location: Anime Heartland

Re: How do I access a usb flash drive?

Sat Aug 04, 2018 2:31 pm

how about using pmount to manually mount your usb flash drive?
"Don't come to me with 'issues' for I don't know how to deal with those
Come to me with 'problems' and I'll help you find solutions"

Some people be like:
"Help me! Am drowning! But dont you dare touch me nor come near me!"

RomoBoom
Posts: 45
Joined: Sat Sep 01, 2018 12:07 am

Re: How do I access a usb flash drive?

Wed Jan 16, 2019 6:30 pm

but where is it in the folders if zou have raspbian stretch

please, use simple words :lol:

RomoBoom
Posts: 45
Joined: Sat Sep 01, 2018 12:07 am

Re: How do I access a usb flash drive?

Wed Jan 16, 2019 6:35 pm

nvm i found it :lol:
but how to wipe the MiniSD card...?

i have a old pi3 data and stuff on the card, and want to put the pi3b+ code on it w.o. the other stuff, but it will not let me delete it :( :roll:

please, help

Return to “Beginners”