Because you are on this page I assume you have received the same warning I did. “warning: device is not properly aligned”. I allocated a new 1 TB iSCSI drive and I attached it to the initiating server. After the iSCSI device was connected I partitioned it to use 100% of the disk. Then I attempted to format the partition with the XFS file system using the following command.
I immediately got the following response:
warning: device is not properly aligned /dev/sdb1 Use -f to force usage of a misaligned device
Finding the fix for “device is not properly aligned”
So I did some digging and came across this article about how to properly align the partition. I followed the post to grab the following values from the device.
[root@server ~]# cat /sys/block/sdb/queue/optimal_io_size 1048576 [root@server ~]# cat /sys/block/sdb/queue/minimum_io_size 131072 [root@server ~]# cat /sys/block/sdb/alignment_offset 0 [root@server ~]# cat /sys/block/sdb/queue/physical_block_size 131072
Following the formula that was outlined (optimal_io_size + alignment_offset) / physical_block_size. And got the following results: (1048576 + 0) / 131072 = 8. I plugged that information into parted, which resulted in mixed results.
(parted) mklabel gpt Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you want to continue? Yes/No? Yes (parted) mkpart primary 8s 100% Warning: You requested a partition from 4096B to 1074GB. The closest location we can manage is 17.4kB to 1074GB. Is this still acceptable to you? Yes/No? Yes Warning: The resulting partition is not properly aligned for best performance. Ignore/Cancel? Ignore (parted) align-check optimal 1 1 not aligned
Making Sense of the Parted Alignment Response
So my drive was still not properly aligned, but I had some better info which would help me fix the problem. So let’s break down the Parted commands
(parted) mklabel gpt
Destroyed the existing partition table and cleared things out to start fresh.
(parted) mkpart primary 8s 100%
This command told Parted to create a new primary partition starting at sector 8 and use the rest of the drive. The response that came from this command gave me the clue that I needed to fix the alignment.
Warning: You requested a partition from 4096B to 1074GB. The closest location we can manage is 17.4kB to 1074GB.
The warning output indicated that 8 sectors of 512B would only come to 4096B or 4kB. But Parted could only adjust the alignment to 17.4kB, so this was still out of alignment as the rest of the output indicated. That gave me the clue I needed to fix it though.
Knowing now that Parted could only get within 17.4kB of the start of my drive I adjusted the sectors to match that. Since 8 sectors was 4096B, I adjusted it to be an even number of sectors beyond the 17.4kB point. Choosing 32768B, or 64 sectors. This change yielded the following results.
(parted) mklabel gpt Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you want to continue? Yes/No? Yes (parted) mkpart primary 64s 100% (parted) align-check optimal 1 1 aligned (parted) quit Information: You may need to update /etc/fstab.
The partitioning was successful, using the 64 sector starting point pushed it beyond the 17.4kB point. Then it was properly aligned. I formatted the partition with XFS and all went swimmingly.
[root@server ~]# mkfs.xfs /dev/sdb1 specified blocksize 4096 is less than device physical sector size 131072 switching to logical sector size 512 meta-data=/dev/sdb1 isize=256 agcount=32, agsize=8191872 blks = sectsz=512 attr=2, projid32bit=0 data = bsize=4096 blocks=262139648, imaxpct=25 = sunit=32 swidth=256 blks naming =version 2 bsize=4096 ascii-ci=0 log =internal log bsize=4096 blocks=128000, version=2 = sectsz=512 sunit=32 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0
Now the device is formatted, mounted, and working like a champ. Who would have known that a simple offset of 32kB could make such a problem.