How to successfully change blocksize of disk on Azure?

Michał Czajkowski 0 Reputation points
2025-02-22T08:45:57.4733333+00:00

Im trying to change blocksize on Azure disk, to store multiple small files:

sudo mkfs -t ext4 -b 1024 /dev/sdd

Warning: specified blocksize 1024 is less than device physical sectorsize 4096 Discarding device blocks: done Creating filesystem with 268435456 1k blocks and 16777216 inodes Filesystem UUID: ***************************** Superblock backups stored on blocks: 8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409, 663553, 1024001, 1990657, 2809857, 5120001, 5971969, 17915905, 19668993, 25600001, 53747713, 128000001, 137682945, 161243137

Allocating group tables: done Writing inode tables: done Creating journal (262144 blocks): done Writing superblocks and filesystem accounting information: done

Looks more or less ok, but when checked :

azureuser@***************:~$ sudo blockdev --getbsz /dev/sdd

4096

Any workaround ?

Azure Disk Storage
Azure Disk Storage
A high-performance, durable block storage designed to be used with Azure Virtual Machines and Azure VMware Solution.
663 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Vinodh247 29,361 Reputation points MVP
    2025-02-22T10:07:07.33+00:00

    Hi ,

    Thanks for reaching out to Microsoft Q&A.

    You are facing an issue where Azure disks enforce a physical sector size of 4096 bytes, which overrides your attempt to set a smaller block size (1024 bytes). The problem is that Azure-managed disks are based on SSDs, and most modern SSDs use 4K sectors natively, which makes it difficult to force a smaller block size.

    Workarounds & Solutions:

    Use a Loopback Device with a Smaller Blocksize

    Instead of formatting the disk directly, you can create a file-backed loop device that supports a 1024-byte block size

    Consider XFS Instead of EXT4

    If your goal is efficient storage of small files, XFS might be a better choice than EXT4 with a smaller block size, since it handles small files better due to its inode clustering.

    Use Filesystem-Level Optimizations

    If your goal is to store many small files efficiently, you can also tweak inode settings while formatting. This will optimize for smaller file sizes without changing the block size.

    Please feel free to click the 'Upvote' (Thumbs-up) button and 'Accept as Answer'. This helps the community by allowing others with similar queries to easily find the solution.


  2. Sathvika Reddy Dopathi 200 Reputation points Microsoft External Staff
    2025-02-24T05:21:28.7466667+00:00

    Hi @Michał Czajkowski,

    Adding additional information to the above:

    The physical sector size of the disk is 4096 bytes, it determines the minimum block size that can be set. You cannot set a block size smaller than the physical sector size.

    Workarounds:

    1.Use the Default Block Size: Since the physical sector size is 4096 bytes, you can create the filesystem with the default block size. This will ensure optimal performance and compatibility.

    To format the disk with a smaller allocation unit size using the mkfs command:

    sudo mkfs -t ext4 -b 4096 -T small /dev/sdd
    

    2. Use a File System Efficient for Small Files: Using a file system like NTFS or ReFS on Windows, which are efficient for handling small files.

    3.Use Btrfs Filesystem (with Compression): Btrfs is a filesystem that supports compression and is optimized for storing a large number of small files. It can manage various block sizes effectively, and its compression features enhance the efficient storage of small files.

    sudo mkfs.btrfs -d single -O compress=zlib /dev/sdd
    

    4. Use XFS with Larger Inodes: While XFS may already be a better choice than EXT4 for small file storage, you can further optimize it by configuring it with larger inodes.This improves the handling of metadata, which is useful when dealing with small files.

    You can use the -i flag to adjust the inode size during formatting:

    sudo mkfs.xfs -i size=512 /dev/sdd
    

    5. Utilize Azure Blob Storage: If your workload primarily consists of small files, consider using Azure Blob Storage instead of Azure disks. Blob Storage is optimized for storing large amounts of unstructured data, including small files.

    Please let us know if you have any further queries. I’m happy to assist you further. 

    Please consider to “up-vote” and "accept the answer" wherever the information provided helps you, this can be beneficial to other community members.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.