Re: A new container with an old header

Michael Kjörling <[email protected]> Wed, 12 Jul 2023 18:25:35 +0000
Newsgroups dev.linux.lists.cryptsetup
Message-ID <[email protected]>
On 12 Jul 2023 15:59 +0000, from [email protected] (Darek Hisc):
> Alternatively, a way to increase the size of "file1" to 200MB. All
> the information I've found is about resizing a partition or LVM. But
> I don't know how to increase LUKS2 file-container.

There should be nothing special about the LUKS container being within
a file.

Of course DO make a backup of your container (and header, if separate)
before you do this, and I'd triple-check to ensure the container isn't
open at the time just to avoid the risk of something getting confused
by the change in size, but something adapted from the following should
work.

$ dd if=/dev/urandom of=luks-container bs=1048576 count=100
$ stat luks-container
  File: luks-container
  Size: 104857600 ...
$ md5sum -b luks-container
<something>
$ truncate -s 200M luks-container
$ dd if=luks-container bs=1048576 count=100 | md5sum -b
<same something, proves that the first half is unaltered>
$ stat luks-container
  File: luks-container
  Size: 209715200 ...
$

Then enlarge the file system within the container normally. Exactly
how you do that will of course depend on exactly what the contents of
the container is.

The key here is using "truncate -s" to set the new size of the file
without otherwise altering its contents.

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