512 byte is not really the default sector size. It depends on your hardware.
You can display what physical/logical sector sizes your disk reports via the
/sys pseudo filesystem, for instance:
# cat /sys/block/sda/queue/physical_block_size
# cat /sys/block/sda/queue/logical_block_size
What is the difference between those two values?
physical_block_size is the minimal size of a block the drive is able to write in an atomic operation.
logical_block_size is the smallest size the drive is able to write (cf. the linux kernel documentation).
Thus, if you have a 4k drive it makes sense that your storage stack (filesystem etc.) uses something equal or greater than the physical sector size.
Those values are also displayed in recent versions of
fdisk, for instance:
# fdisk -l /dev/sda
Sector size (logical/physical): 512 bytes / 4096 bytes
On current linux distributions, programs (that should care about the optimal sector size) like
mkfs.xfs will pick the optimal sector size by default (e.g. 4096 bytes).
But you can also explicitly specify it via an option, for instance:
# mkfs.xfs -f -s size=4096 /dev/sda
# mkfs.ext4 -F -b 4096 /dev/sda
In any case, most
mkfs variants will also display the used block size during execution.
For an existing filesystem the block size can be determined with a command like:
# xfs_info /mnt
data = bsize=4096
naming =version 2 bsize=4096
log =internal bsize=4096
realtime =none extsz=4096
# tune2fs -l /dev/sda
Block size: 4096
Fragment size: 4096
# btrfs inspect-internal dump-super /dev/sda | grep size
When creating the filesystem on a partition, another thing to check then is if the partition start address is actually aligned to the physical block size. For example, look at the
fdisk -l output, convert the start addresses into bytes, divide them by the physical block size - the reminder must be zero if the partitions are aligned.