Restoring full capacity of SATA disk on Linux with hdparm

For some reason some of my 2TB Hitachi SATA disks report 2000000000000 bytes instead of 2000396697600 2TB disk from all other manufacturer do. Even some Hitachi’s show 2000396697600 bytes.



This is what I got on dmesg for two seemingly identical Hitachi 7K2000 disks from same batch.

[ 11.736298] sd 1:0:0:0: [sdb] 3906250000 512-byte logical blocks: (2.00 TB/1.81 TiB)
[ 11.736715] sd 2:0:0:0: [sdc] 3907029168 512-byte logical blocks: (2.00 TB/1.81 TiB)

You can probably guess it – I was trying to replace failed half of RAID-1 mirror but failed because new disk reported lower capacity. No worries, this is easily fixable without reboot. At least as long as your BIOS doesn’t do DCO/HPA locking which will require on-the-fly power cycling disks to reset that flag.

root@foopc:~# hdparm -N /dev/sdb
/dev/sdb:
max sectors = 3906250000/3907029168, HPA is enabled

root@foopc:~# hdparm -N /dev/sdc
/dev/sdc:
max sectors = 3907029168/3907029168, HPA is disabled

root@foopc:~# hdparm -N p3907029168 /dev/sdb
/dev/sdb:
setting max visible sectors to 3907029168 (permanent)
max sectors = 3907029168/3907029168, HPA is disabled

root@foopc:~# hdparm -N /dev/sdb
/dev/sdb:
max sectors = 3907029168/3907029168, HPA is disabled

To force Linux to re-read new capacity info we take disk offline and then back online.

root@foopc:~# echo x > /sys/bus/scsi/devices/1:0:0:0/delete
... wait a bit here as disk will spin down on delete

root@foopc:~# echo "0 0 0" >/sys/class/scsi_host/host1/scan


Now you should have nice new capacity shown on dmesg

[ 897.847654] sd 1:0:0:0: [sdb] 3907029168 512-byte logical blocks: (2.00 TB/1.81 TiB)


Other useful commands:

hdparm --yes-i-know-what-i-am-doing --dco-restore /dev/sdb
- reset disk settings to factory defaults as there might be also other settings wrong than capacity.

hdparm -J 60 /dev/sdb
- turn off head parking on WD green disks (like WDIDLE3)

smartctl -l scterc,70,70 /dev/sdb
- enable 7s TLER (like WDTLER)

hdparm --user-master u --security-disable "3wareUserPassword               " /dev/sdb
- unlock ata password of disk that was previously used with 3ware controller


Comments

  1. Thank you! One improvement. It is better to scan full host (to catch all drives on the bus) like:

    > echo "- - -" >/sys/class/scsi_host/host1/scan

    ReplyDelete

Post a Comment

Got something to say?!