Linux – Create Empty Image with 4096 Byte Sectors Using dd

ddhard-disklinuxpartition

The final purpose is to build the image of a partition sector by sector. I want the sector size to be 4096. As a first step I am trying to create an empty image of 32MiB with 4096bytes sectors rather than 512bytes. For this I am trying:

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

Then I do

fdisk -l empty4k.img

and shows 512 byte sectors. I believe it is because if you do "

fdisk -l /dev/zero

it also says 512 byte sectors.

Can anyone help me?

Best Answer

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.
Related Question