Is it possible to import a container directly as a file system?

Hi All,
I have a running LXD 4.4 and need to import a server as a container configured by another developer. He copied the file system from his container instead of using export, so I have the rootfs directory along with backup.yaml. I’ve set up a template container as Ubuntu 18.04 and tried using lxc file push to overwrite directories under / in the stopped container. A few items under /dev failed to copy. The container did start up but services like apache2 and mysqld don’t fire up and /etc/init.d/apache2 and /etc/init.d/mysql just hang when trying to start.

Is there a cleaner way to directly import a full root file system like this? Has anyone done anything along these lines?

I’m just starting to get into LXD and would very much appreciate any help.
Thanks in advance!

Sasha

:thinking:
First of all, why can’t the developer just send you another copy?
Then:
I did not test these methods myself, but you could try multiple things:

  1. lxd-p2c: This is a tool to convert regular systems to containers (p2c=physical to container); sadly there is no recent documentation for it, but just search for p2c and you might find something.
  2. It might be easier to set up a new image/container:
    • try to find out what software was installed, you can then install all of that via cloud-init or distrobuilder (assuming that it is avialable in software repos)
    • copy /etc and other config folders
    • copy /home
    • copy special folders that you think are important
  3. Try to implement the rootfs as an image:
    https://linuxcontainers.org/lxd/advanced-guide/#import-container-image
    You should take a look at some original image files (for example: ubuntu bionic amd64) and try to replicate that.
    You need 2 things:
    • rootfs (e.g. rootfs.tar.xz or rootfs.squashfs): You might be able to use the rootfs you have for that.
    • lxd.tar.xz: This is somethings you might need to create by yourself, just look at the original to find out what it contains.

Otherwise wait for a better answer :wink:.

Thanks for the tips!
I did a bunch more searching and came across this thread. Basically, the container filesystems can be accessed in /var/snap/lxd/common/mntns/var/snap/lxd/common/lxd/storage-pools/<storage_pool_name>/<container_name>. I stopped the dummy container, copied he new file system to this location and updated file ownership by incrementing uid and gid by 1000000. The container then fired up with all services running. Not sure if it’s the cleanest way to go but at least I got it working without involving third party tools that may have their own issues.

For some reason, this information is not found anywhere in the official LXD manual.

Sasha

1 Like