- Consulting
- Training
- Partners
- About Us
x
Amazon’s Elastic Block Store Volumes are easy to use and expand but notoriously hard to shrink once their size has grown. Here are the steps for Shrinking any mounted EBS volume on EC2 Instances.
For various reasons you may need to expand or shrink the size of your EBS volume. Because you are only charged for the space currently allocated to your EBS volumes, it is also cost efficient to allocate only your approximate short term need and expand the volume as the need arises (this should be considered during the planning phase of your projects and/or during formulation of growth strategies for your service).
The below steps have been tested on an Amazon Linux instance to resize an EBS Volume using the AWS console
1 |
ssh -i <Private-key> ec2-user@ip-address |
1 |
sudo mkfs -t ext4 /dev/sdi |
3.Then make a directory at /mnt/ebs1 and mount the new volume using following commands
1 |
sudo mkdir /mnt/ebs1 |
1 |
sudo mount /dev/sdi /mnt/ebs1 |
4. Now copy your data recursively from your source volume to your newly created volume using the following command(Assuming your old volume is mounted at /mnt/ebs)
1 |
sudo cp -r --preserve=all /mnt/ebs/. /mnt/ebs1 --verbose |
Copying data recursively preserves the file attributes such as mode,ownership,timestamps and security contexts, if possible additional attributes such as links.
5. After copying the data detach your old volume and mount your new volume at the same mount point using the following command
1 |
sudo umount -l /mnt/ebs |
1 |
sudo mount /dev/sdi /mnt/ebs |
In order to automate all this process here is the Script which will automate the process
Download the zip from this page https://github.com/cloudthat/ebs-shrink
Extract the zip and navigate to the extracted folder
Step 1: Place the script on the instance with permissions to execute
1 |
scp -i <identity_file> <path-to>/ebsreducescript <user>@<host_name>:/home/ec2-user/. |
Now SSH into the instance using the following command and Update file permissions
1 |
ssh -i <Private-key> ec2-user@ip-address |
1 |
sudo chmod 500 ebsreducescript |
Step 2: Configure AWS Cli
Also before executing the script you need to configure awscli use the following commands to install
1 |
sudo yum install python-pip |
1 |
sudo pip install awscli |
Run aws configure at the command line to set up your credentials and settings.
1 2 3 4 5 |
$ aws configure AWS Access Key ID [None]: ANKITIOSFODNN7EXAMPLE AWS Secret Access Key [None]: ANKITXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY Default region name [None]: us-west-1 Default output format [None]: json |
This Script Will Create a New Volume of User Defined,Mount it to /mnt/ebs1 Copy all the data from the attached EBS Volume recursively that need to be Migrated preserving all the user permissions,then Unmount it and Mount the Newly Created EBS Volume at the Same Mount Point
Note:The migrated volume is not deleted it is just unmounted So if any error occurs we can reattach it. This Script can only use for Attached(Mounted) EBS Volumes not Root Volume.
Voiced by Amazon Polly |
CloudThat is a leading provider of cloud training and consulting services, empowering individuals and organizations to leverage the full potential of cloud computing. With a commitment to delivering cutting-edge expertise, CloudThat equips professionals with the skills needed to thrive in the digital era.
Our support doesn't end here. We have monthly newsletters, study guides, practice questions, and more to assist you in upgrading your cloud career. Subscribe to get them all!
Amazon expands Elastic Block Storage | CloudThat's Blog
Mar 24, 2015
[…] If you want to increase the size of your existing volumes to take advantage of this new feature release, you can resize your current volumes using our previous blog post here. […]
Click to Comment