User:Tingo/setblocksize

From NDWiki
Jump to navigation Jump to search

setblocksize is created by Michael Bauerle. It is a tool to reformat a SCSI disk with new block size.

setblocksize requires GNU/Linux with sg driver installed - connect the disk to a machine running this OS to reformat it.

Since my experiments with sg_format (see the sg3_utils page) failed, I decided I had nothing to loose by testing this tool as well.

Machine info

I used an old machine I had lying, installed an Adaptec AVA-2904 SCSI card into it, a hard drive and installed Fedora 24 serve on it.

[tingo@kg-htpc ~]$ cat /etc/fedora-release
Fedora release 24 (Twenty Four)
[tingo@kg-htpc ~]$ uname -a
Linux kg-htpc.kg4.no 4.5.5-300.fc24.i686 #1 SMP Thu May 19 13:42:13 UTC 2016 i686 i686 i386 GNU/Linux

Drive info

The drive is the same old Seagate ST31200N that I managed to "brick" with sg_format.

[tingo@kg-htpc ~]$ dmesg | grep sd
[...]
[   19.581428] sd 2:0:0:0: Attached scsi generic sg1 type 0
[   19.599840] sd 2:0:0:0: [sdb] Read Capacity(10) failed: Result: hostbyte=DID_OK driverbyte=DRIVER_SENSE
[   19.599851] sd 2:0:0:0: [sdb] Sense Key : Medium Error [current] 
[   19.599858] sd 2:0:0:0: [sdb] Add. Sense: Medium format corrupted
[   19.602945] sd 2:0:0:0: [sdb] Write Protect is off
[   19.602955] sd 2:0:0:0: [sdb] Mode Sense: 9f 00 00 08
[   19.606941] sd 2:0:0:0: [sdb] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
[   19.626816] sd 2:0:0:0: [sdb] Read Capacity(10) failed: Result: hostbyte=DID_OK driverbyte=DRIVER_SENSE
[   19.626828] sd 2:0:0:0: [sdb] Sense Key : Medium Error [current] 
[   19.626835] sd 2:0:0:0: [sdb] Add. Sense: Medium format corrupted
[   19.635282] sd 2:0:0:0: [sdb] Attached SCSI disk

I edited out the info about sda (the os drive) since it is not relevant here

Compiling setblocksize

I had to install both kernel-headers and gcc in F24 (Fedora 24) before I could compile the program. Commands:

[tingo@kg-htpc setblocksize]$ sudo dnf install kernel-headers
[tingo@kg-htpc setblocksize]$ sudo dnf install gcc

after that it was a simple make command to get a executable program

[tingo@kg-htpc setblocksize]$ make all

I tested that the program worked

[tingo@kg-htpc setblocksize]$ ./setblocksize

setblocksize V0.2

Checking parameters ...
   Parameter error!
   Usage: 'setblocksize [-b<Blocksize in Byte>] [-t<Timeout in Minutes>] <sg_device>'

it worked so far.

Test if setblocksize works on the drive

The drive is already "bricked" so it can't be worse.

[tingo@kg-htpc ~]$ sudo work/setblocksize/setblocksize -b1024 /dev/sg1

setblocksize V0.2

Checking parameters ...
   Blocksize specified.
   Done.
New blocksize: 1024 Bytes
Format timeout: 120 minutes
Open device file ...
   Done.
Prepare command ...
   Done.
Send INQUIRY command ...
   Done.
Check status ...
   Command successful.
Check for LUN ...
   LUN present.

===============================================================================
SCSI ID     : 0
LUN         : 0
Connected to: Host2 / Channel0
Manufacturer: SEAGATE 
Model       : ST31200N        
Device type : Disk
===============================================================================
Do you really want to reformat this device [y/n]? y
Prepare command ...
   Done.
Send MODE SELECT command ...
   Done.
Check status ...
   Command successful.
Prepare command ...
   Done.
Send FORMAT UNIT command ...
   *** Please wait - Do not manually interrupt or power down! ***

(the LED on the drive lights up, now I have to wait)

   Done.
Check status ... 
   Command successful.
Close device file ...
   Done.

Exiting ...

The process took about 20 minutes on this drive.

check the result

I installed sg3_utils on the Fedora machine to figure out if setblocksize had done its job.

sg_format

[tingo@kg-htpc ~]$ sudo sg_format /dev/sg1
    SEAGATE   ST31200N          8008   peripheral_type: disk [0x0]
Mode Sense (block descriptor) data, prior to changes:
  Number of blocks=0 [0x0]
  Block size=1024 [0x400]
Read Capacity (10) results:
   Number of logical blocks=1074591
   Logical block size=1024 bytes
No changes made. To format use '--format'. To resize use '--resize'

So sg_format thinks the drive has 1024 byte blocks - good.

sg_readcap

[tingo@kg-htpc ~]$ sudo sg_readcap /dev/sg1
Read Capacity results:
   Last logical block address=1074590 (0x10659e), Number of blocks=1074591
   Logical block length=1024 bytes
Hence:
   Device size: 1100381184 bytes, 1049.4 MiB, 1.10 GB

sg_readcap also agrees with sg_format.

So it looks like setblocksize really managed to change the drive.

fdisk

fdisk -l output was requested. Here it is:

[tingo@kg-htpc ~]$ sudo fdisk -l /dev/sdb
Disk /dev/sdb: 1 GiB, 1100381184 bytes, 1074591 sectors
Units: sectors of 1 * 1024 = 1024 bytes
Sector size (logical/physical): 1024 bytes / 1024 bytes
I/O size (minimum/optimal): 1024 bytes / 1024 bytes

Another vote for 1024 byte blocks (or "sectors").

History

2016-09-07: I did 'fdisk -l' on the drive, and documented the output.
2016-09-06: initial testing with setblocksize.