Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

If you wirte to USB sticks / SD cards you should use (a multiple of) of the erase block size in oder not wear out the flash. I don't know what somewhat current sizes are. But 1M sounds likely to be a reasonable multiple.

For USB also make sure to power it off before removing otherwise you might lose data. Eg. by

   udisksctl power-off -b /dev/sdX


Huh. I always run `sync` (twice, because Tradition™) before yanking a USB stick, and I've never noticed issues; any idea if powering off is better?


Sync just syncs but it doesn't prevent anything from starting to write while you go to pull it.

"udisksctl power-off" checks nothing is using the drive, commits buffers to storage, deconfigures the drive, and powers it off. Unfortunately it may kill more devices than you want in some scenarios due to the way killing the port works. Also for normal USB drives I don't think® poweroff is any different than an immediate physical pull post unmounting. The upside is it'll be completely disabled the instance the command completes, i.e. it can't even be written to raw as it is no longer powered even though plugged in. Not sure how helpful that is in reality though.

I usually just umount the drive which syncs and prevents further writes (well, to the mount at least) but doesn't try to kill it for me. Most likely sync is "good enough" for the vast majority of use though.


Wait, what about eject?


Eject is supposed to be like the udisksctl option but I've had it act wonky on me depending on the type of drive being ejected so I've avoided it myself. If it works though it shouldn't be any different.


I learned in the 1980s that it's

    sync; sync; sync
I feel more comfortable with just unmounting and powering off nowadays. But I have no hard evidence.

Hardly ever user more than one USB drive same time, so not sure whether there could be side effects with powering off one of them. Well, USB being USB, nothing would surprise me too much.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: