Search code examples
mysqlamazon-web-servicesamazon-ec2amazon-ebs

switch ebs volume between instance


Here is the situation

In instance A , have EBS volume where my mysql db data located was created based on this http://qugstart.com/blog/amazon-web-services/how-to-set-up-db-server-on-amazon-ec2-with-data-stored-on-ebs-drive-formatted-with-xfs/

I want to move db into separate instance B so I have created instance and installed Mysql already.

Both instances and volume were in same region.

My question here was if I detach ebs volume from instance A and attach to instance B will work automatically or do I have to make any precaution steps?


Solution

  • If you are following the instructions from the link/blog. You don't have to shutdown the instance to detach the EBS volume. You only need to shutdown your EC2 instance if your EC2 volume is the root volume. i.e /dev/sda1 /dev/sda /dev/xvda

    Having said that, you do need to shutdown your mysql service on instance A before detaching the volume:

    service mysqld stop
    

    Then you can bring up another instance B and then attach the EBS volume where your data is and then mount it. (Assuming you are attaching to /dev/sdh or /dev/xvdh)

    echo "/dev/sdh /vol xfs noatime 0 0" | sudo tee -a /etc/fstab
    sudo mkdir -m 000 /vol
    sudo mount /vol