An experiment : ISO to Image : Docker Successful but LXD failed

I have started finding myself more comfortable with LXD than docker. Earlier, I was able to convert any iso file to docker image by following commands:

wget https://releases.ubuntu.com/18.04.4/ubuntu-18.04.4-live-server-amd64.iso

(1)sudo apt install squashfs-tools
(2) mkdir rootfs unquashfs
(3) sudo mount -o loop ubuntu-18.04.4-live-server-amd64.iso rootfs
(4) find . -type f | grep filesystem.squashfs
(5) sudo unsquashfs -f -d unsquashfs/ rootfs/casper/filesystem.squashfs
(6) sudo tar -C unsquashfs -c . | docker import - root/ubuntuserver1804

Now I have ubuntuserver1804 as docker image. But I want to import it as lxd image in point no. 6
Tried number of syntax but failed.

I know ,
(1) cant create lxd image from file with .tar extension. Requires .tar.gz extension.
(2) Distrobuilder : https://distrobuilder.readthedocs.io/en/latest/
(3) p2c

I was trying to have lxd image of coreOS as an experiment.
I find this method more easy to create image. When we can create a docker image from squashfs-tools then we should also able to create lxd image.

I am still new to world of linux.

I have no easy answer for you, but you could take a look at what is inside the files that are created by distrobuilder for an image:

  • lxd.tar.xz
  • rootfs.squashfs

and then try to replicate that.
But no promises, I don’t know if that is possible :slightly_smiling_face: .

Thanks Toby, I tried it with tar.xz and tar.gz but no success in building lxd image.
Error: Could not extract image metadata.yaml from tar: Failed to run: tar -O -xf /var/lib/lxd/images/lxd_build_600179762/lxd_post_378730985 metadata.yaml: tar: metadata.yaml: Not found in archive

Thats what I meant with replicate:
distrobuilder seems to add some files, like “metadata.yaml”, so you would have to create/modify and add that by hand.

But honestly what is the purpose, you can just download or create lots of distro images.
You can also modify the templates used by distrobuilder: https://github.com/lxc/lxc-ci/tree/master/images
to add software etc.
And you can create an image from a container, so this way you can save and reuse all the modifications from it.

Note: This applies only to existing templates or images, if you want to setup an unsupported Operating System you at least need to combine this with other methods (like template modification so it fits the new OS etc.).
An Alternative would be the other way around, take a look at an iso (open it) and find out what programs are installed in it for example, and then include that in a template for the distrobuilder or in the cloud-init config that can run on container start, so the resulting image or container, contains all the software the .iso includes.

Actually , I want to create CoreOS lxd limage…( just for an experiment) . https://coreos.com/os/docs/latest/booting-with-iso.html . This gives me docker image by above method in question.

okay I will check this :slight_smile:
An Alternative would be the other way around, take a look at an iso (open it) and find out what programs are installed in it for example, and then include that in a template for the distrobuilder or in the cloud-init config that can run on container start, so the resulting image or container, contains all the software the .iso includes.

My Argument is When we can create a docker image from squashfs-tools then we should also able to create lxd image.

Actually , I want to create CoreOS lxd limage

Ah ok, thats a valid purpose indead :smiley:.

One more approach, you could look at the templates:

And take the template that is most similar to CoreOS (I don’t know about CoreOS so I can’t give you an advice about that; maybe CoreOS is so different that none fits) and try to modify it so it fits for CoreOS.
And then build the new template with distrobuilder.

Maybe someone else tried the same thing already, so a search in the net might bring helpful advice.

My Argument is When we can create a docker image from squashfs-tools then we should also able to create lxd image.

Hmm I don’t know about that :thinking: , but I agree that building an image by hand would be a good thing, then again there is a reason for the distrobuilder, so it seems to be a bit more complicated.

Update:
Just found this:

Might be easier to setup (for example with the template modification mentioned above), but I don’t have a clue :smile:.

Some more ideas:

  • If CoreOS can be run inside Docker you might find a converter to convert the necessary Dockerfile etc. into LXD (though that maybe does not solve the image problem…)

Interestingly the website seems to only recommend set up in virtual machines or on servers/computers directly…

  • If you use a virtual machine, that might be much easier.

Hmm tried.
docker image to image.tar.gz and building lxd contained :doesnt work

Also , Converting Docker image to LXD

Maybe your best chance is to use p2c.
(I know you already mentioned that above)

I don’t know exactly how it works (never tried it yet), but it seems you first have to setup a vm and then you can create a container from it.

There is an image of coreos for qemu: