{"id":3556,"date":"2021-10-12T11:10:30","date_gmt":"2021-10-12T11:10:30","guid":{"rendered":"https:\/\/www.deftboxsolutions.com\/blog\/?p=3556"},"modified":"2021-11-08T12:38:18","modified_gmt":"2021-11-08T12:38:18","slug":"how-to-reduce-externally-attached-ebs-volume-size","status":"publish","type":"post","link":"https:\/\/www.deftboxsolutions.com\/blog\/how-to-reduce-externally-attached-ebs-volume-size\/","title":{"rendered":"How to reduce EBS volume size in AWS"},"content":{"rendered":"<p>Sometimes we attach large volumes while launching AWS EC2 instance, later to realise only that we don&#8217;t need large size and need to decrease it.<\/p>\n<p>There&#8217;s no option in AWS console to perform the same but with a small trick we can achieve the same.<\/p>\n<p>In this article, we&#8217;ll see detailed steps to do that. The task follow below steps.<\/p>\n<ol class=\"\">\n<li id=\"06c9\" class=\"hl hm fv hn b ho ik hp hq hr il hs ht hu im hv hw hx in hy hz ia io ib ic ie ip iq ir gs\" data-selectable-paragraph=\"\">Take snapshot the current volume (let&#8217;s say it&#8217;s 9 GB for this article)<\/li>\n<li id=\"d69d\" class=\"hl hm fv hn b ho is hp hq hr it hs ht hu iu hv hw hx iv hy hz ia iw ib ic ie ip iq ir gs\" data-selectable-paragraph=\"\">Create a new smaller EBS volume (let&#8217;s say it&#8217;s 7 GB for this article)<\/li>\n<li id=\"2769\" class=\"hl hm fv hn b ho is hp hq hr it hs ht hu iu hv hw hx iv hy hz ia iw ib ic ie ip iq ir gs\" data-selectable-paragraph=\"\">Attach the new (smaller) volume<\/li>\n<li id=\"f4cb\" class=\"hl hm fv hn b ho is hp hq hr it hs ht hu iu hv hw hx iv hy hz ia iw ib ic ie ip iq ir gs\" data-selectable-paragraph=\"\">Mount the new (smaller) volume<\/li>\n<li id=\"6dbe\" class=\"hl hm fv hn b ho is hp hq hr it hs ht hu iu hv hw hx iv hy hz ia iw ib ic ie ip iq ir gs\" data-selectable-paragraph=\"\">Copy data from old (larger) volume to the new (smaller) volume<\/li>\n<li id=\"65ce\" class=\"hl hm fv hn b ho is hp hq hr it hs ht hu iu hv hw hx iv hy hz ia iw ib ic ie ip iq ir gs\" data-selectable-paragraph=\"\">Detach and unmount old (larger) volume<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p>In below screen, we can see that we already have volume attached to instance and size is 9 GB.<\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-3558 \" src=\"https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/2.png\" alt=\"\" width=\"922\" height=\"407\" srcset=\"https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/2.png 1121w, https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/2-300x132.png 300w, https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/2-1024x452.png 1024w, https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/2-768x339.png 768w, https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/2-650x287.png 650w, https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/2-624x276.png 624w\" sizes=\"(max-width: 922px) 100vw, 922px\" \/><\/p>\n<p>You can see that volume is mounted in a server under \/mnt\/Big_Volume and have some dummy files in it also.<\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-3559\" src=\"https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/3.png\" alt=\"\" width=\"750\" height=\"279\" srcset=\"https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/3.png 526w, https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/3-300x112.png 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-3565 size-full\" src=\"https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/1-1.png\" alt=\"\" width=\"813\" height=\"250\" srcset=\"https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/1-1.png 813w, https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/1-1-300x92.png 300w, https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/1-1-768x236.png 768w, https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/1-1-650x200.png 650w, https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/1-1-624x192.png 624w\" sizes=\"(max-width: 813px) 100vw, 813px\" \/><\/p>\n<p>Showing fstab entry for this volume.<\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-3566 size-full\" src=\"https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/2-1.png\" alt=\"\" width=\"902\" height=\"146\" srcset=\"https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/2-1.png 902w, https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/2-1-300x49.png 300w, https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/2-1-768x124.png 768w, https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/2-1-650x105.png 650w, https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/2-1-624x101.png 624w\" sizes=\"(max-width: 902px) 100vw, 902px\" \/><\/p>\n<p>NOW WE WANT TO REDUCE THE SIZE FROM <strong>9 GB TO 7 GB<\/strong>.<\/p>\n<p>Create another volume of 7 GB and attach it to the instance. It&#8217;s needless to say that you have to create another volume in the same region.<\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-3567 \" src=\"https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/3-1.png\" alt=\"\" width=\"924\" height=\"443\" srcset=\"https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/3-1.png 1122w, https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/3-1-300x144.png 300w, https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/3-1-1024x491.png 1024w, https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/3-1-768x368.png 768w, https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/3-1-650x312.png 650w, https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/3-1-624x299.png 624w\" sizes=\"(max-width: 924px) 100vw, 924px\" \/><\/p>\n<p>Attach this volume to an already running instance.<\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-3568\" src=\"https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/4.png\" alt=\"\" width=\"750\" height=\"271\" srcset=\"https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/4.png 715w, https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/4-300x108.png 300w, https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/4-650x235.png 650w, https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/4-624x225.png 624w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/p>\n<p>Now login into the instance and execute below command :<\/p>\n<ul>\n<li>$ <strong>sudo fdisk -l<\/strong><\/li>\n<\/ul>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-3569\" src=\"https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/5.png\" alt=\"\" width=\"751\" height=\"167\" srcset=\"https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/5.png 634w, https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/5-300x67.png 300w, https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/5-624x139.png 624w\" sizes=\"(max-width: 751px) 100vw, 751px\" \/><\/p>\n<p>Next step is to create the filesystem. Use below command.<\/p>\n<ul>\n<li><strong>$ sudo mkfs -t xfs \/dev\/xvdg<\/strong><\/li>\n<\/ul>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-3570 size-full\" src=\"https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/6.png\" alt=\"\" width=\"835\" height=\"262\" srcset=\"https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/6.png 835w, https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/6-300x94.png 300w, https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/6-768x241.png 768w, https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/6-650x204.png 650w, https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/6-624x196.png 624w\" sizes=\"(max-width: 835px) 100vw, 835px\" \/><\/p>\n<p>Create any Directory where you want to mount this Volume. <strong>i.e. : \/mnt\/New_Small_Volume<\/strong><\/p>\n<p>Using blkid and \/etc\/fstab complete your mount process.<\/p>\n<ul>\n<li><strong>$ sudo blkid <\/strong><\/li>\n<\/ul>\n<p>Copy the UUID of <strong>xvdg<\/strong> and edit your \/etc\/fstab.<\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-3571 size-full\" src=\"https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/7.png\" alt=\"\" width=\"963\" height=\"168\" srcset=\"https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/7.png 963w, https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/7-300x52.png 300w, https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/7-768x134.png 768w, https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/7-650x113.png 650w, https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/7-624x109.png 624w\" sizes=\"(max-width: 963px) 100vw, 963px\" \/><\/p>\n<p>Next is to prepare the volume for mount : $ <strong>sudo mount -a<\/strong><\/p>\n<p>And using <strong>lsblk<\/strong> command we can verify our smaller volume.<\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-3572\" src=\"https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/8.png\" alt=\"\" width=\"750\" height=\"238\" srcset=\"https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/8.png 601w, https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/8-300x95.png 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/p>\n<p>Next step is to copy the date from larger volume to smaller volume.<\/p>\n<ul>\n<li>$ <strong>sudo rsync -HAXxSPa \/source\/ \/Target<\/strong><\/li>\n<\/ul>\n<ul>\n<li><strong>i.e : <\/strong>sudo rsync -HAXxSPa \/mnt\/Big_Volume\/ \/mnt\/New_Small_Volume<\/li>\n<\/ul>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-3573 size-full\" src=\"https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/9.png\" alt=\"\" width=\"928\" height=\"307\" srcset=\"https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/9.png 928w, https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/9-300x99.png 300w, https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/9-768x254.png 768w, https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/9-650x215.png 650w, https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/9-624x206.png 624w\" sizes=\"(max-width: 928px) 100vw, 928px\" \/><\/p>\n<p>you can see data is available in smaller volume.<\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-3574 size-full\" src=\"https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/10.png\" alt=\"\" width=\"816\" height=\"168\" srcset=\"https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/10.png 816w, https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/10-300x62.png 300w, https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/10-768x158.png 768w, https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/10-650x134.png 650w, https:\/\/www.deftboxsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/10-624x128.png 624w\" sizes=\"(max-width: 816px) 100vw, 816px\" \/><\/p>\n<p>Now we need to delete the \/etc\/fstab entry for larger volumer and then we can detach is from console and delete it.<\/p>\n<p>Make sure you delete the entry from the<strong> fstab <\/strong>otherwise instance will not be able to start again once it&#8217;s stopped.<\/p>\n<h1 id=\"6e76\" class=\"ix iy fv bb da iz ja hp jb jc jd hs je jf jg jh ji jj jk jl jm jn jo jp jq jr gs\" data-selectable-paragraph=\"\">Conclusion<\/h1>\n<p id=\"5aa0\" class=\"hl hm fv hn b ho js hp hq hr jt hs ht hu ju hv hw hx jv hy hz ia jw ib ic ie dn gs\" data-selectable-paragraph=\"\">We cannot decrease the size of EBS volume directly but we can create a new smaller volume and move the data.<\/p>\n<p id=\"0b95\" class=\"hl hm fv hn b ho ik hp hq hr il hs ht hu im hv hw hx in hy hz ia io ib ic ie dn gs\" data-selectable-paragraph=\"\">Hope this article will help! Please write your suggestions\/feedback in comment section.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes we attach large volumes while launching AWS EC2 instance, later to realise only that we don&#8217;t need large size and need to decrease it.<\/p>\n","protected":false},"author":2,"featured_media":3602,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[57,46],"tags":[61,62,59,60,58],"_links":{"self":[{"href":"https:\/\/www.deftboxsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/3556"}],"collection":[{"href":"https:\/\/www.deftboxsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.deftboxsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.deftboxsolutions.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.deftboxsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=3556"}],"version-history":[{"count":12,"href":"https:\/\/www.deftboxsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/3556\/revisions"}],"predecessor-version":[{"id":3561,"href":"https:\/\/www.deftboxsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/3556\/revisions\/3561"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.deftboxsolutions.com\/blog\/wp-json\/wp\/v2\/media\/3602"}],"wp:attachment":[{"href":"https:\/\/www.deftboxsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=3556"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.deftboxsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=3556"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.deftboxsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=3556"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}