Bootable Linux USB stick: Difference between revisions

Jump to navigation Jump to search
No edit summary
Line 117: Line 117:


=== generating images and copies of the stick ===
=== generating images and copies of the stick ===
Fill empty part of all partitions on the stick with “zeros”: for each partition, do
dd if=/dev/zero of=/mountpoint/delete.me bs=65536  # this will stop when filesystem full
rm /mountpoint/delete.me
This also seems to result in faster writes afterwards i.e. it is a way to restore the write speed of a USB stick.


Save a compressed disk image - we use the parallel gzip program called pigz:
Save a compressed disk image - we use the parallel gzip program called pigz:
  dd if=/dev/sd? | pigz -c usbstick.img.gz
  dd if=/dev/sd? bs=4096 | pigz -c usbstick.img.gz
(time: ~180 secs speed: ~175MB/s, size of image: 1.8 GB)
(time: ~180 secs speed: ~175MB/s, size of image: 1.8 GB)
write compressed image back to a stick:
write compressed image back to a stick:
  unpigz -c usbstick.img.gz | dd of=/dev/sd? bs=4096
  unpigz -c usbstick.img.gz | dd of=/dev/sd? bs=4096
(speed should be >100MB/s)
(speed should be >100MB/s)
=== for techies: taking care of the stick ===
The following is about performance and durability of the USB stick, and reading it is not required for the functionality described above. If you don't know what TRIM is and how it relates to flash media, this section is probably not for you.
To fill empty part of all partitions on the stick with “zeros”: for each partition, do (as root)
dd if=/dev/zero of=/mountpoint_of_partition/delete.me bs=10M  # this will stop when filesystem is full
rm /mountpoint_of_partition/delete.me
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 bridge and controller do not pass the ATA trim command to the device. The workaround is to use the <code>wiper.sh</code> script which is part of the <code>hdparm</code> package. This works beautifully, as verified with the [https://sites.google.com/site/lightrush/random-1/checkiftrimonext4isenabledandworking test_trim.sh] script.
1,328

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu