Moving LXC container to USB

So here is the situation. I have installe Debian lxc container on my omnia a installed an Unifi controller to have better control over my Unifi APs.

Now to protect the Omnia internal memory I would like to move the entire container to a USB dongle or to a LAN NAS (I have 3 - two WD and a Seagate Black Armor).

First thing I intended to do was to copy the entire /srv/lxc/Debian folder on the mounted USB stick and change the links in config files but that does not work.

Is there any other option apart from creating new container and istalling that one directly to the USB Drive?

And then there is second question and that is how to mount a NAS drive in the network so the Omnia would be able to see it.

Thank you

You can use symlinks.

How will that help with moving the installed lxc container?

Move whatever you want 1:1 to new location and create symlink in original location referring to new location. Then you donā€™t need to care about configs or possible rewrites of them after updates etc.

I tried to copy, but the copy process failed several times with error messages like ā€œunable to create linkā€ etcā€¦ will try move then

You canā€™t just copy Linux Containers from one file system to another and have it work. See https://stackoverflow.com/questions/23427129/how-do-i-backup-move-lxc-containers for an explanation/answer.

I have done the equivalent to what you want on TO (from one internal FS to USB) using tar --numeric-owner and it worked for me.

2 Likes

Now, THIS was helpful! Thanks!

If it works, mark as a solution so everyone can benefit.

I canā€™t remember this problem while moving my lxc from internal storage to SSD. Maybe in case of USB itā€™s different.
Just to make sure: this is needed when moving to another file system or it is just needed when moving from one system to another (move lxc from one machine to another).
Thank youā€¦

TBH, I am not 100% sure. I seem to remember reading that a simple copy/move may still cause problems, even if staying within the one OS.

All I can tell you is I used ā€“numeric-owner to:

  • archive from mPCIe/internal SSD to USB/external HDD, and then
  • restore back to the mPCIe/internal SSD (after formatting as BTRFS)

(all within TO) and had no difficulty (which is just as well, as Iā€™d destroyed the original FS).

Letā€™s wait to see what @Vit says!

1 Like

And I say it works! I didnā€™t use the symlink, just updated the path to /mnt/sda1 in the LXC container config file. So now the statistic and Unify controller remains on the USB stick. Its not slower, than it was before!

Thank dbonnes very much for help!

I am trying to do the same as ā€˜subjectā€™. And I am not sure i can follow the solution provided.
Could you ( @vit or @dbonnes ) please summarize all the steps necessary to do to move the container from omnia internal memory to usb attached.
Thanks a lot :slight_smile:

@ajsicek: Maybe Foris 3.10 might be an easier solution for you (not tested by me).

Anyway:

  1. For each LXC:
for NAME in guacd nginx home mysql tomcat; do
  lxc-stop -n ${NAME}
  cd /srv/lxc/${NAME}/
  tar --numeric-owner -czvf /tmp/run/mountd/sdb1/lxc-${NAME}.tar.gz ./*
done
  1. Replace /srv on local storage with external storage

  2. For each LXC:

for NAME in guacd nginx home mysql tomcat; do
  mkdir -p /srv/lxc/${NAME}/
  cd /srv/lxc/${NAME}/
  tar --numeric-owner -xzvf /tmp/run/mountd/sdb1/lxc-${NAME}.tar.gz .
done
  1. Profit!

This link may be useful:

1 Like

Beautiful thanks a lot :slight_smile: problem solved
As I use the USB disk for some other stuff and have it mounted in /mnt/sda1 I only changed step 2. for

  1. in /etc/lxc/lxc.conf change line to lxc.lxcpath = /mnt/sda1/lxc

and than change the path in step 3. accordingly.

Everything works great.