I created an AMI with Packer and Ansible. It uses Ubuntu 20.04 and I installed system libraries, application packages, Docker, Compose, configuration files, and source code. This data was installed on the root device. The storage looks like this:
Device ID | Device Name | Size |
---|---|---|
snap-1 | /dev/sda1 (root) | 20GB |
Let’s give this AMI the ID AMI-1. With Terraform, I provisioned a single EC2 instance with AMI-1. I created and attached a 50GB EBS volume, formatted, and mounted it to /var/lib/docker/volumes
. EBS lifecycle snapshot policies were also created to back up this EBS volume to snapshots. The storage looks like this:
Volume ID | Device Name | Size | Mount Location |
---|---|---|---|
vol-1 | /dev/sda1 (root) | 20GB | / |
vol-2 | /dev/sdf | 50GB | /var/lib/docker/volumes |
Everything works as intended. I now would like to update the OS to Ubuntu 22.04 and bring over all the data I created without corrupting or losing it. None of it needs changing, I only intend to change the OS.
The EBS volume (vol-2) is safe and easy to bring over to the new instance. I just detach and reattach it. I’m not concerned with the data on this volume.
The data on the EBS volume on the root device is my concern. It contains the OS and replacing the OS means all of the data I installed and configured with Packer and Ansible may be lost.
- Is my assumption, correct? This data will be lost and I’ll need to redo these steps on the new instance?
- Is there a realistic way to get it on the new instance, possibly on a new EBS volume not on the volume of the root device?
- What is the recommended approach to get all of the data in both volumes to a new instance with an updated OS?
- How should I have configured this EC2 instance & volumes to be able to perform seamless OS upgrades without losing data?