Using the losetup command, you can turn a regular file into a pretend block device. You can then partition and format it like any other device.

Is there some way to make Linux pretend that this "device" has a 4K logical sector size?


fdisk has a number of switches:

-b sectorsize

Specify the sector size of the disk. Valid values are 512, 1024, 2048 or 4096. (Recent kernels know the sector size. Use this 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.

-C cyls

Specify the number of cylinders of the disk. I have no idea why anybody would want to do so.

-H heads

Specify the number of heads of the disk. (Not the physical number, of course, but the number used for partition tables.) Reasonable values are 255 and 16.

That's not me editorializing ("I have no idea why anybody would want to do so."). Kind of nice someone included functionality they didn't see a use for at the time.

  • I notice based on your other question you were more interested in the GPT format. I'd guess you can use fdisk to partition the device, then apply gdisk to it.
    – goldilocks
    Nov 12 '13 at 15:53

Not at a low level. It is certainly possible to tell some mkfs dispatch utilities that they should use a certain block size when formatting though. See the man page of the specific mkfs.* tool for further information.

  • I'm more interested in partitioning tools such as gdisk, but thanks. Nov 12 '13 at 14:24
  • @MathematicalOrchid: Those are easy though. Most of them can have a specific drive geometry forced upon them via the command line. Nov 12 '13 at 14:26
  • I can't find a switch to gdisk to do this... Nov 12 '13 at 14:37
  • 1
    Maybe you could elaborate in your question what exact problem you are facing with gdisk. The solution may be something else entirely. Nov 12 '13 at 14:46
  • That only changes the partition alignment, not what gdisk thinks the sector size is. The GPT header is still 512 bytes from the start of the disk. Nov 12 '13 at 15:04

Latest losetup should have this feature: https://github.com/karelzak/util-linux/commit/a1a41597bfd55e709024bd91aaf024159362679c

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.