Skip to main content

Resetting a USB SSD For Optimal Performance

usb-logo.png

Pulling out an older SSD device from the shelf for re-use, I realize that because of the "weirdness" of SSD devices, I should reset the device beofre using it to refresh the NAND storage in it. As always, I want to do this from the Linux command line, so my first attempt was to search the man-page of smartctl for the string erase. As this yielded no results, it only took about 5 minutes from looking for a solution on the Internet to actually doing it. And this without using any LLM to do the job for me. And I even learned something new.

Trying the naive way

Searching for help on that topic quickly shows that hdparm has support for this use case. Studying the man page shows the functionality is in the --security-erase PWD command line flag. Trying this naively with a joke password yield this:

dzu@krikkit:~$ sudo hdparm --security-erase PASS /dev/sdf
security_password: "PASS"

/dev/sdf:
 Issuing SECURITY_ERASE command, password="PASS", user=user
SECURITY_ERASE: Input/output error
dzu@krikkit:~$ sudo hdparm -I /dev/sdf | grep -i frozen
        not	frozen

Ok, so something more complicated

Ok, so it seems to really use the functionality, we need to get the device into the not frozen state and this is done by actually setting a password. The man-page shows how to do this and so we use it to define our own password.

dzu@krikkit:~$ sudo hdparm --user-master u --security-set-pass reallyerase /dev/sdf
security_password: "reallyerase"

/dev/sdf:
 Issuing SECURITY_SET_PASS command, password="reallyerase", user=user, mode=high
dzu@krikkit:~$

We can check if we were successful by inspectin the output of -I (look for frozen):

dzu@krikkit:~$ sudo hdparm -I /dev/sdf

/dev/sdf:

ATA device, with non-removable media
        Model Number:       TS128GESD400K                           
        Serial Number:      20160323C86172063131
        Firmware Revision:  O1229A  
        Media Serial Num:   �
        Transport:          Serial, ATA8-AST, SATA 1.0a, SATA II Extensions, SATA Rev 2.5, SATA Rev 2.6, SATA Rev 3.0
Standards:
        Supported: 9 8 7 6 5 
        Likely used: 9
Configuration:
        Logical		max	current
        cylinders	16383	16383
        heads		16	16
        sectors/track	63	63
        --
        CHS current addressable sectors:    16514064
        LBA    user addressable sectors:   250069680
        LBA48  user addressable sectors:   250069680
        Logical  Sector size:                   512 bytes
        Physical Sector size:                   512 bytes
        Logical Sector-0 offset:                  0 bytes
        device size with M = 1024*1024:      122104 MBytes
        device size with M = 1000*1000:      128035 MBytes (128 GB)
        cache/buffer size  = unknown
        Form Factor: 2.5 inch
        Nominal Media Rotation Rate: Solid State Device
Capabilities:
        LBA, IORDY(can be disabled)
        Queue depth: 32
        Standby timer values: spec'd by Standard, no device specific minimum
        R/W multiple sector transfer: Max = 1	Current = 1
        Advanced power management level: disabled
        DMA: mdma0 mdma1 mdma2 udma0 udma1 udma2 udma3 udma4 udma5 *udma6 
             Cycle time: min=120ns recommended=120ns
        PIO: pio0 pio1 pio2 pio3 pio4 
             Cycle time: no flow control=120ns  IORDY flow control=120ns
Commands/features:
        Enabled	Supported:
           *	SMART feature set
           *	Security Mode feature set
           *	Power Management feature set
           *	Write cache
                Look-ahead
           *	Host Protected Area feature set
           *	WRITE_BUFFER command
           *	READ_BUFFER command
           *	NOP cmd
           *	DOWNLOAD_MICROCODE
                Advanced Power Management feature set
           *	SET_MAX security extension
           *	48-bit Address feature set
           *	Device Configuration Overlay feature set
           *	Mandatory FLUSH_CACHE
           *	FLUSH_CACHE_EXT
           *	SMART error logging
           *	SMART self-test
           *	General Purpose Logging feature set
           *	WRITE_{DMA|MULTIPLE}_FUA_EXT
           *	64-bit World wide name
           *	Gen1 signaling speed (1.5Gb/s)
           *	Gen2 signaling speed (3.0Gb/s)
           *	Gen3 signaling speed (6.0Gb/s)
           *	Native Command Queueing (NCQ)
           *	Host-initiated interface power management
           *	Phy event counters
           *	READ_LOG_DMA_EXT equivalent to READ_LOG_EXT
                DMA Setup Auto-Activate optimization
                Device-initiated interface power management
           *	Software settings preservation
           *	Device Sleep (DEVSLP)
           *	DOWNLOAD MICROCODE DMA command
           *	Data Set Management TRIM supported (limit 8 blocks)
Security: 
        Master password revision code = 65534
                supported
                enabled
        not	locked
        not	frozen
        not	expired: security count
                supported: enhanced erase
        Security level high
        2min for SECURITY ERASE UNIT. 2min for ENHANCED SECURITY ERASE UNIT.
Logical Unit WWN Device Identifier: 0000000000000000
        NAA		: 0
        IEEE OUI	: 000000
        Unique ID	: 000000000
Device Sleep:
        DEVSLP Exit Timeout (DETO): 30 ms (drive)
        Minimum DEVSLP Assertion Time (MDAT): 30 ms (drive)
Checksum: correct
dzu@krikkit:~$

As we see not frozen near the end of that output, we know the last command worked for us and we can now really erase the device. Let's time it to document the time it needs:

dzu@krikkit:~$ time sudo hdparm --user-master u --security-erase reallyerase /dev/sdf
security_password: "reallyerase"

/dev/sdf:
 Issuing SECURITY_ERASE command, password="reallyerase", user=user

real	0m8,784s
user	0m0,000s
sys	0m0,011s
dzu@krikkit:~$

I would say, 8 seconds is pretty fast. Let's again look at the output of -I:

dzu@krikkit:~$ sudo hdparm -I /dev/sdf

/dev/sdf:

ATA device, with non-removable media
        Model Number:       TS128GESD400K                           
        Serial Number:      20160323C86172063131
        Firmware Revision:  O1229A  
        Media Serial Num:   �
        Transport:          Serial, ATA8-AST, SATA 1.0a, SATA II Extensions, SATA Rev 2.5, SATA Rev 2.6, SATA Rev 3.0
Standards:
        Supported: 9 8 7 6 5 
        Likely used: 9
Configuration:
        Logical		max	current
        cylinders	16383	16383
        heads		16	16
        sectors/track	63	63
        --
        CHS current addressable sectors:    16514064
        LBA    user addressable sectors:   250069680
        LBA48  user addressable sectors:   250069680
        Logical  Sector size:                   512 bytes
        Physical Sector size:                   512 bytes
        Logical Sector-0 offset:                  0 bytes
        device size with M = 1024*1024:      122104 MBytes
        device size with M = 1000*1000:      128035 MBytes (128 GB)
        cache/buffer size  = unknown
        Form Factor: 2.5 inch
        Nominal Media Rotation Rate: Solid State Device
Capabilities:
        LBA, IORDY(can be disabled)
        Queue depth: 32
        Standby timer values: spec'd by Standard, no device specific minimum
        R/W multiple sector transfer: Max = 1	Current = 1
        Advanced power management level: disabled
        DMA: mdma0 mdma1 mdma2 udma0 udma1 udma2 udma3 udma4 udma5 *udma6 
             Cycle time: min=120ns recommended=120ns
        PIO: pio0 pio1 pio2 pio3 pio4 
             Cycle time: no flow control=120ns  IORDY flow control=120ns
Commands/features:
        Enabled	Supported:
           *	SMART feature set
                Security Mode feature set
           *	Power Management feature set
           *	Write cache
                Look-ahead
           *	Host Protected Area feature set
           *	WRITE_BUFFER command
           *	READ_BUFFER command
           *	NOP cmd
           *	DOWNLOAD_MICROCODE
                Advanced Power Management feature set
           *	SET_MAX security extension
           *	48-bit Address feature set
           *	Device Configuration Overlay feature set
           *	Mandatory FLUSH_CACHE
           *	FLUSH_CACHE_EXT
           *	SMART error logging
           *	SMART self-test
           *	General Purpose Logging feature set
           *	WRITE_{DMA|MULTIPLE}_FUA_EXT
           *	64-bit World wide name
           *	Gen1 signaling speed (1.5Gb/s)
           *	Gen2 signaling speed (3.0Gb/s)
           *	Gen3 signaling speed (6.0Gb/s)
           *	Native Command Queueing (NCQ)
           *	Host-initiated interface power management
           *	Phy event counters
           *	READ_LOG_DMA_EXT equivalent to READ_LOG_EXT
                DMA Setup Auto-Activate optimization
                Device-initiated interface power management
           *	Software settings preservation
           *	Device Sleep (DEVSLP)
           *	DOWNLOAD MICROCODE DMA command
           *	Data Set Management TRIM supported (limit 8 blocks)
Security: 
        Master password revision code = 65534
                supported
        not	enabled
        not	locked
        not	frozen
        not	expired: security count
                supported: enhanced erase
        2min for SECURITY ERASE UNIT. 2min for ENHANCED SECURITY ERASE UNIT.
Logical Unit WWN Device Identifier: 0000000000000000
        NAA		: 0
        IEEE OUI	: 000000
        Unique ID	: 000000000
Device Sleep:
        DEVSLP Exit Timeout (DETO): 30 ms (drive)
        Minimum DEVSLP Assertion Time (MDAT): 30 ms (drive)
Checksum: correct
dzu@krikkit:~$ 

Summary

In order to securely erase the device, we have to define a password first and then start the erase passing in the same password again. Seems awkward, but still doable.

Comments

Comments powered by Disqus