{"id":236,"date":"2024-10-28T18:03:21","date_gmt":"2024-10-29T01:03:21","guid":{"rendered":"https:\/\/pronoiac.org\/misc\/?p=236"},"modified":"2024-10-28T18:05:11","modified_gmt":"2024-10-29T01:05:11","slug":"testing-new-drives","status":"publish","type":"post","link":"https:\/\/pronoiac.org\/misc\/2024\/10\/testing-new-drives\/","title":{"rendered":"Testing new drives"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">about<\/h2>\n\n\n\n<p>I bought some used hard drives, from a vendor that was new to me. I was careful with burn-in and testing, as they were being shipped and deployed remotely. I checked for defects and verified capacity. Testing quickly was important, so I could return something that wasn&#8217;t working, and get a replacement.<\/p>\n\n\n\n<!--more-->\n\n\n\n<h2 class=\"wp-block-heading\">checking for defects<\/h2>\n\n\n\n<p>Most drives have <a href=\"https:\/\/en.wikipedia.org\/wiki\/Self-Monitoring,_Analysis_and_Reporting_Technology\">SMART diagnostics<\/a> built-in. It&#8217;s a good first pass, requiring little CPU or I\/O from the system.<\/p>\n\n\n\n<p>Using an external USB enclosure, and a Linux system, I ran <code>smartctl<\/code> to test them. I ran <code>smartctl --scan-open<\/code> to detect the device and type. Of the SMART tests:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>conveyance<\/code> wasn&#8217;t available.<\/li>\n\n\n\n<li><code>short<\/code> was quick, a few minutes.<\/li>\n\n\n\n<li><code>long<\/code> took around 10 hours.<\/li>\n<\/ul>\n\n\n\n<p>I can&#8217;t find my references for parsing the results; perhaps refer to <a href=\"https:\/\/en.wikipedia.org\/wiki\/Self-Monitoring,_Analysis_and_Reporting_Technology\">the Wikipedia page<\/a>.<\/p>\n\n\n\n<p>Of the three drives, one wasn&#8217;t recognized. I plugged it in internally; it was recognized, though it yielded errors in the system logs, and <code>smartctl<\/code> was unable to start any tests. I returned this one drive for replacement, without issue.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">verifying capacity<\/h2>\n\n\n\n<p>Or, Checking for counterfeits, bootlegs, and fakes<\/p>\n\n\n\n<p>An issue mostly seen with flash drives: scammy, dodgy firmware lets it <em>claim<\/em> to have a multiple of its real capacity. If you try writing beyond its real capacity, it could:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>quietly discard the data<\/li>\n\n\n\n<li>quietly loop back and overwrite earlier data<\/li>\n<\/ul>\n\n\n\n<p>badblocks is a classic tool for testing drives &#8211; however, it was first built for floppy disks. For the nondestructive mode, it would notice the first one (discarding data) but not the second (wrap around to earlier data). The <a href=\"https:\/\/wiki.archlinux.org\/title\/badblocks\">Arch Linux wiki page for badblocks<\/a> has a suggestion about using a crypto layer above the device.<\/p>\n\n\n\n<p>I&#8217;m largely working from a Synology NAS. It lacks <code>cryptsetup<\/code>, and I&#8217;m not going to investigate how to install it, but the idea is sound:<\/p>\n\n\n\n<p>Using an encryption key, we&#8217;ll fill the drive with encrypted zeroes. This would be ordering-sensitive &#8211; one can&#8217;t start decrypting from the middle. Then we&#8217;ll decrypt, starting from the beginning, and count how many zeroes we get back from the drive.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">About encryption mode<\/h3>\n\n\n\n<p>(Avoiding <a href=\"https:\/\/words.filippo.io\/the-ecb-penguin\/\">ECB mode<\/a>.)<\/p>\n\n\n\n<p><a href=\"https:\/\/en.wikipedia.org\/wiki\/Block_cipher_mode_of_operation#Cipher_block_chaining_(CBC)\">CBC mode<\/a><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>&#8220;In CBC mode, each block of plaintext is XORed with the previous ciphertext block before being encrypted. This way, each ciphertext block depends on all plaintext blocks processed up to that point.&#8221;<\/p>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\">Writing encrypted zeroes<\/h3>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>Note: this can destroy any data on a drive, so check and double-check the device, <code>sdq<\/code> on mine. If it breaks, you keep both pieces.<\/p>\n<\/blockquote>\n\n\n\n<p>This quick-and-dirty attempt worked quickly enough on my Synology NAS:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>date\n(for i in $(seq 800); do \n    cat \/dev\/zero | head -c 10000000000\n    &gt;&amp;2 printf \".\"\n    done) | \\\n  openssl aes256 -pass \"pass:testing\" &gt; \\\n  \/dev\/sdq\ndate<\/code><\/pre>\n\n\n\n<p>That writes 800 x 10GiB chunks, for a total of 8TiB. It prints &#8220;.&#8221; every chunk, about one a minute.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Verifying encrypted zeroes<\/h3>\n\n\n\n<p>This doesn&#8217;t print progress information:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># cat \/dev\/sdq | \\\n  openssl aes256 -d -pass \"pass:testing\" | \\\n  cmp - \/dev\/zero<\/code><\/pre>\n\n\n\n<p>For my 8TB drive, the output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>- \/dev\/zero differ: char 8000000000001, line 1<\/code><\/pre>\n\n\n\n<p>There&#8217;s some difference between that and 8TB, due to base-10 terabytes vs base-2 tebibytes, but this ruled out that it was really a 1TB drive, handling my concern.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Side notes<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Performance<\/h4>\n\n\n\n<p>My first attempt at reading zeroes involved <code>xxd -a<\/code>, which would essentially hexdump one line of zeroes, and skip other all-zero rows. I estimated the rate as under 1\/10th the writing speed.<\/p>\n\n\n\n<p>Hardware acceleration for aes 256 is common, along with Linux kernel support; I don&#8217;t think this method takes advantage. Adding <code>-evp<\/code> might do the trick though.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">why not use <code>pv<\/code> on the Synology?<\/h4>\n\n\n\n<p>I would have <em>loved<\/em> to use <a href=\"https:\/\/www.ivarch.com\/programs\/pv.shtml\">pv &#8211; pipe viewer<\/a> &#8211; for a handy progress meter and estimate for how long it would take, but it wasn&#8217;t readily available for my NAS.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Raspberry Pi notes<\/h4>\n\n\n\n<p>Side note: I tried this on my Raspberry Pi 4. I was able to use <code>pv<\/code> here for a nifty progress meter, get an ETA, etc. However, it ran at something like 1\/4 the speed &#8211; unoptimized openssl? &#8211; so, non-starter. <code>openssl<\/code> required <code>-md -md5<\/code> to accept the password; that&#8217;s deprecated. For what I&#8217;m doing, I didn&#8217;t have to worry about zeroes falling into the wrong hands.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Other software for this<\/h2>\n\n\n\n<p>I didn&#8217;t use these, but they&#8217;re likely better-put-together and more usable than my quick draft above. \ud83d\ude42<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>&#8220;F3 stands for f, or Fight Fake Flash.&#8221; <a href=\"https:\/\/github.com\/AltraMayor\/f3\">Github repo<\/a>, <a href=\"https:\/\/fight-flash-fraud.readthedocs.io\/en\/stable\/\">docs<\/a> &#8211; available on several platforms.<\/li>\n\n\n\n<li>h2testw &#8211; from 2008, Windows only, <a href=\"https:\/\/www.heise.de\/download\/product\/h2testw-50539\">download page is in German<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>about I bought some used hard drives, from a vendor that was new to me. I was careful with burn-in and testing, as they were being shipped and deployed remotely. I checked for defects and verified capacity. Testing quickly was important, so I could return something that wasn&#8217;t working, and get a replacement.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-236","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/pronoiac.org\/misc\/wp-json\/wp\/v2\/posts\/236"}],"collection":[{"href":"https:\/\/pronoiac.org\/misc\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pronoiac.org\/misc\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pronoiac.org\/misc\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pronoiac.org\/misc\/wp-json\/wp\/v2\/comments?post=236"}],"version-history":[{"count":7,"href":"https:\/\/pronoiac.org\/misc\/wp-json\/wp\/v2\/posts\/236\/revisions"}],"predecessor-version":[{"id":243,"href":"https:\/\/pronoiac.org\/misc\/wp-json\/wp\/v2\/posts\/236\/revisions\/243"}],"wp:attachment":[{"href":"https:\/\/pronoiac.org\/misc\/wp-json\/wp\/v2\/media?parent=236"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pronoiac.org\/misc\/wp-json\/wp\/v2\/categories?post=236"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pronoiac.org\/misc\/wp-json\/wp\/v2\/tags?post=236"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}