====== Disk or Flash Drive Testing and Preparation ======
===== Testing =====
* Testing best done with direct connection - USB connections are really slow and not fully functional (smart)
* Check for I/O errors in /var/log/messages
* Install 'smartmontools' package
* http://smartmontools.sourceforge.net/badblockhowto.html
* http://www.cyberciti.biz/tips/monitoring-hard-disk-health-with-smartd-under-linux-or-unix-operating-systems.html
* man smartctl for many options/disk/controller types
* Typically, you need to dismount the filesystems on the drives to be tested
==== SMART ====
Disks support smart?
sudo smartctl -i /dev/sdX
Show disk info:
sudo smartctl -a /dev/sdX
Enable smart:
sudo smartctl -s on -d ata /dev/sdX
Initiate quick health check:
sudo smartctl -d ata -H /dev/sdX
Initiate extended self test:
sudo smartctl -d ata -t long /dev/sdX
then
sudo smartctl -l selftest /dev/sdX
==== Badblocks ====
:!: Badblocks can be hazardous to your data. **Make a backup first!**
:!: Running ''badblocks'' on **SSDs** may **reduce lifespans**.
There are some valid circumstances where you have to use the '-f' switch to force the testing. Be careful when doing so to make sure you 'do no harm'.
=== Determine Optimal Block Size ===
tune2fs -l /dev/sdX1 | grep Block
=== Non-Destructive Test ===
Read/write test a disk/partition:
sudo badblocks -nvs /dev/sdX # entire disk
sudo badblocks -nvs /dev/sdX1 # partition only
=== Destructive Test ===
This is the best test and uses 4096K blocks for improved speed and saves a log file of bad blocks (add f to -wvs to force if drive reports in use):
sudo badblocks -wvs -b 4096 /dev/sdX | tee badblocks.txt
===== Preparation =====
==== Wipe a Disk ====
Write zeros to disk (best for making compressible images) (also wipes out MBR):
sudo sh -c "cat /dev/zero > /dev/sdX"
==== Partition a Disk ====
Show disks:
sudo fdisk -l
Partition a drive:
sudo fdisk /dev/sdX
==== Write a DOS MBR ====
Write a DOS MBR (like fdisk /MBR) (may need --force)
sudo install-mbr /dev/sdX -v --interrupt n --partition D --timeout 0
Note: the syslinux package also includes a mbr.bin file:
sudo dd if=/usr/lib/syslinux/mbr.bin of=/dev/sdX
==== Make a Filesystem ====
Linux EXT3:
sudo mkfs.ext3 /dev/sdX1
FAT32 (Flash is normally FAT16 or FAT32):
Partition the flash device as 'W95 FAT32' and set the 'bootable' flag if desired.
sudo mkdosfs -F 32 /dev/sdX1
or
sudo mkfs.vfat -F 32 /dev/sdX1