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)


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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.