Skip to content

Instantly share code, notes, and snippets.

@wuct
Forked from mattjay/ec2MongoUpgrade
Created June 13, 2017 15:42
Show Gist options
  • Save wuct/ee71023349314591975206cdfc15114f to your computer and use it in GitHub Desktop.
Save wuct/ee71023349314591975206cdfc15114f to your computer and use it in GitHub Desktop.
Increase the disk space on a MongoDB EC2 Instance in Amazon Web Services
  1. Create a Snapshot of the current EC2 instance running Mongo. First, note down the Volume ID from your Instance list since for whatever reason you can't see any instance info in the Snapshot page. Second, go to the Snapshot page and click [Create Snapshot]. Choose the Volume ID you just noted down and name the Snapshot and create it.

  2. Create a new Volume with the backup Snapshot. In your instance list note the Availability Zone of the instance you are trying to upgrade. Go to the Volumes page and click [Create Volume]. Pick Standard and enter how many GB you'd like to create. This should be larger than the Volume you just created the Snapshot from. Then from the drop down choose the Snapshot you just created and click create. Also choose the Availability Zone that the instance you are upgrading is in as they must be the same.

  3. Find the instance you'd like to upgarde in the Instances list and note the name of the disk which will be next to "Block devices" (most likely /dev/sda1).

  4. Stop the Instance you'd like to upgrade.

  5. From the Volumes page right click the Volume that is currently attached to the instance you are upgrading and Detatch from the now stopped instance.

  6. Right click on the new Volume you've created with the new Snapshot and attach it to the stopped instance you are upgrading. After choosing the instance from the drop down make sure the name in the "Device" text box matches the name you noted in Step 3.

  7. Start the instance you're upgrading.

  8. SSH into the box and confirm you have the newly added disk space by running "fdisk -l /dev/sda1" or whatever you named the device. Note: this could be automatically renamed to /dev/xvda1 based on newer linux kernal behavior.

  9. Need to resize the partition from the old Snapshot by running "resize2fs /dev/sda1 30G" which assumes you're newly upgraded Volume size is 30 Gigs. Change accordingly.

  10. Reboot your Instance to make sure all is working as intended, but if all is well SSH back in and run "mongod" and let Mongo reassociate with all the db files which will take longer than normal to boot up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment