Re: A new container with an old header

Michael Kjörling <[email protected]> Thu, 13 Jul 2023 16:29:12 +0000
Newsgroups dev.linux.lists.cryptsetup
Message-ID <[email protected]>
On 13 Jul 2023 15:30 +0000, from [email protected] (Darek Hisc):
> Thank you Michael for your suggestions!
> Particularly valuable for me is the ability to check the checksum of a fragment of a file (I did not know this before):
> $ dd if=luks-container bs=1048576 count=100 | md5sum -b

You can also use skip= and/or different values for bs= and count= to
get a checksum for any arbitrary portion of a file (of known offset
and length); or really, pass the data to any arbitrary program. I used
md5sum for illustrative purposes and because any non-malicious change
is likely to have a significant impact on even a MD5 hash, making
obvious any corruption from the enlargement. I strongly advise against
using MD5 for anything where cryptographic strength matters.


> Instead of `truncate -s 200M` I found a better solution for my use case:
> `head -c 200M /dev/urandom >> my-container`

Yes, something like that should work just as well (though of course
with that particular command and starting with a 100 MB container
you'd get a 300 MB container instead of 200 MB). There are other ways
as well, like using dd to graft data from one file into another; I
picked one method, not really to the exclusion of others but to keep
things reasonably straight-forward in my example.

**In short**, there are multiple ways to enlarge the container file,
and once that has been done, there should be nothing special about
your setup compared to having a LUKS container backed by a partition
or a portion of LVM-managed storage.

-- 
Michael Kjörling                     🔗 https://michael.kjorling.se
“Remember when, on the Internet, nobody cared that you were a dog?”