Code Gist: Verify Disk Zeroing

Two methods: xxd and cmp.

Check whether or not cat /dev/zero > /dev/sda; sync or dd if=/dev/zero of=/dev/sda status=progress worked. Zeroing was successful if nothing prints.

xxd /dev/sda | sed -e 's/\(.*:\ \)\([0-9a-fA-F]\{4\} [0-9a-fA-F]\{4\} [0-9a-fA-F]\{4\} [0-9a-fA-F]\{4\} [0-9a-fA-F]\{4\} [0-9a-fA-F]\{4\} [0-9a-fA-F]\{4\} [0-9a-fA-F]\{4\} \)\(.*\)/\2/' -e 's/ //g' -ne '/[1-9a-fA-F]/p'

Using cmp is probably faster. Returns True if successful.

file=/dev/sda; sz1=$((512 * $(blockdev --getsz $file))); sz2=$(cmp $file /dev/zero 2>&1 | grep -o [0-9]*, | tr -d ,); [[ sz1 -eq sz2 ]] && echo "True" || echo "False"