Made a script to convert a KVM VM to an LXD rootfs

There have been times when I found a .ISO of which I’d like to create an LXD container but in the past had to settle for using it to create a KVM VM for the application.

I finally spent some time to create a script which automatically extracts the KVM VM’s rootfs and copies it to an previously created LXD container’s rootfs directory.

So far this seems to work well as I’ve taken various .ISO from both TurnkeyLinux ( and Bitnami (, created a KVM VM, then used the script to extract the VM’s rootfs and copy it to an LXD container I’d previously prepared for it. The script hopefully sets the UID/GID in the container correctly for use. I want to thank Stephane Graber for that line in the script which I’d found in an answer he’d posted to someone else in the issues section of the LXD Github.

The script’s process is fairly fast and so far has enabled me to turn up 4-5 LXD containers that originated from an .ISO file. They all seem to work okay from what I can tell.

Hopefully, I’ve documented the script enough so that others might improve on it and/or make use of it in the use-cases like I had.

You can find everything on Github at:


Cool, I’m sure that will be pretty useful to some of our users!

It looks like this repo was taken down. @bmullan, would it be possible to get a copy of this script, or put the repo back up? Thanks!


With the introduction of LXD’s own p2c (physical to container) conversion tool which is supported by the LXD team I felt it was not useful to keep that posted.

With the P2C tool you could take your ISO, create a KVM VM image of it on your machine then use the P2C tool to convert that to an LXD container.

That will probably do a much more complete conversion job than my script did.

They have I think even update the P2C tool recently. Here is some info from when it was first introduced that I posted which includes the info I got from Stephane Graber about how to compile the tool.


1 Like

Ah man, I thought I did a very thorough google for something like that. Thanks for the response!