Bug 504128

Summary: partitionmanager Nvme SSD's sector size is not autodetected for megabyte alignment
Product: [Applications] partitionmanager Reporter: Shmerl <shtetldik>
Component: generalAssignee: Andrius Štikonas <andrius>
Status: RESOLVED FIXED    
Severity: normal    
Priority: NOR    
Version First Reported In: 24.12.0   
Target Milestone: ---   
Platform: Debian testing   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description Shmerl 2025-05-13 03:05:42 UTC
Not sure if this is fixed in newer version (I'm using 24.12.0 from Debian testing), but I noticed that partitionmanager always assumes 2048 sectors for partition alignment.

The logic behind it is that 2048 x 512 B = 1048576 B = 1 MiB. I.e. that's megabyte alignment... but only if sector size is 512 bytes.

Modern NVMe SSDs support 4 KiB sector sizes (not always by default, but it's often an option to select such sector size with nvme-cli for example). In such case, to get megabyte alignment you need to use 256 sectors, not 2048! I.e. 256 x 4 KiB = 1 MiB.

But partitionmanager is oblivious to this detail and always sticks to 2048 sectors alignment, unless user explicitly set it to 256 in its settings (which many won't even realize should be done). That wastes some space / creates unnecessary gaps or edges when making partitions.

Please make partitionmanager autodetect sector size (it already has that info from smart tools) and use correct value for getting the default megabyte alignment.

Thank you!
Comment 1 Shmerl 2025-09-25 20:08:42 UTC
FYI, this still happens at least in the version in Debian testing.
Comment 2 Andrius Štikonas 2025-09-25 20:50:04 UTC
(In reply to Shmerl from comment #1)
> FYI, this still happens at least in the version in Debian testing.

Well,, cause so far nobody who has 4k device has sent a patch...

At the moment all my drives have 512b sectors, perhaps if my next drive has large sectors, I can take a look.
Comment 3 Shmerl 2025-09-25 20:57:52 UTC
(In reply to Andrius Štikonas from comment #2)
>
> At the moment all my drives have 512b sectors, perhaps if my next drive has
> large sectors, I can take a look.

NVMe SSDs at least often have options for sector size. For instance I have SK hynix Platinum P41. Sector size can be checked like this:

    sudo nvme id-ns -H /dev/nvme0n1 | grep 'Relative Performance'
    LBA Format  0 : Metadata Size: 0   bytes - Data Size: 512 bytes - Relative Performance: 0 Best
    LBA Format  1 : Metadata Size: 0   bytes - Data Size: 4096 bytes - Relative Performance: 0 Best (in use)

By default it was 512 for me. I set it to 4KiB like this:

    sudo nvme format --lbaf=1 /dev/nvme0n1

You can check if you drive has such option too, even if it's not using it out of the box. Note that changing sector size deletes all data on the drive, so do it with a spare one that you can experiment with.
Comment 4 Andrius Štikonas 2025-09-25 21:07:41 UTC
(In reply to Shmerl from comment #3)
> (In reply to Andrius Štikonas from comment #2)
> >
> > At the moment all my drives have 512b sectors, perhaps if my next drive has
> > large sectors, I can take a look.
> 
> NVMe SSDs at least often have options for sector size. For instance I have
> SK hynix Platinum P41. Sector size can be checked like this:
> 
>     sudo nvme id-ns -H /dev/nvme0n1 | grep 'Relative Performance'
>     LBA Format  0 : Metadata Size: 0   bytes - Data Size: 512 bytes -
> Relative Performance: 0 Best
>     LBA Format  1 : Metadata Size: 0   bytes - Data Size: 4096 bytes -
> Relative Performance: 0 Best (in use)
> 
> By default it was 512 for me. I set it to 4KiB like this:
> 
>     sudo nvme format --lbaf=1 /dev/nvme0n1
> 
> You can check if you drive has such option too, even if it's not using it
> out of the box. Note that changing sector size deletes all data on the
> drive, so do it with a spare one that you can experiment with.

Yeah, I already checked and unfortunately the only drive that had that option was is my root fs drive, so tricky to convert for reasons you mentioned. But I'll keep it in mind for my next purchases...
Comment 5 Andrius Štikonas 2025-09-27 19:58:55 UTC
(In reply to Shmerl from comment #3)
> You can check if you drive has such option too

Actually I did find a spare NVMe that has that option. I'll still need to do some data moving but a bit later I should be able to look at this.
Comment 6 Andrius Štikonas 2025-09-27 22:26:09 UTC
I've adjusted partition alignment here https://invent.kde.org/system/kpmcore/-/merge_requests/65

It needs a bit more testing though. In particular I still need to do some testing to make sure it doesn't break LVM.
Comment 7 Shmerl 2025-09-27 23:55:21 UTC
It's probably good to add a comment there, since this division by 512 is pretty obscure otherwise.