Friday, 29 March 2019

How to persist root volume of a running EBS-backed EC2 instance By Raj Gupta

By default, the DeleteOnTermination attribute for the root volume of an instance is set to true, but it is set to false for all other volume types. 



So to persist root volume of a running EBS-backed EC2 instance use below step:-

1. You can see in below picture for my production running EC2 server Delete on termination value is True



But I want to make value Delete on termination = false,So that if our EC2 server delete then it will not going to delete root volume.


2. Now take any Linux or Window system in which AWS CLI is already installed..
In my case I am taking Linux system 

Save the below content in the file mapping.json


[root@ip-172-31-85-11 ~]# vi mapping.json

[
  {
    "DeviceName": "/dev/xvda",     This is your root device type of my production server
    "Ebs": {
      "DeleteOnTermination": false      Here we are setting value as false for our production server
    }
  }
]

After saving the file mapping.json run the below AWS CLI command


[root@ip-172-31-85-11 ~]# aws ec2 modify-instance-attribute --instance-id i-0694f343c5515ce78 --block-device-mappings file://mapping.json

i-0694f343c5515ce78 -----This is instance id of our production server 


3. Now you are able to see Delete on termination = false  in the below picture for our production server,






Note:- 

If you want to preserve your root volume at the time of EC2 creation then just in the Add Storage section during creation of EC2 server unchecked the box of  Delete on termination  as shown in below pic ..in my case it is checked, just you need to unchecked it.




No comments:

Post a Comment