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?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityfdisk
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.
fdisk
to partition the device, then apply gdisk
to it.
Nov 12, 2013 at 15:53
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)
--direct-io=on
? (Please update your question to clarify, as otherwise it's essentially the same as another answer)
Aug 14 at 13:43
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.
gdisk
, but thanks.
Nov 12, 2013 at 14:24
gdisk
. The solution may be something else entirely.
Nov 12, 2013 at 14:46
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
Latest losetup should have this feature: https://github.com/karelzak/util-linux/commit/a1a41597bfd55e709024bd91aaf024159362679c