LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Hardware (https://www.linuxquestions.org/questions/linux-hardware-18/)
-   -   How to write files immediately to flash drive. (https://www.linuxquestions.org/questions/linux-hardware-18/how-to-write-files-immediately-to-flash-drive-489248/)

adds2one 10-04-2006 12:40 AM

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?

pda_h4x0r 10-04-2006 01:08 AM

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

adds2one 10-05-2006 12:11 AM

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.

Wim Sturkenboom 10-05-2006 01:21 AM

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.

adds2one 10-05-2006 04:40 PM

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.

Electro 10-05-2006 05:56 PM

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.

pda_h4x0r 10-05-2006 11:34 PM

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...

Wim Sturkenboom 10-06-2006 12:13 AM

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.


All times are GMT -5. The time now is 06:45 PM.