I’m currently going through a course on Amazon Web Services, taught by ACloud.Guru. His course is specifically focused on preparing students to pass all of the AWS certification exams. The course consists of important theoretical concepts as well as hands on labs.
We have a lab today regarding Upgrading our EBS Volumes. The scenario is as follows:
You have a server running a 22 GB magnetic hard disk drive (HDD). You have been requested to upgrade the hard drive of the server to a high speed SSD drive. You aren’t given a large enough budget to acquire a new physical hard drive and server, so your platform of choice is Amazon Web Services.
Through this lab, we will learn the following:
- Provisioning a Magnetic HDD on an EC2 instance
- Installing a file system using the linux command line interface (CLI)
- Mounting a volume to a directory. (Assigning a directory to a specific mount point)
- Using the Nano Linux Text Editor through the Linux CLI
- Unmounting & Remounting EBS Volumes using the Linux CLI.
- Detaching & Reattaching EBS volumes using the AWS console
- Creating and Restoring Snapshots using the AWS console
To start off, we have to launch an EC2 instance and configure an EBS volume. In the configuration settings, we will select Magnetic to mimic the scenario of our lab.
Now that the Server with the classic magnetic hard drive has been created using EC2, we now log into the machine using SSH, and run the routine updates.
To view the EBS volumes attached to the EC2, do the following:
We can see that there are two volumes, XVDA and XVDF. From the XVDA volume, a logical partition was automatically made by AWS, called XVDA1.. The volume we are concerned with is the 22 gb XVDF volume. If you look to the last colum, you can see that the XVDF volume is NOT mounted to or associated with any directory. The XVDA volume is mounted to the file system (/). Now we need to mount the 22 GB XVDF to a new directory called /testdirectory.
But before we can do that, XVDF needs to be formatted with a file system. Otherwise, we will get an error when trying to mount the directory.
After this, we can make the directory and mount it.
Now you can see the XVDF volume has a mount point of /testdirectory. This means the /testdirectory is now associated with the volume XVDF.
After this, we need to create a test file to see if it will remain after we upgrade this 22 GB EBS volume.
Navigate to the testdirectory, and display the contents, you will find it empty.
The last command was to start the Linux text editor, called NANO. We created a file called text.html.
At the bottom are the commands for the Nano editor. After writing something in the file,quit the Nano Linux text editor by pressing: CTRL-X then ‘Y’ for “yes” to save and quit.
Now comes the juicy part. We will swap out the 22 gb magnetic EBS volume with a high speed SSD EBS volume. We will do this by attaching another EBS volume to the EC2 through the AWS console. Then we will unmount the /testdirectory and remount it to the new volume. And if the test.html file shows up, we know that our little lab worked out and the data remained in tact.
- First we create snapshot of the XVDF volume in the AWS console:
- Then we create a new SSD Provisioned IOPS EBS Volume from the snapshot. *Make sure the volume is in the same Region as the instance, or else you won’t be able to attach the volume.
- Thirdly, we take the new SSD Volume, and attach it to the EC2 instance. Watch and observe if you’re confused by these directions.
After attaching the EBS volume in the AWS console, you should see it in your Linux SSH window by the LSBLK command.
The new volume is called: XVDG. The final step is to remount the /testdirectory to the new XVDG volume. We have to unmount the /testdirectory from XVDF and mount it to XVDG.
We see that the same test.html file is on the newly attached EBS volume XVDG, which means we completed our task and lab.