create empty img with dd so that it its sectors are of 4096bytes rather than 512

It's not possible to do it the way you describe. Sector size is a block device property which files don't inherently have. A file is just a sequence of a certain number of bytes, how those are stored is an implementation detail...

So if you want a specific sector size, you need a block device. And Linux offers loop devices just for this purpose, so use losetup to create a file-backed virtual block device with a certain sector size.

Test file:

# dd if=/dev/zero of=empty4k.img bs=4096 count=8192

Regular loop device:

# losetup --find --show empty4k.img 
/dev/loop0
# fdisk -l /dev/loop0
Disk /dev/loop0: 32 MiB, 33554432 bytes, 65536 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

4096-byte sectors loop device:

# losetup --find --show --sector-size=4096 empty4k.img 
/dev/loop1
# fdisk -l /dev/loop1
Disk /dev/loop1: 32 MiB, 33554432 bytes, 8192 sectors
Units: sectors of 1 * 4096 = 4096 bytes
Sector size (logical/physical): 4096 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

In both cases, the file is completely identical, sector size property is provided by the block loop device layer.


The bs given to dd just tells how large the buffer should be during creating the file. In the end, the file consists of nothing but zero-bytes, there is no information about alignment.

You have to use the specific parameter to fdisk, which is -b, as per the man-page of fdisk(8):

  -b, --sector-size sectorsize
          Specify  the  sector  size  of  the  disk.   Valid values are 512,    1024, 2048, and 4096.  (Recent kernels know the sector size.  Use this option only on old kernels or to override the kernel's
          ideas.)  Since util-linux-2.17, fdisk differentiates between logical and physical sector size.  This option changes both sector sizes to sectorsize.