# changed files in usb flash drives save only if... [Solved]

## ultraincognito

Hi all.

I have a trouble with usb flash drives. Please help me solve it.

If I unmount my flash drive before ejecting then all good.

# mount /dev/sda /mnt/tmp/

# ls /mnt/tmp/

2.txt

# rm /mnt/tmp/2.txt 

# umount /dev/sda 

# # device ejecting

# # device inserting

# mount /dev/sda /mnt/tmp/

# ls /mnt/tmp/

#

But if I don't do the unmounting before the ejecting then the change doesn't save.

# mount /dev/sda /mnt/tmp/

# ls /mnt/tmp/

2.txt

# rm /mnt/tmp/2.txt 

# # device ejecting

# umount /dev/sda

# # device inserting

# mount /dev/sda /mnt/tmp/

# ls /mnt/tmp/

2.txtLast edited by ultraincognito on Fri Apr 13, 2012 8:51 am; edited 1 time in total

----------

## ultraincognito

I found the solution. It's the 'sync' option for the mounting:

```
# mount /dev/sda /mnt/tmp -o sync
```

My problem is solved already.

I will not delete this topic, ok?

----------

## gorkypl

Do not do it! 

Mounting flash drive with '-sync' can kill it after copying several dozen of files.

All drives must be unmounted before ejecting, just do it. If you have no privileges to umount a flash drive, just execute 'sync' before plugging it off.

----------

## ultraincognito

But how does it work in the Windows? If I unplug the usb flash drive without an previous unmount, the files saves.

----------

## Ant P.

Windows disables write caching for removable drives, which is the same thing as -o sync.

----------

## gorkypl

AFAIK it is not true. Up to my knowledge Windows synces drive just after the file is copied, and just then shows that the copy process is over.

On contrary, '-o sync' implies that the FAT table on pendrive is updated after every chunk of file is written, which may be as often as size_of_file/512. As a result the memory cells in FAT region can be destroyed very quickly.

The 'flush' mount option may come handy, because it probably just mimic Windows behaviour. Anyway, I just prefer to sync before plugging the drive out.

----------

## ultraincognito

Understood, the 'sync' option is bad for flash drives. The 'flush' option is that I need. Thank you.

----------

