Create And Mount Amazon AWS EC2 EBS Storage To AWS EC2 Linux Instance

Amazon’s AWS products are pretty amazing and allow you to scale with ease for short or long term projects. One thing that can be helpful is mounting extra storage to AWS instances so you have the ability to unmount the storage and mount to different instances in the future. The other benefit is the ability to terminate an Amazon AWS instance and keep the Elastic Block Store (EBS) volume to use on another AWS instance at a later date. Use the directions below to create an Amazon EC2 EBS volume, attach the volume to an Amazon AWS instance, format the volume, and then mount the volume to the instance.

Create Amazon AWS EC2 Elastic Block Store Volume:

Amazon’s Elastic Block Store volumes or EBS volumes can be thought of as hard drive space that you are reserving such as an external hard drive located on AWS for you to mount or unmount at any time you like to any instance within the same location. Make sure location is considered before creating the EBS volume and adding data to the volume. EBS volumes must be in the same exact location as the instance so the AWS region is not enough. Take for instance an EBS volume located in US East Virginia us-east-1A cannot be mounted to an AWS instance located in US East Virginia us-east-1B. You would need to create the EBS instance in the us-east-1c location to be able to mount the storage or EBS volume to a AWS EC2 GPU instance that is also running in us-east-1c. If you want storage that can be mounted across locations then you should consider AWS S3 storage however the speeds will be much different than mounting an AWS EBS volume from the same location.

  1. Login To AWS: First login to your AWS management console located at https://aws.amazon.com.
  2. AWS EC2 Console Dashboard: Click on Ec2 in the list of AWS products or if you are already logged in click Ec2 in the top navigation bar which will take you to the EC2 Console Dashboard as shown in the below example image.
    Amazon AWS EC2 Console DashboardMake sure that you select the correct region once the EC2 Console Dashboard is displayed similar to the above example image. Again the AWS EC2 EBS volume must be in the exact location as the AWS Ec2 instance you want to mount to.
  3. Elastic Block Store Volumes: Now click Volumes located in the left navigation underneath Elastic Block Store to open the list of EBS volumes associated to your account in this specific region as shown in the below example image.
    Amazon EC2 Elastic Block Store VolumesNotice in the above example I have a single 100GB EBS volume where I am storing some wordlists and oclHashcat items that I use for password cracking.
  4. Create EBS Volume: Click the Create Volume button located in the top left corner of the center column of the Elastic Block Store Console Dashboard window which will launch the below EBS volume creation wizard.
    Amazon EC2 EBS Create Volume WizardSimply fill in the details for your new Elastic Block Store volume as shown in the below example image. Again I want to note that the volume must be created in the exact location of the AWS EC2 instance you want to mount to. So keep in mnind that if the EBS volume is created in us-east-1a it will not be able to be mounted to a EC2 instance located in us-east-1b.
    Create Elastic Block Store Volume WizardOnce the details have been entered click the Yes, Create button to create the EBS volume. Once the Yes, Create button is clicked the Create EBS Volume wizard will close and the new EBS volume will display in the list of Elastic Block Store volumes located in this AWS location as shown in the below example image.
    List Of EBS Volumes

You now have created an Amazon Elastic Block Store volume that can be formatted and mounted to an Amazon AWS EC2 instance. Below are the instructions for formatting and mounting the volume to an AWS EC2 instance.

Format & Mount Elastic Block Store Volume To AWS EC2 Instance:

Keep in mind that during this example we are mounting EBS volumes to Linux AWS instances.

  1. Attach EBS Volume To Instance: Once you have an existing volume the first thing you need to do is attach the EBS volume to the instance where you want to mount it. This can be accomplished by right clicking on the EBS volume and clicking AttachVolume from the menu that appears as shown in the below example image.
    Attach EBS Volume To InstanceOnce you select Attach Volume the below window will appear over top of the list of EBS volumes.
    AWS EC2 Attach Volume WizardSelect the Instance you want to attach the EC2 Elastic Block Store volume to as shown in the below example image.
    Attach Volume Instance SelectedClick the Yes, Attach button to attach the EBS volume to the instance you selected. Once the volume is attached the list of volumes will now display the volume attached to the instance as shown in the below example image.
    EBS Volume Attached
  2. Login To AWS Instance:Next login to the AWS instance where you attached the EBS volume. You can see that the new EBS volume is attached to the instance by using fdisk as shown in the below example output. In this case the new volume is attached as /dev/xvdf shown below with roughly 10GB of space.Use fdisk To Display Attached Volumes:
    [root@ip-10-16-18-55 ~]# fdisk -l
    
    Disk /dev/hda: 21.4 GB, 21474836480 bytes
    255 heads, 63 sectors/track, 2610 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/hda1   *           1          13      104391   83  Linux
    /dev/hda2              14        2610    20860402+  8e  Linux LVM
    
    Disk /dev/xvdb: 901.8 GB, 901875499008 bytes
    255 heads, 63 sectors/track, 109646 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    
    Disk /dev/xvdb doesn't contain a valid partition table
    
    Disk /dev/xvdc: 901.8 GB, 901875499008 bytes
    255 heads, 63 sectors/track, 109646 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    
    Disk /dev/xvdc doesn't contain a valid partition table
    
    Disk /dev/xvdf: 10.7 GB, 10737418240 bytes
    255 heads, 63 sectors/track, 1305 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    
    Disk /dev/xvdf doesn't contain a valid partition table
    [root@ip-10-16-18-55 ~]#
    
  3. Format New EBS Volume:You only need to format the volume the first time you use it so this step can be skipped next time you want to mount the volume to another instance. Use mkfs to format the EBS volume as ext3 shown in the example syntax below.Format EBS Volume As ext3 Using mkfs On Linux AWS Instance:
    [root@ip-10-16-18-55 ~]# mkfs -t ext3 /dev/xvdf
    mke2fs 1.39 (29-May-2006)
    Filesystem label=
    OS type: Linux
    Block size=4096 (log=2)
    Fragment size=4096 (log=2)
    1310720 inodes, 2621440 blocks
    131072 blocks (5.00%) reserved for the super user
    First data block=0
    Maximum filesystem blocks=2684354560
    80 block groups
    32768 blocks per group, 32768 fragments per group
    16384 inodes per group
    Superblock backups stored on blocks:
            32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
    
    Writing inode tables: done
    Creating journal (32768 blocks): done
    Writing superblocks and filesystem accounting information: done
    
    This filesystem will be automatically checked every 22 mounts or
    180 days, whichever comes first.  Use tune2fs -c or -i to override.
    [root@ip-10-16-18-55 ~]#
    
  4. Make Directory & Mount EBS Volume:First create a directory to mount the EBS volume to such as “/mnt/ebs-volume” and then mount the volume use the mount command within Linux. Below there is example output showing a directory being created and the EBS volume being mounted to the new directory.Create New Directory & Mount AWS EBS Volume To Linux AWS Instance:
    [root@ip-10-16-18-55 ~]# mkdir /mnt/ebs-volume
    [root@ip-10-16-18-55 ~]# mount /dev/xvdf /mnt/ebs-volume/
    [root@ip-10-16-18-55 ~]#
    [root@ip-10-16-18-55 ~]# df -kh
    Filesystem            Size  Used Avail Use% Mounted on
    /dev/mapper/VolGroup00-LogVol00
                          9.9G  3.7G  5.8G  39% /
    /dev/hda1              99M   13M   82M  14% /boot
    tmpfs                  11G     0   11G   0% /dev/shm
    /dev/sdf              9.9G  151M  9.2G   2% /mnt/ebs-volume
    [root@ip-10-16-18-55 ~]#
    

    Notice that when we issue “df -kh” from the Linux command line that the volume is now mounted and can be used from the Amazon Linux instance.

Thats it. You can create and mount as many volumes as you like to each instance.


List Price: $39.95 USD
New From: $2.90 USD In Stock
Used from: $2.34 USD In Stock

Programming Amazon EC2 (Paperback)

By (author): Jurg van Vliet, Flavia Paganelli


List Price: $34.99 USD
New From: $19.16 USD In Stock
Used from: $8.70 USD In Stock

Share