Amazon EC2 - Swap root instance store device with EBS device
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Amazon EC2 (Elastic Compute Cloud) offers a versatile computing environment that allows developers to easily scale their applications. One common need when working with EC2 instances, particularly those utilizing ephemeral storage, is to swap the root instance store device with an Elastic Block Store (EBS) device. This process can enhance persistence, backup, and resilience strategies within your infrastructure. This article explains how you can achieve this, along with technical considerations, detailed examples, and additional insight.
What is Amazon EC2?
Amazon EC2 is a web service that provides resizable compute capacity in the cloud, designed to make web-scale computing easier for developers. It allows for the rapid deployment of virtual servers, known as instances, which can be scaled up or down according to the user’s needs.
Instance Store vs. EBS
Instance Store
- Volatile Storage: Instance store provides temporary block-level storage for use with EC2 instances. It is directly attached to the host machine, leading to high performance but lacks durability across instance stops or terminations. Data on an instance store is lost when the instance is stopped or terminated.
- Usage: Primarily used for temporary data such as caches, buffers, and other transient states.
Elastic Block Store (EBS)
- Persistent Storage: EBS offers persistent storage in the form of volumes that are independent of the actual instance. The data persists even after the instance is stopped or terminated.
- Features: EBS volumes can be easily backed up with snapshots, attached or detached from instances, and provide features like encryption and fine-tuned performance options.
Swapping the Root Instance Store with EBS
Swapping the root instance store with an EBS device involves creating an instance with an EBS-backed root volume. Here’s a step-by-step guide to making this transition:
1. Select an AMI
Choose an Amazon Machine Image (AMI) that supports EBS-backed instances. These AMIs should be selected with consideration to the operating system, architecture, and other requirements relevant to your application.
2. Launch the Instance with EBS
Launch a new EC2 instance using the selected EBS-backed AMI. During instance configuration:
- Step 3: Configure Instance Details: Ensure "Delete on Termination" is unchecked for the root EBS volume if you want to preserve data after termination.
- Step 4: Add Storage: Specify the size, type, and IOPS if using provisioned IOPS SSD.
3. Transfer Data from Instance Store to EBS
- Attach the EBS Volume: You can attach a secondary EBS volume and use it to copy data from the instance store, or directly copy data to the EBS root volume, based on the nature of the data and application.
- Use `dd` Command: For low-level block copying from instance store to EBS:
- Performance: EBS-backed instances facilitate snapshots and redundancy strategies but may have different performance characteristics compared to instance store, depending on volume type (e.g., gp3, gp2, io1).
- Cost: Using EBS incurs additional costs as compared to instance store, which is included in the price of the instance type.
- Limitations: Some legacy instance types may not support booting from EBS volumes, necessitating careful instance selection.

