Skip to content

Instantly share code, notes, and snippets.

@swyngaard
Last active July 15, 2018 21:06
Show Gist options
  • Save swyngaard/baa0e8bfe269ad2fb4ca5ba5b4a1e24c to your computer and use it in GitHub Desktop.
Save swyngaard/baa0e8bfe269ad2fb4ca5ba5b4a1e24c to your computer and use it in GitHub Desktop.
Migrate unprivileged LXC container to a new host

Migrate unprivileged LXC container to a new host

Shutdown the container

lxc-stop -n $NAME

Archive container rootfs and config

cd $HOME/.local/share/lxc/$NAME
sudo -s
tar --numeric-owner -czvf container_fs.tar.gz ./*

Copy the file to your new host

rsync -avh container_fs.tar.gz user@newserver:.local/share/lxc/

Extract rootfs

mkdir $HOME/.local/share/lxc/$NAME
chown 100000:$USER $HOME/.local/share/lxc/$NAME
cd $HOME/.local/share/lxc/$NAME
sudo -s
tar --numeric-owner -xzvf ../container_fs.tar.gz .

References

  1. https://stackoverflow.com/questions/23427129/how-do-i-backup-move-lxc-containers
@wmantly
Copy link

wmantly commented Jul 15, 2018

I noticed you have sudo -s, does this mean I need to add the user which runs my unprivileged containers to the sudo group?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment