canonical / lxd

Powerful system container and virtual machine manager
https://canonical.com/lxd
GNU Affero General Public License v3.0
4.3k stars 929 forks source link

Support squashfs as compression algorithm #6273

Closed stgraber closed 4 years ago

stgraber commented 4 years ago

LXD already supports unpacking squashfs in a number of situations but it doesn't support using mksquashfs to generate squashfs based images or backups.

The existing compression logic for images and backups should be updated so that one can set the compression_algorithm to squashfs.

Consumption of squashfs images should already pretty much just work, consuming squashfs backups will need a few code updates too.

ulziibuyan commented 4 years ago

I would like to work on this

stgraber commented 4 years ago

So I forgot just how dependent we unfortunately are of tarballs... tarballs are very convenient internally because we can build them and alter file attributes without ever having to write anything on the actual filesystem, so I don't expect us to be moving away from them as the main building block for images and backups.

What we effectively want in this case is a way to use squashfs as a sort of compressor for a standard tar stream as is coming out of Export(). Looking around, our best bet is to support squashfs-tools-ng found at https://github.com/AgentD/squashfs-tools-ng/. That project has a very convenient tar2sqfs which appears to do exactly what we want. We'll deal separately with adding this binary to our snap package.

We'll want to stream the tarball output of Export() through tar2sqfs --compresor xz --no-skip FILENAME

For this, you'll want to:

With all that done, you should be able to:

This would effectively exercise all the code paths above and should result in two working containers.

ulziibuyan commented 4 years ago

Thanks for writing the elaborate guide, @stgraber. I've opened pull-request #6356 for your review.