0

On my Linux system I have a file "1gb.file" that is 1073741824 bytes in size.

This file I'll put into a LUKS container ("1gb.file.crypt") with ext4 filesystem inside.

What size must the file "1gb.file.crypt" have so there is enough space inside for the luksformat and the ext4 filesystem (I'll do mkfs.ext4 -m 0) on the luksdevice.

How to get enough space in the ext4 filesystem so I can put my 1073741824 bytes file inside, how to calculate this?

What size for the container if I have a 3 ... 7 or 10GB file into a LUKS container with ext4 filesystem?

How to calculate?

Some MBs left and free inside the container and on the ext4 filesystem it's OK, but I don't want to have hundreds of MBs free.

I don't know id it's relevant, but the file and the container are for read-only.

Or should I make the container big enough and shrink it after the file is in there a better way? But how to do this?

1
  • Hey ChanganAuto, ext4 is usually not capitalized. Writing it as EXT4 is more than unusual, so I fixed your edit in that respect. Authorative source Commented Jul 12 at 17:20

1 Answer 1

2

How to calculate

That depends on how the ext4 filesystem is set up, the shortest way to predict that is to make ext4 filesystems in image files until you find the size where your file fits. And it depends on your LUKS header (the encryption itself won't increase the data size, that would be bad, but the header will need to fit all keys, and encryption parameters).

However, you're not the first one to ask "how large must a file system be to fit exactly so and so many bytes in files. I have addressed that in at least two answers, of which I can only find one right now (but these two questions weren't the only ones on this platform):

The answer is always the same, regardless of file system: There's obviously file system overhead; and the moment you want to do anything with that file, you might run out of space. Note that ext4 is a journalling file system: Even just changing file attributes like modification or access time will need space for a journal. So, wrong choice of file system for your purpose.

So, what you want sounds useless. Instead of a mutable file system like ex4, put your file into a read-only file system that you create with nothing but the file inside, e.g.

mksquashfs 1gb.file files.img -comp zstd

and then encrypt that.

11
  • dont understand, how to encrypt?
    – user447274
    Commented Jul 12 at 15:34
  • 1
    you… encrypt. You make an image file, say, 2MB larger than your files.img, you cryptsetup luksFormat it, you open it with luksOpen, you write the contents of the files.img over the such-created block device. Commented Jul 12 at 15:53
  • yes, i know that, but what i am not know and understand is how to bring files.img to the block device. i think i do need a filesystem at the block the device? or is there an other way?
    – user447274
    Commented Jul 12 at 16:19
  • 1
    you simply cat files.img > {blockdevice}. Commented Jul 12 at 16:20
  • 1
    none is left afterwards. The concept of "space left" doesn't apply to block devices, only to file system. Random data: do not ask unrelated questions in the comments to answers, please! Ask them as new question posts. Commented Jul 12 at 16:42

You must log in to answer this question.

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