Extend VeraCrypt Container Size

1

Suppose I have created a 1 GiB VeraCrypt container and now have it filled to 900 MiB.

How can I extend the container to 5 GiB on Ubuntu?

(without having to create a new 5 GiB container and then copying the files over)

Following the advice of pbies, I created a 5 MiB VeraCrypt container (with a normal and hidden partition).

I used dd if=/dev/zero bs=5M count=1 >> File to append 5 MiB of null bytes

Running sudo resize2fs /dev/mapper/veracrypt1, I get an error:

resize2fs 1.42.13 (17-May-2015)
resize2fs: Bad magic number in super-block while trying to open /dev/mapper/veracrypt1
Couldn't find valid filesystem superblock.

I made sure to use EXT4 as the filesystem (rather than FAT, as resize2fs cannot operate on it)

7Fwt7jmMuyR5BZd

Posted 2017-05-06T17:48:41.920

Reputation: 11

Answers

0

You should be able to add 4GB of zero-bytes at the end of the container and then after connecting it in VeraCrypt - resizing the partition inside.

Create 4GB file of zero-bytes using dd and /dev/zero, cat it by >> at the end of the container, then mount the drive and use resize2fs to make it bigger.

If there are hidden partitions in container you may loose them. Backup your data first!

EDIT: After adding 4GB at the end of file, you need to run fdisk and resize the partition (remove it and create it but bigger, no data loss in this process - it only operates on partition table).

pbies

Posted 2017-05-06T17:48:41.920

Reputation: 1 633

@7Fwt7jmMuyR5BZd see my edit. – pbies – 2017-05-06T18:04:09.637

By doing this, would the container no longer be encrypted / filled with random data? – 7Fwt7jmMuyR5BZd – 2017-05-06T18:05:35.767

No; It would be encrypted – Ramhound – 2017-05-06T18:12:19.830

@7Fwt7jmMuyR5BZd it would be filled with random data but usable. – pbies – 2017-05-06T18:53:02.270

But didn't we just fill it with zeros (or would it be because VeraCrypt encrypts it while writing to the container)? Anyways, I'll go ahead and try it on a test container – 7Fwt7jmMuyR5BZd – 2017-05-06T19:00:30.750

We fill it with zeroes so it will be treated as random data for encrypting functions in VC. Really it doesn't matter what data you add to the container. – pbies – 2017-05-06T19:17:08.790

If you encrypt a region of space on the hdd and its filled with 0s when you encrypt the 0s you end up with a bunch of 0s....it's only after you fill that space up with actual data will it be random noise.... – Ramhound – 2017-05-07T01:53:01.513

Doesn't this method destroy the backup header at the end of the veracrypt volume? – kdb – 2018-05-16T14:45:39.957

@kdb This happens only for hidden volume. – pbies – 2018-05-16T14:57:13.650

@pbies Hidden volumes shouldn't be relevant here. From the documentation, the hidden-volume header is at a fixed reserved position at the start of the container and shouldn't be affected by the resize (though the hidden-volume contents may be). The backup header for both standard and hidden volume is positioned at a fixed offset relative to the end of the container, so VeraCrypt should no longer find it after the described resize operation, or any other operation that changes the file-size. – kdb – 2018-05-17T08:19:21.147

@kdb I don't know anything about header at the end of container for non-hidden volumes. Any source for that info? – pbies – 2018-05-17T10:20:27.350

@pbies Best source for this is the Veracrypt Volume Format Specification: "Each VeraCrypt volume contains an embedded backup header, located at the end of the volume." (details see link).

– kdb – 2018-05-17T12:21:20.897

@kbd Yes, I can see there "Backup header for hidden volume" in the table, seems like not strict info if this is only for hidden volume or not. OP should test if the solution works in the end = no problems with mount process. – pbies – 2018-05-17T16:09:30.980