{"id":797,"date":"2016-09-01T17:08:53","date_gmt":"2016-09-01T12:08:53","guid":{"rendered":"http:\/\/www.stonemillkids.com\/?p=797"},"modified":"2016-09-24T23:53:14","modified_gmt":"2016-09-24T18:53:14","slug":"changing-aws-disk-size","status":"publish","type":"post","link":"http:\/\/www.stonemillkids.com\/index.php\/2016\/09\/01\/changing-aws-disk-size\/","title":{"rendered":"Changing the Disk Size of your AWS Instance"},"content":{"rendered":"<p>I do not want to pay more using more space than I need, so in this post I am going to reduce my disk size on the AWS EC2 instance to use less disk space. Let me start off by saying I do not know if AWS charges for &#8220;empty&#8221; space on their drives. \u00a0If they don&#8217;t then reducing your hard drive size is not really needed. \u00a0However, since I cannot determine that, forward ho!<\/p>\n<p>It should also be noted that this procedure could be used for creating a larger drive as well,\u00a0with a couple of minor changes.\u00a0 There are lots of blog posts on that, but not so many that instruct you to reduce the size.<\/p>\n<p>Once question you might ask is where did the &#8220;big&#8221; disk drive come from? \u00a0When I was tying to recover my AWS snapshot, I accidently added more disk space than I wanted. \u00a0Granted I only went from 8G to 100G, but I wanted to determine how to change the\u00a0disk size of my root Linux partition. \u00a0 As always, I ran into a couple of hiccups, but was able to get it to work once I stopped blindly copying instructions on other websites and really tried to understand what they were doing.<\/p>\n<p>The best articles I found via research I listed below, but keep in mind that I did not follow them step by step.<\/p>\n<p>Resizing:<\/p>\n<p><a href=\"http:\/\/serverfault.com\/questions\/332648\/decreasing-root-disk-size-of-an-ebs-boot-ami-on-ec2\/332670\">http:\/\/serverfault.com\/questions\/332648\/decreasing-root-disk-size-of-an-ebs-boot-ami-on-ec2\/332670<\/a><\/p>\n<p><a href=\"https:\/\/www.howtoforge.com\/linux_resizing_ext3_partitions\">https:\/\/www.howtoforge.com\/linux_resizing_ext3_partitions<\/a><\/p>\n<p>Creating Images:<\/p>\n<p><a href=\"http:\/\/robpickering.com\/2010\/07\/create-a-full-backup-image-of-your-amazon-ec2-instance-2-129\">http:\/\/robpickering.com\/2010\/07\/create-a-full-backup-image-of-your-amazon-ec2-instance-2-129<\/a><\/p>\n<h2>How to Reduce a Disk Size on AWS<\/h2>\n<p>My current EC2 instance that is up and running using a\u00a0100G drive. \u00a0My old instance that crashed had 8G. \u00a0Here is what I did to reduce my operating drive size<\/p>\n<h3>Starting in the AWS Console<\/h3>\n<ol>\n<ol>\n<li>Since I just did a snapshot of my working system, I did not need another one. \u00a0But if you are just starting to follow along at home, you need to create a snapshot of your working image (Mine was called &#8220;Current&#8221;) and then a new Volume from that snapshot (I labeled mine &#8220;Small Source&#8221;)<\/li>\n<li>My first step was to bring up a new EC2 instance with the min 8G. \u00a0I went with the free t2.micro instance and\u00a0labeled that &#8220;New 8&#8221;<\/li>\n<li>Then I created a snapshot of &#8220;New 8&#8221; and from there created a new 8G volume and labeled it\u00a0&#8220;Small Dest&#8221;<\/li>\n<li>I then restarted my &#8220;New 8&#8221; Ec2 instance and waited for it to come up.<\/li>\n<li>Once it was up, I attached &#8220;Small Source&#8221; &#8211; my 100G working drive to \/dev\/sdz. and I attached &#8220;Small Dest&#8221; &#8211; my new 8G drive to \/dev\/sdm<\/li>\n<\/ol>\n<\/ol>\n<p style=\"padding-left: 90px;\">In summary &#8220;New 8&#8221; has three hard drives:<\/p>\n<p style=\"padding-left: 120px;\">\/dev\/xcda &#8211; the drive it came with<\/p>\n<p style=\"padding-left: 120px;\">\/dev\/sdz &#8211; the 100G &#8220;Small Source&#8221;<\/p>\n<p style=\"padding-left: 120px;\">\/dev\/sdm &#8211; the 8G &#8220;Small Dest&#8221;<\/p>\n<h3>Launch a Console to the &#8220;New 8&#8221; EC2 instance<\/h3>\n<p>My goal now is to reduce the size of the &#8220;Small Source&#8221; such that it will fit on the &#8220;Small Dest&#8221; and copy the files across. \u00a0the next few commands are all done in the &#8220;New 8&#8221; Linux console.<\/p>\n<p>See what the two drives look like<\/p>\n<pre># fdisk -l \/dev\/sdz1\r\nDisk \/dev\/sdz1: 107.4 GB, 107372068352 bytes, 209711071 sectors\r\nUnits = sectors of 1 * 512 = 512 bytes\r\nSector size (logical\/physical): 512 bytes \/ 512 bytes\r\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes<\/pre>\n<pre># fdisk -l \/dev\/sdm\r\nWARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.\r\nDisk \/dev\/sdm: 8589 MB, 8589934592 bytes, 16777216 sectors\r\nUnits = sectors of 1 * 512 = 512 bytes\r\nSector size (logical\/physical): 512 bytes \/ 512 bytes\r\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes\r\nDisk label type: gpt\r\n\r\n# Start End Size Type Name\r\n 1 4096 16777182 8G Linux filesyste Linux\r\n128 2048 4095 1M BIOS boot parti BIOS Boot Partition<\/pre>\n<pre># fdisk -l \/dev\/sdm1\r\nDisk \/dev\/sdm1: 8587 MB, 8587820544 bytes, 16773087 sectors\r\nUnits = sectors of 1 * 512 = 512 bytes\r\nSector size (logical\/physical): 512 bytes \/ 512 bytes\r\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes<\/pre>\n<p>Check the existing filesystem on &#8220;Small Source&#8221;<\/p>\n<pre># e2fsck \/dev\/sdz1\r\ne2fsck 1.42.12 (29-Aug-2014)\r\n\/: clean, 119138\/507904 files, 1327858\/2022400 blocks<\/pre>\n<p>Reduce the size of files on &#8220;Small Source&#8221;<\/p>\n<pre># resize2fs -p \/dev\/sdz1 7900M<\/pre>\n<p>Change the partition table on &#8220;Small Source&#8221; to fit on &#8220;Small Dest&#8221;<\/p>\n<pre># fdisk \/dev\/sdz\r\nWARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.\r\nWelcome to fdisk (util-linux 2.23.2).\r\nChanges will remain in memory only, until you decide to write them.\r\nBe careful before using the write command.<\/pre>\n<p>&#8211; print the table (redundant as we did this previously)<\/p>\n<pre>Command (m for help): p\r\nDisk \/dev\/sdz: 107.4 GB, 107374182400 bytes, 209715200 sectors\r\nUnits = sectors of 1 * 512 = 512 bytes\r\nSector size (logical\/physical): 512 bytes \/ 512 bytes\r\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes\r\nDisk label type: gpt\r\n# Start End Size Type Name\r\n 1 4096 16183295 7.7G Linux filesyste\r\n128 2048 4095 1M BIOS boot parti BIOS Boot Partition\r\nCommand (m for help):<\/pre>\n<p>&#8211; delete the partition<\/p>\n<pre>Command (m for help): d\r\nPartition number (1,128, default 128): 1\r\nPartition 1 is deleted<\/pre>\n<p>&#8211; Create a new partition. \u00a0Start it at 4096. \u00a0Make it 7900MB\u00a0(the same size as the resize above)<\/p>\n<pre>Command (m for help): n\r\nPartition number (1-127, default 1): 1\r\nFirst sector (34-209715166, default 4096): 4096\r\nLast sector, +sectors or +size{K,M,G,T,P} (4096-209715166, default 209715166): +7900M<\/pre>\n<p>&#8211; write the table (&amp; quit)<\/p>\n<pre>w<\/pre>\n<pre>q<\/pre>\n<p>Copy the &#8220;Small Source&#8221; partition to &#8220;Small Dest&#8221;<\/p>\n<pre># dd if=\/dev\/sdz1 of=\/dev\/sdm1 bs=32M<\/pre>\n<p>Check the new filesystem on &#8220;Small Dest&#8221;<\/p>\n<pre># e2fsck \/dev\/sdm1<\/pre>\n<p>Mount the drive just to make sure it has the contents you want.<\/p>\n<pre># mount \/dev\/sdm1 sdm\/\r\n# ls sdm\/\r\nbin cgroup dev home lib64 lost+found mnt proc run selinux sys usr\r\nboot config etc lib local media opt root sbin srv tmp var<\/pre>\n<h3>On AWS launch with the Smaller Disk Size<\/h3>\n<p>All that is left to do now is associate the new &#8220;Small Dest&#8221; volume with an EC2 instance and you will be back up and running. \u00a0For me, I simply stopped the &#8220;Current&#8221; EC2, detached the booting volume and then attached &#8220;Small Dest&#8221; as the booting volume for &#8220;Current&#8221;<\/p>\n<p>If you needed 100% uptime, you could launch a new EC2 instance, or use &#8220;New 8&#8221; and attach &#8220;Small Dest&#8221; as the booting partition, then use Elastic IP to point to your new small server.<\/p>\n<h3>Cleanup the Old Items<\/h3>\n<p>My next step is to clean up the snapshots, volumes, and instances that are no longer needed leaving me with a new clean instance an the associated backups. I am not going into detail on this one, as I feel we have used those features enough over the past couple of posts<\/p>\n<p>And that is how I reduced my disk size.\u00a0 Thanks for reading.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I do not want to pay more using more space than I need, so in this post I am going to reduce my disk size on the AWS EC2 instance to use less disk space. Let me start off by saying I do not know if AWS charges for &#8220;empty&#8221; space on their drives. \u00a0If [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":739,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[18],"tags":[25,24,29,30,26,27,28],"_links":{"self":[{"href":"http:\/\/www.stonemillkids.com\/index.php\/wp-json\/wp\/v2\/posts\/797"}],"collection":[{"href":"http:\/\/www.stonemillkids.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.stonemillkids.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.stonemillkids.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.stonemillkids.com\/index.php\/wp-json\/wp\/v2\/comments?post=797"}],"version-history":[{"count":12,"href":"http:\/\/www.stonemillkids.com\/index.php\/wp-json\/wp\/v2\/posts\/797\/revisions"}],"predecessor-version":[{"id":834,"href":"http:\/\/www.stonemillkids.com\/index.php\/wp-json\/wp\/v2\/posts\/797\/revisions\/834"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.stonemillkids.com\/index.php\/wp-json\/wp\/v2\/media\/739"}],"wp:attachment":[{"href":"http:\/\/www.stonemillkids.com\/index.php\/wp-json\/wp\/v2\/media?parent=797"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.stonemillkids.com\/index.php\/wp-json\/wp\/v2\/categories?post=797"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.stonemillkids.com\/index.php\/wp-json\/wp\/v2\/tags?post=797"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}