Sometimes you need to rescue the data stored on AWS EBS volume that is attached to an original Amazon EC2 instance in your production environment. In case the instance is terminated or inaccessible, you can still access the data stored on that Instance EBS. The following steps are useful when handling a failure scenario:
- You need to detach the volume from the original EC2 instance after stopping it.
- Attach the same volume to the newly launched EC2 instance.
- After remounting the volume, the data can be easily accessible.
The Step-By-Step Re-Mounting ProcessAmazon Elastic Block Store (Amazon EBS) allows us to create storage volumes and attach them to Amazon EC2 instances. You can attach and detach the EBS volume to any EC2 instance and mount it after creating a file system on top of these volumes. Below is the detailed step-by-step process for re-mounting EBS volume to Amazon EC2 instance. Attaching EBS Volume to EC2 Instance
- Open AWS Console.
- Click the Volume section within AWS console under the EC2 dashboard.
- Select the EBS Volume that you want to attach to an EC2 instance. The EBS volume should be in available status.
- Enter the Instance ID or the Instance name. Make sure that the Amazon EBS volume and the Amazon EC2 instance are in the same availability zone.
- After attaching the volume, you will be able to see identical block devices for an EC2 instance.
- Congratulations ! You have successfully attached the Amazon EBS volume to an Instance. Now you need to ssh to the instance and mount the device to a mount directory.
- How To Mount EBS VolumeLog in to an instance through ssh and list the disk attached to the instance by using the command: fdisk -l
- Depending on the block device or driver of the kernel, the device might be attached with a different name than what you specified. For example, if we specify a device name of /dev/sdf, our device might be renamed /dev/xvdf by the kernel. In most cases, the trailing letter remains the same.
- List the block device by using the command: lsblk
- Check the file system on the attached volume: file -s /dev/xvdf
- EBS volumes restored from snapshots often have a file system on them already. If it’s not a new volume, we need to create a file system for them before we can mount them. We can do this by using: mkfs.ext4 /dev/xvdf
- Create a mount directory where you want to mount the device: mkdir /mountdir
- Open the /etc/fstab file and add a new line at the end of file, as demonstrated in the screenshot below. Adding this entry is important. This will make sure even after rebooting the instance directory, mounting will begin.device_name mount_point file_system_type fs_mntops fs_freq fs_passn /dev/xvdf /mountdir ext4 defaults, nofail 0 2
- Run below-mentioned mount command to mount all of the filesystems in /etc/fstab file. mount -a
- Check the disk’s free space by using the command below df -h Congratulations! You can see the /dev/xvdf device size and also see that it’s mounted on mountdir.Amazon EBS Re-Mounting Best PracticesUsing EBS is easy. However, there are few things that needs to be taken care of while re-mounting the EBS to an EC2 Instance.
- You must unmount the volume before you detach it.
- If the EBS volume is inside the root device of an instance then you must stop the original EC2 instance before detaching the volume.
- Make sure that the EBS volume and new instances the same availability zone.
- Make sure to check how many volumes you can attach to your instance. It depends on your operating system. (refer to http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/volume_limits.html)
- Volumes that have been restored from snapshots, or have already been attached to an instance, likely have a file system on them. if you create a new file system on the top of an existing file system, the operation overwrites your data. So, only in the case of a new volume, should you create a file system.
Connecting a Volume with Windows server:Let’s assume that we have a Windows 2012 server already launched with 30GB of EBS volume, and we would like to add another EBS volume of 30GB. First we need to detach the volume from current instance. To do so using AWS console, we need to go to Volumes tab, select the volumes, and detach the volume from the previous instance. This can be done with the AWS CLI command as well. $aws ec2 detach volume –volume-id vol-5erd004ar After detaching the volume, we attach the volume to current Windows instances: Selecting the instance to attach with newly created volume. The volume is now attached to the windows instance, but the newly attached volume is not working yet. To bring that volume online and define a new Drive letter, we have to log in to our Windows instance. From the windows server, managerclick on the stat menu open ‘Server Manager’. From Manager, you can navigate to ‘File and Storage Services’ => ‘Volumes’ à Disks: Bringing online the new volume simply right click on the volume: After getting online, right click on volume and select ‘New Volume’: Click ‘Next’ to begin the process of defining a new drive letter: ‘Disk1′ is the newly created volume of 30GB. Click Next’ to proceed: Specify the size and click ‘Next’: Specify the drive letter: When you reach the File system setting ‘NTFS’, click ‘Next’: ‘Create’ will create the new volume drive letter which is ‘D:\’ and brings it online with the current instance: The new volume is attached with Windows instance as ‘New Volume (D: ). Extend the volume in the Windows server:
- We need to log into our Windows server using Remote Desktop
- Once we are in our Windows server, we will select Server Management and then Disk Management.