Bootable Linux USB stick: Difference between revisions

No edit summary
Line 143: Line 143:
This is sensible to do after deleting large amounts of data from the USB stick, and before saving and compressing an image of it. It also seems to result in faster writes afterwards i.e. it may be a way to restore the write speed of the stick.  
This is sensible to do after deleting large amounts of data from the USB stick, and before saving and compressing an image of it. It also seems to result in faster writes afterwards i.e. it may be a way to restore the write speed of the stick.  


A better method that does not wear the stick (flash media support a limited number of writes!) is to use TRIM. The SANdisk Extreme supports TRIM, as <code>hdparm -I</code> shows. However, neither the <code>fstrim</code> command nor the <code>discard</code> mount option work for USB sticks (at least not the ones that I tested), presumably because the usb-storage kernel module does not pass the ATA trim command through the USB bridge and controller to the device.  
<code>hdparm</code>'s (ENHANCED) SECURITY ERASE initializes the whole stick in 12.5 seconds - I checked the result.


The workaround I found is to use the <code>wiper.sh</code> script which is part of the <code>hdparm</code> package - this uses <code>hdparm</code> directly. For me, this seems to work, as verified with the [https://sites.google.com/site/lightrush/random-1/checkiftrimonext4isenabledandworking test_trim.sh] script. Use it on your own risk!
All other methods, like the <code>fstrim</code> command nor the <code>discard</code> mount option work for USB sticks, presumably because the usb-storage kernel module does not pass the ATA trim command through the USB bridge and controller to the device. The same goes for [http://unix.stackexchange.com/questions/97143/utility-to-trim-unallocated-space-on-drive <code>blkdiscard</code>]. The <code>wiper.sh</code> script (which is part of <code>hdparm</code>) gives no error message, but does not reproducibly fill the empty space of the filesystem with zeroes (it sometimes does).
 
For initializing the whole stick or a specific partition, in principle [http://unix.stackexchange.com/questions/97143/utility-to-trim-unallocated-space-on-drive <code>blkdiscard</code>] may work - but it gave me an error message (seems also to be using usb-storage).
 
However, <code>hdparm</code>'s (ENHANCED) SECURITY ERASE initializes the whole stick - I checked the result.
1,330

edits