LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-30-2024, 01:11 PM   #1
GPGAgent
Senior Member
 
Registered: Oct 2018
Location: Surrey UK
Distribution: Mint 20 xfce 64bit
Posts: 1,026
Blog Entries: 3

Rep: Reputation: 133Reputation: 133
Copying to a USB stick


Title says it all, sounds dead easy, but I have problems doing this

I want to use the commandline and here is what happens.

Plug in USB stick

df -h shows this:
Code:
/dev/sdc1        29G   16K   29G   1% /media/jonke/A239-DFE4
I want to mount it as /media/OTR_MMSCIFI so I did this:
Code:
sudo mkdir /media/OTR_MMSCIFI
I had to use sudo because I didn't have permission under my login

Then I unmounted sdc1
Code:
umount /dev/sdc1
df -h shows sdc1 is unmounted

I mounted it
Code:
sudo mount /dev/sdc1 /media/OTR_MMSCIFI
df -h shows it is
Code:
/dev/sdc1        29G   16K   29G   1% /media/OTR_MMSCIFI
Then I copy a file
Code:
cp OTHERWORLDS.png /media/OTR_MMSCIFI
And I get this:
Code:
cp: cannot create regular file '/media/OTR_MMSCIFI/OTHERWORLDS.png': Permission denied
Fair enough it's owned by root

So I issued
Code:
sudo cp OTHERWORLDS.png /media/OTR_MMSCIFI
entered the sudo password an it copied, but everything is owned by root now.

What should I do so I can just use my login to:

Create a mount point
Mount USB
cp folders to USB

Seems a reasonable thing to do

I'm guessing the mount point is the issue because I don't have permission with my login to create a folder in /media
 
Old 03-30-2024, 01:55 PM   #2
yancek
LQ Guru
 
Registered: Apr 2008
Distribution: Slackware, Ubuntu, PCLinux,
Posts: 10,547

Rep: Reputation: 2498Reputation: 2498Reputation: 2498Reputation: 2498Reputation: 2498Reputation: 2498Reputation: 2498Reputation: 2498Reputation: 2498Reputation: 2498Reputation: 2498
Change the owner of the mount point /media/OTR_MMSCIFI. Standard users by default generally have read/write access only to their /home/username directory and not to partitions on external devices. This is standard behavior in Linux. You can change the owner partitions. If the USB you are using is simply data it should not be a problem. Do you have a Linux filesystem on the usb?
 
Old 03-30-2024, 02:21 PM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,761

Rep: Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931
Interesting, depends on what distribution/version you are running but most desktops these days automatically mount the drive when plugged in with r/w permissions for that particular user. A239-DFE4 would indicate a VFAT filesystem.

Typically linux permissions are by filesystem and not mount point of which VFAT is not compatible. You can manually mount the drive using mount options uid,gid that matches your user's uid and gid.
 
Old 03-30-2024, 06:28 PM   #4
GPGAgent
Senior Member
 
Registered: Oct 2018
Location: Surrey UK
Distribution: Mint 20 xfce 64bit
Posts: 1,026

Original Poster
Blog Entries: 3

Rep: Reputation: 133Reputation: 133
Thanks yancek and michaelk

The USB is formatted as FAT32 - I use it on Windows systems and my TV to play movies.

Anyway, I changed ownership of /media/OTR_MMSCIFI to $USER
Code:
sudo chown $USER OTR_MMSCIFI/
So far so good, I plug in my USB stick and copy to it, but the files jist go tp/media/OTR_MMSCFIFI - not the USB stick

So I unmounted it

Then I mounted it
Code:
$ mount /dev/sdc1 /media/OTR_MMSCIFI
mount: only root can do that
Okay lets try this
Code:
sudo mount /dev/sdc1 /media/OTR_MMSCIFI
[sudo] password for jonke:          
mount: /media/OTR_MMSCIFI: special device /dev/sdc1 does not exist.
I'm obviously doing this incorrectly, it cannot be so hard, all I want to do is to pop my usb stick into a port, and then cp a folder full of files to it.

Something like this should work
Code:
umount /dev/sdc1
sudo mkfs.fat -F 32 /dev/sdc1 -n "OTR_MMSCIFI"
mkdir /media/OTR_MMSCIFI
sudo chown $USER OTR_MMSCIFI/
sudo mount /dev/sdc1 /media/OTR_MMSCIFI
cp -r -v OTR-MURDER-MYSTERY-SCIFI /media/jonke/OTR_MMSCIFI
 
Old 03-30-2024, 06:53 PM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,761

Rep: Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931
[\quote]/dev/sdc on /media/username/TEST type vfat (rw,nosuid,nodev,relatime,uid=1000,gid=1000,fmask=0022,dmask=0022...[/quote]

Here is output of mount for a FAT32 flash drive automatically mounted when inserted on my debian 12 system. The mount point /media/username/drive_label is automatically created and the drive mounted using uid=1000,gid=1000 which is the uid and gid for my user on this system. Without the uid,gid it will be owned by root.

Quote:
mkdir /media/OTR_MMSCIFI
sudo chown $USER OTR_MMSCIFI/
sudo mount /dev/sdc1 /media/OTR_MMSCIFI
cp -r -v OTR-MURDER-MYSTERY-SCIFI /media/jonke/OTR_MMSCIFI
Your mounting to /media/OTR_MMSCIFI but then copying to /media/jonke/OTR_MMSCIFI which does not work. Changing the owner of the mount point prior to mounting has no affect on the filesystem itself. I don't have a Mint VM at the moment but I would expect it to do something similar.
 
Old 03-31-2024, 07:56 AM   #6
yancek
LQ Guru
 
Registered: Apr 2008
Distribution: Slackware, Ubuntu, PCLinux,
Posts: 10,547

Rep: Reputation: 2498Reputation: 2498Reputation: 2498Reputation: 2498Reputation: 2498Reputation: 2498Reputation: 2498Reputation: 2498Reputation: 2498Reputation: 2498Reputation: 2498
Linux user:group and rwx permissions do not apply on vfat filesystems, I missed that in your initial post. You can use fmask, dmask and/or umask in the /etc/fstab file or in your mount command. I expect the original location allowed you to copy as a user and likely would also work if you used "/media/jonke/OTR_MMSCIFI" as the mount point.
 
Old 03-31-2024, 10:06 AM   #7
GPGAgent
Senior Member
 
Registered: Oct 2018
Location: Surrey UK
Distribution: Mint 20 xfce 64bit
Posts: 1,026

Original Poster
Blog Entries: 3

Rep: Reputation: 133Reputation: 133
Hi Guys, Thanks for the update, I'll check through it and a bit more research ie duckduckgo!
 
Old 03-31-2024, 11:04 AM   #8
GPGAgent
Senior Member
 
Registered: Oct 2018
Location: Surrey UK
Distribution: Mint 20 xfce 64bit
Posts: 1,026

Original Poster
Blog Entries: 3

Rep: Reputation: 133Reputation: 133
Update, I've simplified my task with a tiny bit of research and help from you guys

The steps are:
Code:
~$ sudo umount /dev/sdc1
[sudo] password for jonke:          
jonke@charlie:~$ sudo mkfs.fat -n MMSCIFI -F 32 /dev/sdc1
mkfs.fat 4.1 (2017-01-24)
jonke@charlie:~$ cp -r -v OTR-MURDER-MYSTERY-SCIFI /media/jonke/MMSCIFI
Because I'm using FAT32 I don't specify a mount point, linux sorts that out for me

Cheers all Happy Easter
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to differentiate a mounted usb stick vs plugged in but not mounted usb stick. andrewysk Linux - Newbie 22 04-05-2021 02:42 PM
copying to this usb stick takes a long time, is there something wrong? Pedroski Linux - Hardware 7 06-22-2018 04:51 PM
frugal install to hd before copying to usb stick vonbiber Incognito 1 10-16-2009 04:09 PM
OSS software for copying PS saved games onto USB stick? DJOtaku Linux - Games 0 05-25-2005 10:35 PM
copying/moving stalls when moving a lot of data to a usb stick =X¥®µ§= Linux - Hardware 10 07-30-2004 05:29 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:42 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration