[Feature Request] Keep Data Option for Attaching Volumes

At the moment, mounting a disk device to a path inside the container will effectively delete the contents of that folder in the container. It would be nice if you’d like to attach a volume later on to have the option of keeping the data intact and that being build into LXD.

My request is to implement a flag of --keep-data when mounting a volume to a folder like this:

lxc config device add ${containername} device-name disk pool=pool source=mysql-volume path=/var/lib/mysql --keep-data

A possible way could be to copy the data 1:1 into memory, mount and copy back.
When trying to do this manually I get data corruption on the mysql data so I was hoping you guys find a better way.

The data isn’t destroyed, you just get a mount added on top of it.
In your case, you could do this in the container to get to the data under the mount:

  • mount -o bind / /mnt
  • ls -lh /mnt/var/lib/mysql/
1 Like

Thanks! Will test that once I have the time.