How to move EBS volume to a different EC2 Instance within the same availability zone

Steps:

  1. Unmount volume from Instance 1
  2. Remove entry from fstab
  3. Detach volume from Instance 1
  4. Attach volume to Instance 2
  5. Create mount point
  6. Mount volume
  7. Add entry to fstab

SSH into EC2 Instance 1 and identify the volume that you would like to move to Instance 2. In the below example, I have moved xvdg mounted on /u02.

Unmount the volume using umount command.

Remove volume uuid from /etc/fstab file.

Login to the AWS Management console and open volumes under EC2 dashboard and identify the volume that you need to move. Right click on the volume and choose Detach Volume.

You will see the confirmation message shown as below. Choose Yes,Detach to detach the volume from EC2 Instance 1.

The State of the volume changes from in-use to available. Now, this volume can be attached to any EC2 instance within the same availability zone.

Right click on the volume and choose Attach Volume to attach the volume to EC2 Instance 2.

Select the EC2 Instance that you would like to attach the volume to and choose Attach.

SSH into EC2 Instance 2. You will notice that the volume can be seen using lsblk command. Verify if the file system exists on the volume with the command file -s /dev/xvdf.

Create the mount point /u01 using command mkdir /u01 and mount the volume using command mount /dev/xvdf /u01

Finally query the uuid using command blkid and add an entry into /etc/fstab to automatically mount the volume after server reboot.