I have cloned a disk into a sparse file that is about 80G but indeed requires only about 12G, even not compressed it fits on my memory, but in order to save some resources I want to use zram:

sudo modprobe zram num_devices=1
echo 79999997952 | sudo tee /sys/block/zram0/disksize
sudo fdisk -c=dos --sector-size 512 /dev/zram0

However when I create the partition it is using 4096 sector size even I told fdisk to use 512.

It do not let me type the size of the partition based on 512 sector size, and it is not a exact number which I could divide by 8 in order to have a 4096 based one, so I have done on a sparse mbr:

truncate -s79999997952 /tmp/block
fdisk -c=dos --sector-size 512 /tmp/block
# o, n, p, 1, 63, 156232124, t, 7, a, w
sudo dd if=/tmp/block of=/dev/zram0 count=1 bs=512

It seems with regular files fdisk sees no problem in using a 512 sector size! But zram is still weird, I do not know if it is going to work, because it shows a different disk size when on 512 mode:

$ sudo fdisk -lu /dev/zram0
Disk /dev/zram0: 74.5 GiB, 80000000000 bytes, 19531250 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
Disklabel type: dos
Disk identifier: 0x5f8b6465

Device       Boot Start       End   Sectors  Size Id Type
/dev/zram0p1 *       63 156232124 156232062  596G  7 HPFS/NTFS/exFAT

$ sudo fdisk -lu --sector-size 512 /dev/zram0
Disk /dev/zram0: 9.3 GiB, 10000000000 bytes, 19531250 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0x5f8b6465

Device       Boot Start       End   Sectors  Size Id Type
/dev/zram0p1 *       63 156232124 156232062 74.5G  7 HPFS/NTFS/exFAT

Understand, once 156232062 / 8 = 19529007.75 there is no way it can fit on 4096 sector size.

How to force fdisk or the zram itself to use 512 sector size?

1 Answer 1


The partition table on a 4K block device must be written in terms of 4K blocks.

zram does not include any option to control block size. It is hard-coded.


 * To ensure that we always get PAGE_SIZE aligned
 * and n*PAGE_SIZED sized I/O requests.
blk_queue_physical_block_size(zram->disk->queue, PAGE_SIZE);
blk_queue_io_min(zram->disk->queue, PAGE_SIZE);
blk_queue_io_opt(zram->disk->queue, PAGE_SIZE);

ZRAM_LOGICAL_BLOCK_SIZE is defined as a constant.

  • It's sad, but that is the truth! Mar 5, 2019 at 17:30
  • @TiagoPimenta more constructively, it might be possible to use a loop device to effectively adapt the block size. This can work because the loop device is implemented using "buffered" [cached] IO by default. The flip side is that you will get "double caching" when you access it, so the cache will use twice as much memory as usual :-). It's just cache though, so if you don't need a large working set on the device then it need not be a problem. unix.stackexchange.com/questions/187748/…
    – sourcejedi
    Mar 5, 2019 at 18:05

You must log in to answer this question.

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