I have followed several links on Google and on this forums to reduce EBS Volumes on Amazon AWS, including these links too:
http://wiki.jokeru.ro/shrink-amazon-ebs-root-volume
and
http://www.lantean.co/shrinking-ebs-volume/
I have a 254 GB EBS Volume which needs to be resized to 150 GB. Here are the steps what I did:
- Create a new instance with 8 GB volume /dev/xvde (base OS)
- Mount 254 GB Volume /dev/xvdj on base OS.
- Mount 150 GB empty Volume /dev/xvdk on base OS.
- /dev/xvdj has 8 partitions as follows:
Disk /dev/xvdj: 272.7 GB, 272730423296 bytes 255 heads, 63 sectors/track, 33157 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00029527 Device Boot Start End Blocks Id System /dev/xvdj1 * 1 13 102400 83 Linux Partition 1 does not end on cylinder boundary. /dev/xvdj2 13 6540 52428800 83 Linux /dev/xvdj3 6540 10457 31457280 83 Linux /dev/xvdj4 10457 33114 181998592 5 Extended /dev/xvdj5 10457 11501 8388608 82 Linux swap / Solaris /dev/xvdj6 11501 12154 5242880 83 Linux /dev/xvdj7 12154 12285 1048576 83 Linux /dev/xvdj8 12285 33114 167314432 83 Linux
- Since /dev/xvdk is empty volume, it has no partition, which i suppose has to be created according to /dev/xvdj
- According to the links above, I ran e2fsck -f /dev/xvdj1, followed by resize2fs -M -p /dev/xvdj1, for all the partitions on /dev/xvdj (except /dev/xvdj4 and 5)
- After the above command is completed, I created partitions on /dev/xvdk volume according to the requirements, keeping in mind about the sizes which will be greater than the partitions of /dev/xvdj
- The partitions of 150 GB Volume is as follows:
Disk /dev/xvdk: 161.1 GB, 161061273600 bytes 255 heads, 63 sectors/track, 19581 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0xeea3d8c8 Device Boot Start End Blocks Id System /dev/xvdk1 * 1 132 1060258+ 83 Linux /dev/xvdk2 133 9271 73409017+ 83 Linux /dev/xvdk3 9272 17105 62926605 83 Linux /dev/xvdk4 17106 19581 19888470 5 Extended /dev/xvdk5 17106 18150 8393931 82 Linux swap / Solaris /dev/xvdk6 18151 19456 10490413+ 83 Linux /dev/xvdk7 19457 19581 1004031 83 Linux
- For the first partition, I also added a bootable flag using fdisk /dev/xvdk and selecting a and partition number (which is 1)
- After partitions, I followed the above links to count the blocks, issuing the dd command to copy data.
- When the dd command was completed, I ran e2fsck -f /dev/xvdk1, followed by resize2fs -p /dev/xvdk1, for all the partitions on /dev/xvdk (except /dev/xvdk4 and 5)
- After completing the above command, I powered off the base OS and then detached the 150 GB Volume.
- I created a snapshot of the the 150 GB Volume, and after the snapshot was created, I created an image (AMI) out of that snapshot.
- I used this image to launch an instance, to which I was successfull, but after launching I am unable to connect to that instance.
- Also, 1 of the 2 status checks were throwing an error about connectivity, which I am unable to investigate where could I have gone wrong.
Can someone tell me where I have gone wrong or Am I completely off the track?
Advertisement
Answer
I have found out an elegant solution which was present in the knowledge base of AWS.
The link is here: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/storage_expand_partition.html#expanding-partition-parted
It makes use of parted tool.
NOTE: You need to attach the volume to a different instance in order to resize it.