LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware
User Name
Password
Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?

Notices


Reply
  Search this Thread
Old 10-04-2006, 12:40 AM   #1
adds2one
Member
 
Registered: Aug 2005
Location: Vancouver, BC
Distribution: Ubuntu 6.06
Posts: 154

Rep: Reputation: 30
How to write files immediately to flash drive.


I am having trouble writing files to my USB flash drive from Ubuntu.

I remember reading somewhere about being able to set whether files are copied immediately or at some later time when a command is given to write a file to a drive. I think that this is causing me a problem.

The flash drive mounts fine and I can copy and paste files onto it but when I then take the USB flash drive to another computer (windows or linux) the copied files aren't there.

This is true unless I actually open the file on the flash drive from the flash drive after copying it. Then when I take the drive to another computer the file is there. Also if I leave the flash drive in for a long time and then take it to another computer the files will be there.

Does anyone know about this and what I need to do to fix it?
 
Old 10-04-2006, 01:08 AM   #2
pda_h4x0r
Member
 
Registered: Feb 2006
Location: somewhere in cyberspace
Distribution: Debian, Familiar
Posts: 380

Rep: Reputation: 31
You need to mount your flashdrive with the option "sync" set. You can add it to your /etc/fstab or you can set it as an option with the mount command. Also typing in the command "sync" will cause all the files to move to your flashdrive (i.e. this synchronizes all the mounted drives on the system).

Example:

sudo mount -o sync /dev/sda1
 
Old 10-05-2006, 12:11 AM   #3
adds2one
Member
 
Registered: Aug 2005
Location: Vancouver, BC
Distribution: Ubuntu 6.06
Posts: 154

Original Poster
Rep: Reputation: 30
Ah yes, that sounds familiar.

I am confused though because my USB flash drive is not in my /etc/fstab and yet it mounts perfectly fine when I insert it in the USB port. I have never had to manually mount the flash drive.

The drive mounts automatically to /media/MYUSBSTICK and I can access it from the desktop.

How is it knowing where and how to mount if it has no /etc/fstab entry? And then how can I change it so that all flash drives are mounted with the synch option?

Thanks for your help.
 
Old 10-05-2006, 01:21 AM   #4
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794

Rep: Reputation: 282Reputation: 282Reputation: 282
No answer to your last question, but is there no unmount/eject option in the context menu of the /media/myusbstick icon?

To my knowledge, syncing can significantly reduce the lifespan of an usb-stick. Each byte in any flash or eeprom can only be written a limited number of times. As each write of a file involves an update of the FAT, that will be the weak point. By syncing, you're forcing the actual writing.
 
Old 10-05-2006, 04:40 PM   #5
adds2one
Member
 
Registered: Aug 2005
Location: Vancouver, BC
Distribution: Ubuntu 6.06
Posts: 154

Original Poster
Rep: Reputation: 30
I've got it working now. All I need to do is "eject" the USB flash drive before I remove it. The computer then writes any changes to the stick and then I can remove it and the data is there. It is a little annoying to me that I have to do this extra step but if it makes the lifespan longer then I guess that is better.

Makes me wonder though if using the stick in a Windows environment is going to shorten the lifespan of the stick because it writes immediately.

Thanks for your help.
 
Old 10-05-2006, 05:56 PM   #6
Electro
LQ Guru
 
Registered: Jan 2002
Posts: 6,042

Rep: Reputation: Disabled
The correct way is using the sync command or to include it during mounting. Using the command eject is not the correct way and you do not know if the data has been sync when using the eject command.

Writting to flash disk or flash mediums always shortens its lifespan. These devices have a limit between 100,000 to 1,000,000 writes. Usually reads are unlimited. The oldest bit or byte can be 5 to 10 years old. Another solid-state non-volitile memory is FRAM which has unlimited writes and reads. The only two reasons why we are not using this device is because of its small capacity and power consumption when combining multiple FRAM chips on one board. The maximum is 512 kilobytes for each chip. About four chips can be used for USB and about 8 chips for IEEE-1394.

I think Ubuntu uses dbus which is an another automounter controlled by its own scripts. Automounters are ok, but can create problems in the future. I do not recommend putting any lines in /etc/fstab for USB/IEEE-1394 storage devices because they are not predictable.
 
Old 10-05-2006, 11:34 PM   #7
pda_h4x0r
Member
 
Registered: Feb 2006
Location: somewhere in cyberspace
Distribution: Debian, Familiar
Posts: 380

Rep: Reputation: 31
Quote:
Originally Posted by Electro
The correct way is using the sync command or to include it during mounting. Using the command eject is not the correct way and you do not know if the data has been sync when using the eject command.
Wait, eject doesn't sync? But every time I select "eject" or "Safely Remove" in either GNOME or KDE, I see that my USB drive sometimes is written to during the ejection process. I always assumed that sync had been executed as part of the ejection script...
 
Old 10-06-2006, 12:13 AM   #8
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794

Rep: Reputation: 282Reputation: 282Reputation: 282
Quote:
Originally Posted by Electro
Writting to flash disk or flash mediums always shortens its lifespan.
Yes, but syncing implies that stuff is immediately written while that is not 'necessary'.

If my understanding is correct:
write a file
write same file again

If you use sync, it will be two 'physical' writes. If you don't use sync, it might be one 'physical' write.

Please correct me if I wrong as I don't know the exact details how the OS handles everything.
 
  


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
Cannot mount USB Flash Drive, 4 device files Hakala Linux - Software 1 04-01-2006 12:20 PM
LXer: EDGE Tech Corp Announces Portable Flash Drive With Muscle - the New 8GB DiskGO!(TM) Now Available; Swap and Go With This Secure Thumb-Sized Flash Drive LXer Syndicated Linux News 0 12-14-2005 02:16 AM
Having trouble with DSL File Management: USB flash drive files zubalove DamnSmallLinux 2 08-19-2005 09:01 PM
Flash drive write cache ilikejam Linux - Hardware 5 05-22-2004 11:07 AM
USB Flash drive will not let me write. sniperhf Linux - Hardware 1 12-05-2003 02:39 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware

All times are GMT -5. The time now is 07:12 AM.

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