[SMART] Preventing usage of some bad sectors

Is it is a hdd and not an sdd it is possible with hdparm.

I don’t know the exact command from the top of my head, will come back to it in a moment (unless you find it sooner :slight_smile: )

I posted the model in Reply #14 :wink:

Ahh oke

Oke seems hdparm low level format cam be done on both SDD and HDD, but… it is completely at your own risk.

start with installing hdparm making sure the disk is NOT mounted.
next

sudo hdparm -I /dev/sdX

to check if the disk is frozen or not. If so you need to unfreeze it.

next

sudo hdparm --security-set-pass NULL /dev/sdX

then

sudo time hdparm --user-master u --security-erase NULL /dev/sdX

Finally remove the password,

hdparm --security-unlock NULL /dev/sdX

check if all is good

sudo hdparm -I /dev/sdX

done

1 Like

Ahhh i remember reading those commands somewhere indeed, didn’t know they were for low-level format :+1:
I will try when the current offline test has ended…
In worst case that external HD will become useless, which won’t matter in current state :wink:

I seem to get some errors:

  • This one is from the erase command:
    SG_IO: bad/missing sense data, sb[]: 70 00 05 00 00 00 00 0a 00 00 00 00 24 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

  • These are from the unlock command although it works successfully as can be seen in the output of the info command:

    • The running kernel lacks CONFIG_IDE_TASK_IOCTL support for this device.
    • SECURITY_UNLOCK: Invalid argument
      (This last one does not happen every time when you run the command on it’s own in terminal)
  • I know which command gave what error because i saw them when using the commands on their own in terminal :wink:


low-level-format-drive
#!/bin/env bash
# ~/.local/bin/low-level-format-drive
#
function help () {
	printf "%b\n" \
		"\nUsage: ${0##*/} <drive> [<u|m>] [<password>]" \
		"Where:" \
		"\t<drive>\t= drive name with or without '/dev/' prepended." \
		"\t<u|m>\t= Selection of user (default) or master password." \
		"\t<password> = Password to use, defaults to '0123456789'"
	exit 1
}

if test $(id -u) -ne 0; then
	printf "%s\n" "Need root !"
	help
fi

drv="/dev/${1##*/}";
drvpass="${2:-u}"
pass="${3:-0123456789}"
# pass="${3:-NULL}"
# printf "%s\n" "$drv" "$drvpass" "$pass"

if test ! -b "$drv"; then
	printf "%s\n" "You need to provide a valid drive path !"
	help
elif test "$drvpass" != "u" -a "$drvpass" != "m"; then
	printf "%s\n" "Invalid password type selected !"
	help
fi

exec 2>&1

hdparm --user-master "$drvpass" --security-set-pass "$pass" "$drv"
time hdparm --user-master "$drvpass" --security-erase-enhanced "$pass" "$drv"
hdparm --user-master "$drvpass" --security-unlock "$pass" "$drv"
hdparm --user-master "$drvpass" --security-disable "$pass" "$drv"
hdparm -I "$drv"
sudo low-level-format-drive sde | xclip
security_password: "0123456789"

/dev/sde:
 Issuing SECURITY_SET_PASS command, password="0123456789", user=user, mode=high
SG_IO: bad/missing sense data, sb[]:  70 00 05 00 00 00 00 0a 00 00 00 00 24 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
security_password: "0123456789"

/dev/sde:
 Issuing SECURITY_ERASE command, password="0123456789", user=user

real	0m30.087s
user	0m0.000s
sys	0m0.002s
The running kernel lacks CONFIG_IDE_TASK_IOCTL support for this device.
SECURITY_UNLOCK: Invalid argument
security_password: "0123456789"

/dev/sde:
 Issuing SECURITY_UNLOCK command, password="0123456789", user=user
security_password: "0123456789"

/dev/sde:
 Issuing SECURITY_DISABLE command, password="0123456789", user=user

/dev/sde:

ATA device, with non-removable media
	Model Number:       TOSHIBA MQ01ABB200                      
	Serial Number:      <filtered out by me>
	Firmware Revision:  AY000U  
	Transport:          Serial, ATA8-AST, SATA 1.0a, SATA II Extensions, SATA Rev 2.5, SATA Rev 2.6
Standards:
	Supported: 8 7 6 5 
	Likely used: 8
Configuration:
	Logical		max	current
	cylinders	16383	16383
	heads		16	16
	sectors/track	63	63
	--
	CHS current addressable sectors:    16514064
	LBA    user addressable sectors:   268435455
	LBA48  user addressable sectors:  3907029168
	Logical  Sector size:                   512 bytes
	Physical Sector size:                  4096 bytes
	Logical Sector-0 offset:                  0 bytes
	device size with M = 1024*1024:     1907729 MBytes
	device size with M = 1000*1000:     2000398 MBytes (2000 GB)
	cache/buffer size  = 8192 KBytes
	Form Factor: 2.5 inch
	Nominal Media Rotation Rate: 5400
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 = 16	Current = 16
	Advanced power management level: 128
	DMA: sdma0 sdma1 sdma2 mdma0 mdma1 mdma2 udma0 udma1 udma2 udma3 udma4 *udma5 
	     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
	   *	IDLE_IMMEDIATE with UNLOAD
	   *	WRITE_UNCORRECTABLE_EXT command
	   *	{READ,WRITE}_DMA_EXT_GPL commands
	   *	Segmented DOWNLOAD_MICROCODE
	   *	Gen1 signaling speed (1.5Gb/s)
	   *	Gen2 signaling speed (3.0Gb/s)
	   *	Native Command Queueing (NCQ)
	   *	Host-initiated interface power management
	   *	Phy event counters
	   *	Idle-Unload when NCQ is active
	    	DMA Setup Auto-Activate optimization
	    	Device-initiated interface power management
	   *	Software settings preservation
	   *	SMART Command Transport (SCT) feature set
	   *	SCT Write Same (AC2)
	   *	SCT Error Recovery Control (AC3)
	   *	SCT Features Control (AC4)
	   *	SCT Data Tables (AC5)
Security: 
	Master password revision code = 4
		supported
	not	enabled
	not	locked
	not	frozen
	not	expired: security count
		supported: enhanced erase
	434min for SECURITY ERASE UNIT. 434min for ENHANCED SECURITY ERASE UNIT.
Logical Unit WWN Device Identifier: <filtered out by me>
	NAA		: 5
	IEEE OUI	: 000039
	Unique ID	: <filtered out by me>
Checksum: correct