r/linuxadmin • u/sdns575 • Jan 03 '26
Luks container with multiple images. Is it doable?
Hi, I read from here that I can create Luks container using a file image.
I would like to implement this using multiple file images.
The following could be a doable method:
- Create N images with fallocate of needed size
- Bind each image with losetup using loop devices
- Merge all them using mdadm --create /dev/md0 --level=linear --raid-devices=n /dev/loop[0-N]
- Create Luks file container on the md devices
There is a better way to accomplish to this?
Thank you in advance
6
Upvotes
6
u/bush_nugget Jan 03 '26
What is your actual end goal? Is it a LUKS container that can "grow"? Have you tried what you are suggesting as a "doable method"? Did it work?
3
u/Dolapevich Jan 03 '26
What is the objective? Why would you... I mean, maybe the word
containeris not adecuate, it quickly takes me to docker/podman land. It looks like you are just encrypting a file with luks.2
u/Fighter_M Jan 07 '26
Yes, that’ll work, but it’s kinda overcomplicated, IMHO. LUKS needs a single block device, so you do need some merge layer, but…
mdadm --level=linear
…is usually not the nicest one!
The simpler/cleaner way is to create N files, attach them as loop devices, put LVM on top, create one LV, put LUKS on the LV. Easier to grow later, fewer mdadm quirks.
If you really want md, that’s fine too, but linear gives you zero redundancy. If you care about safety, use md RAID1/10 under LUKS instead.
1
u/michaelpaoli Jan 04 '26
Yes, you can do that.
Better way? To accomplish what exactly? What are your objectives and criteria? Why would you want or prefer to do it that way, as opposed to some other way?
1
u/phagofu Jan 04 '26
Do you need to use LUKS? Otherwise maybe something like CryFS may work for you, assuming your goal is to back up a locally encrypted container to an untrusted remote via rsync.
1
u/will_try_not_to Jan 05 '26
There are a large number of factors that you have to consider here:
There are a few different ways of doing this - yes, what you're proposing will work, but it will probably be slow if the filesystem is bigger than a few GB, because rsync has no way to keep track of the changed areas between runs. Each time you run rsync, at the very least both your source and destination will need to read the entire contents of the entire filesystem (minus any sparse areas), just to figure out what needs to be synched.
Other possible solutions: