I've exchanged emails with the author of ddrescue, Antonio Diaz, and he told me that the correct parameter to use with an "advanced format" drive (i.e., a drive with 4096-byte physical sectors, but 512-byte "logical sectors") is:
-b4096
If you wanted it to read just one 4096-byte sector at a time (slow!) then you would also specify:
-c1
Antonio is not active on StackExchange, but he supports ddrescue via this email mailing list:
https://www.mail-archive.com/bug-ddrescue@gnu.org/
If you send your email to bug-ddrescue@gnu.org then your email will appear on that summary page, as will his answer, in nicely organized form (but without your email address shown, of course). Additionally, you may search on that page to try to find previous discussions of your issue or question, before bothering Antonio. (He is a very busy man, so please don't waste his time!)
The reason that your ddrescue logfile contains a 512-byte "bad" area is that you initially ran ddrescue with the default sector size of 512 bytes. That's not disastrous, but if ddrescue thinks the drive has 512 byte sectors, and a read is issued that returns 0 bytes of data due to a read error, then ddrescue assumes that only the first of 512 bytes are unreadable, and makes no assumption about the rest. So only 512 bytes is marked as bad in the logfile.
man blockdev
--setbsz bytes
Set blocksize. Note that the block size is specific to the cur‐
rent file descriptor opening the block device, so the change of
block size only persists for as long as blockdev has the device
open, and is lost once blockdev exits.
In block/ioctl.c:
case BLKBSZGET: /* get block device soft block size (cf. BLKSSZGET) */
return put_int(arg, block_size(bdev));
case BLKSSZGET: /* get block device logical block size */
return put_int(arg, bdev_logical_block_size(bdev));
case BLKPBSZGET: /* get block device physical block size */
return put_uint(arg, bdev_physical_block_size(bdev));
So BSZ reported by blockdev
is neither logical nor physical block size. It is the "soft block size".
Looking at this code, the part about soft block size being specific to the file descriptor does not appear to make sense. Nor does wanting to set that with blockdev
, given that no other option is documented in terms of blocks (only fixed-size 512 byte sectors).
In my own tests, what actually happens is that BSZ is preserved for as long as any process holds the block device open. It looks like it gets reset on the last close().
Parted got confused by this too some years ago
belay that. BLKBSZGET is the kernel's chosen block size it will use
to access the device (for normal disks turns out this is 1k, for
ata_ram this is 4k), which is not the underlying disk's logical block
size. :-( So we will likely need another ioctl() to get the right
value from the kernel, and BLKSSZGET may wind up being the disks's
logical block size, while a new ioctl() exports the disk's physical
sector size. ugh.
Another quirk:
On Wed, Apr 09, 2003 at 06:53:17PM +0200, Rob van Nieuwkerk wrote:
I get 4096 with BLKBSZGET on several unmounted partitions on my system
(RH 2.4.18-27.7.x kernel). Some give 1024 .. Maybe it is because I
had them mounted first and unmounted them for the test ?
That would be the most likely answer. When you unmount, I don't believe the
filesystem bothers to set_blocksize(get_hardsect_size(dev)).
Best Answer
512 byte is not really the default sector size. It depends on your hardware.
You can display what physical/logical sector sizes your disk reports via the
/sys
pseudo filesystem, for instance:What is the difference between those two values?
physical_block_size
is the minimal size of a block the drive is able to write in an atomic operation.logical_block_size
is the smallest size the drive is able to write (cf. the linux kernel documentation).Thus, if you have a 4k drive it makes sense that your storage stack (filesystem etc.) uses something equal or greater than the physical sector size.
Those values are also displayed in recent versions of
fdisk
, for instance:On current linux distributions, programs (that should care about the optimal sector size) like
mkfs.xfs
will pick the optimal sector size by default (e.g. 4096 bytes).But you can also explicitly specify it via an option, for instance:
Or:
In any case, most
mkfs
variants will also display the used block size during execution.For an existing filesystem the block size can be determined with a command like:
Or:
Or:
When creating the filesystem on a partition, another thing to check then is if the partition start address is actually aligned to the physical block size. For example, look at the
fdisk -l
output, convert the start addresses into bytes, divide them by the physical block size - the reminder must be zero if the partitions are aligned.