dm-crypt.saout.de archive mirror
 help / color / mirror / Atom feed
From: Milan Broz <gmazyland@gmail.com>
To: Chris Murphy <chris@colorremedies.com>, dm-crypt@saout.de
Subject: [dm-crypt] Re: misaligned ending sector, 4096-byte luks sector size can't be used
Date: Mon, 24 Jan 2022 23:10:34 +0100	[thread overview]
Message-ID: <fe8cd3b4-6d50-66d3-375c-254e278a6443@gmail.com> (raw)
In-Reply-To: <CAJCQCtSAvvoGmm8D7gYTHnoRwHXBLTZ2EMBr5XQgfZu9s4dt_w@mail.gmail.com>

On 24/01/2022 18:07, Chris Murphy wrote:
> Hi,
> 
> cryptsetup-2.4.3-1.fc36.x86_64
> 
> On 512-byte logical sector size, 4096-byte physical sector size
> drives, cryptsetup luksFormat uses a 4096-byte LUKS sector size except
> when there's an unaligned last sector in a partition, i.e. the
> partition ends within a 4096-byte physical sector. Unfortunately this
> is pretty common due to the backup GPT, which makes the "last usable"
> sector, unaligned. gdisk, fdisk, and parted can all run into this
> problem. I can't really tell if this was ever considered by UEFI/GPT
> spec writers. The backups GPT is 33 LBAs in size. So it's always
> 4096-byte unaligned.
> 
> All the sectors in the partition are 4096-byte aligned except the last
> one.

And IMO this is the bug in partition tools. We already discussed this with
util-linux (and fdisk) maintainer, I am not sure if they will fix that.

But anything else would be a horrible hack. If the device is not aligned
to requested sector length (usually 4k), then it cannot be used with that
sector size.

The whole idea of misaligned backup GPT at the end of device is broken.
We should not follow that with adding hacks when the easy solution
is just to align a partition properly.

Years ago there was a general agreement to align partition start to 1 MiB
offset, I think we should do the same for the partition length.

> Therefore it seems suboptimal to fall back to 512-byte LUKS
> sector size, or for luksFormat --sector-size 4096 to fail. Is there a
> way for cryptsetup to just map out the dangling 1-7 512-byte sectors
> at the end? They are useless anyway in this case, but the partitioning
> tools aren't in a position to know the use case. The last 1-7 sectors
> are legitimately individually addressable so it's not incorrect for
> the partitioning tool to include them in the last partition on the
> device.

The default is to not store device length in LUKS header - so it follows
underlying device resize.
If you set sector size to 4k, then the unaligned sectors are no longer
"legitimately" addressable (dm-crypt will set 4k as "physical" sector,
IOW as atomic unit of the device). I understand that some filesystems use
hacks to ignore this, but it is really not a system solution.

Milan
_______________________________________________
dm-crypt mailing list -- dm-crypt@saout.de
To unsubscribe send an email to dm-crypt-leave@saout.de

  reply	other threads:[~2022-01-24 22:13 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-24 17:07 [dm-crypt] misaligned ending sector, 4096-byte luks sector size can't be used Chris Murphy
2022-01-24 22:10 ` Milan Broz [this message]
2022-01-25 12:20 [dm-crypt] " Arno Wagner
2022-01-27 13:21 ` Milan Broz
2022-01-27 18:18   ` Christoph Anton Mitterer
2022-01-27 22:32     ` Chris Murphy
2022-01-27 22:35       ` Chris Murphy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fe8cd3b4-6d50-66d3-375c-254e278a6443@gmail.com \
    --to=gmazyland@gmail.com \
    --cc=chris@colorremedies.com \
    --cc=dm-crypt@saout.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).