6

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?

4 Answers 4

5

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.

1
  • 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, 2013 at 15:53
2

Yes it's possible: If you run

losetup --help 

you will notice the option

-b, --sector-size

I suggest also testing to use the direct-IO option too on the loop block device

Here is how I create my loop devices :

losetup --sector-size 4096 --direct-io=on $loop_device $diskfile

But maybe in your case, only --sector-size 4096 is sufficient.

You can then display the loop devices with the losetup -l command:

NAME          SIZELIMIT OFFSET AUTOCLEAR RO BACK-FILE                            DIO LOG-SEC
/dev/loop4000         0      0         0  0 /mnt/fbx/FBX-24T/testspeed2            1    4096
/dev/loop3000         0      0         0  0 /mnt/fbx/FBX-24T/testspeed             1    4096

Please note the 4K block sectors

Please also note that for the moment, you can specify the sector size from 512 to 4096 but for example it's not possible to use 8K sectors (8192), the losetup command will fail if you try to use sectors size bigger than 4096.

Here is why I suggest using direct-IO option: --direct-io=on

When you have a 4K sectors formated filesystem on the underlying file used to create the loop device (see losetup -P or losetup --partscan option), using the direct-IO option will bypass the kernel storage stack working queue by sending the IO directly to the block device.

It helps keeping coherent (aligned) the block device and the filesystem you're writing on.

In some case, it also provide 8 to 10 times better performance, for example when creating a loop device from a LUKS file hosted on a CIFS share
(LUKS = Linux Unified Key Setup aka Cryptsetup which add a crypted layer between the block device and its hosted filesystems)

2
  • Why would you recommend --direct-io=on? (Please update your question to clarify, as otherwise it's essentially the same as another answer) Aug 14 at 13:43
  • Be carefull, the answer you specify is talking about the 'fdisk' command and not the 'losetup' command. I suggest using '--direct-io=on' if you have a 4K sectors formated filesystem on the underlying file used to create the loop device (see losetup '--partscan' option), it will bypass the kernel storage stack working queue by sending the IO directly to the block device. It helps keeping coherent (aligned) the block device and the filesystem you're writing on. In some case, it also provide 8 times better performance, ex: when creating a loop device from a LUKS file hosted on a CIFS share
    – nbanba
    Aug 21 at 8:21
0

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.

6
  • I'm more interested in partitioning tools such as gdisk, but thanks. Nov 12, 2013 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, 2013 at 14:26
  • I can't find a switch to gdisk to do this... Nov 12, 2013 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, 2013 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, 2013 at 15:04
0

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .