Friday 19 August 2016

Mount a Secondary volume to an EC2 instance

How to Mount a Secondary Volume to an EC2 instance

There are times when you need to mount a secondary storage to the EC2 instance.
Here is the example is of an instance  on which the root volume is of 8GB and the secondary volume is of 500GB.

Points to remember:

  • The instance on which we are attaching should be in stopped state.
  • The volume we need to attach should be available to use (not attached to some other instance).
  • The volume and the EC2 instance should be in the same region.

Steps:

  • Stop the running instance, to which volume needs to be attached.
  • Make sure the volume to be attached is available for use.
  • Attach the volume to the required instance from AWS console.
  • Give the volume a "Device Name" which could be /dev/sda1 or /dev/xvda for attaching as a root volume and /dev/sdb or /dev/xvdf for attaching as a secondary volume. More details of naming a device can be found here.
  • After attaching it, start the instance.
  • SSH into the instance and follow the below steps to mount the volume and make it available for use.
    • Run the command to see if the volume is attached.
      sudo fdisk -l
    • After running the above command you will see two volume which with device name changed. For example /dev/sda could become /dev/xvde or /dev/sdb would become /dev/xvdf and /dev/sdc would become/dev/xvdg. Depending upon the kernel being used, it renames the volume internally.
    •  Create a directory in /mnt/
      sudo mkdir /mnt/myvol
    • Give appropriate permission to /mnt/myvol with chmod command
    • Now mount the volume (Assuming the volume has been renamed to /dev/xvdf1)
      sudo mount /dev/xvdf1 /mnt/myvol      #This is in case of CnetOS
      sudo mount /dev/xvdf1 /mnt/myvol -t ext4     #This is in case of Ubuntu
    •  The volume is mounted now and you can access the content inside it like cd /mnt/myvol/home/myuser/myfile
  • To unmount the volume run the following command (Make sure that the volume is not busy for example you have not cd into the volume's directory)
    sudo umount /dev/xvdf1  

0 comments:

Post a Comment

 

Copyright @ 2013 Appychip.

Designed by Appychip & YouTube Channel