Learn how to demonstrate attaching and reattaching EBS volumes while preserving data and encryption state.
- [Instructor] In this video I'm going to demonstrate how we can detach the EBS volume from this Instance and attach it to another. In order to show this functionality, I'm going to need a second EC2 Instance. So, I'm going to head back to the EC2 dashboard and click Launch Instance. I'm going to select all the same options as I did for the original Instance except I'm not going to give it a second EBS volume and it's name will be EBSDemo2. It can have the default open to the world port 22 security group.
And, we'll go ahead and launch. This time I used the demo key that I already have, demo-ssh-key. Back on the EC2 console you can see that EBSDemo2 Instance is initializing. Also, take note that it's in the same availability zone as the first one. This is important because EBS snapshots are exclusive to an AZ. While we're waiting for the second Instance to initialize I'm going to head to the first Instance via an ssh console.
There's one important step that we need to follow before we can detach this EBS Instance and that is we need to unmount the volume from the file system. And, we use sudo again instead of saying mount we'll say umount. Be careful you don't type unmount but rather umount -d and then the volume name, xvdb. This will unmount the volume from the file system. Observe that it's no longer visible in the disc free command. And so we exit. Back on the EC2 console let's hit refresh and see if that Instance is available to login yet.
Once this initializing status changes to two two checks passed, we're good to go. Okay, now that the EBSDemo2 machine is available click on the details, highlight it's IP Address and we'll login to it. Choose Yes if you get this prompt. Now if we take a look at the disc free command, you'll see what we're starting with. The root volume xvda1 which is likely a partition of a volume called xvda. Let's head back to the EC2 console.
Even though we've unmounted the 10 gigabyte volume from our first Instance it's still attached. So, let's take a look at what we can do about that. We'll check the box next to EBSDemo1 and, again, scroll down on the Description window to Block Devices. Clicking on SDB here we can follow the link to the Volume ID. Here you can see if you scroll over Attachment Information. State is In-use and this is the link back to our Instance. We need to go to Actions and Detach Volume.
Are we sure? Say Yes. In a moment this state will change and we'll see that we can reattach the volume. If you like you can press refresh button here on the top right. You can now see that the volume is available. So even though it's still called EBSDemo1, as I said that name can be changed under Tags, we can attach it to a different Instance. Choose Actions, Attach Volume. Here we have the Volume ID and the Instance. Fortunately we don't have to go fetch the Instance ID, it will pop up for us.
We want to attach this volume to EBSDemo2. You can see that we're given a default device name of sdf which will be fine. Click Attach. Now we'll head back to the console now that this EBS volume is attached and see what's going on on our Instance. df -h as usual doesn't show anything new. But, if we do lsblk we'll see that we have the new volume, xvdf. And, by now you should recognize that that's likely to be a symbolic link. We'll look at dev/sdf to confirm.
And, there it is. So now that we have xvdf as a block device, we want to look at the file command. Do we need to format this drive? No. You can see that we don't get just the word data back, but we get the Linux revision 1.0 ext file system. And, that makes sense because this isn't a brand new EBS volume it's one that we detached and reattached from before when we already formatted it. In fact, we can expect that all of our files will be retained there. But, before we do that we, of course, need to mount this file system.
Before we can mount anything we need to create a folder to be the mount point. Again, we'll do sudo mkdir to make a directory and we'll call it ebs-reattached. Now that we have that folder we can use the sudo mount command. To mount dev/xvdf to the new folder. Now, let's go take a look. And, there it is. The hello.text file that we created on the original Instance EBSDemo1.
And you can see that not only is the file in tact but so are the ownership permissions. And that's how you detach and reattach an EBS volume.
Join AWS architect Brandon Rich and learn how to configure object storage solutions and lifecycle management in Simple Storage Service (S3), a web service offered by AWS, and migrate, back up, and replicate relational data in RDS. Find out how to leverage flexible network storage with Elastic File System (EFS), and use the new AWS Glue service to move and transform data. Plus, learn how Snowball can help you transfer truckloads of data in and out of the cloud.
- What is data management?
- AWS S3 basics
- S3 bucket creation
- S3 upload and logging
- S3 event notifications
- S3 data lifecycle configuration
- Working with Amazon Elastic Block Store volumes
- Creating and mounting an EFS
- Creating an AWS RDS instance
- RDS backup and recovery
- Moving data with AWS Database Migration Service
- Moving data with Data Pipeline and Glue