2

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)

1 Answer 1

1

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).

EDIT2: It is not safe solution for extending a partition with container. Resizing a container should be tested if it works, as data may be lost! See https://sourceforge.net/p/veracrypt/discussion/general/thread/c011ff54/?page=1&limit=25#361a

To be safe use VeraCryptExpander.exe on Windows. There may be a file system access problem (if it is ext4).

15
  • @7Fwt7jmMuyR5BZd see my edit.
    – pbies
    May 6, 2017 at 18:04
  • By doing this, would the container no longer be encrypted / filled with random data? May 6, 2017 at 18:05
  • No; It would be encrypted
    – Ramhound
    May 6, 2017 at 18:12
  • @7Fwt7jmMuyR5BZd it would be filled with random data but usable.
    – pbies
    May 6, 2017 at 18:53
  • 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 May 6, 2017 at 19:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .