Increase the root device size in cloudformation autoscaling group

后端 未结 1 1540
無奈伤痛
無奈伤痛 2021-02-02 17:53

I am trying to increase the hard disk space on my ebs backed ec2 instance from my cloudformation AutoScaling::LaunchConfiguration. Initially the root device starts with 8GB. I

相关标签:
1条回答
  • 2021-02-02 18:11

    Your LaunchConfiguration sets the size of the EBS volume block device. However, the file system still thinks that it should only be using 8 GB.

    You can run a command like the following to tell the file system it should use up the entire block device:

    sudo resize2fs /dev/sda1
    

    You could automate this in your custom AMI startup commands, or you could pass in a user-data script in your LaunchConfiguration to the effect of:

    #!/bin/bash
    resize2fs /dev/sda1
    

    user-data scripts are run as root on on first boot, so the sudo is not necessary. Here's an article where I introduced the concept of user-data scripts: http://alestic.com/2009/06/ec2-user-data-scripts

    In a CloudFormation template, this might look something like:

        "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [
          "#!/bin/bash -ex\n",
          "exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1\n",
          "resize2fs /dev/sda1\n",
          ""
        ]]}}
    

    Here's an article where I explain the usefulness of the "exec" line for debugging user-data scripts: http://alestic.com/2010/12/ec2-user-data-output

    0 讨论(0)
提交回复
热议问题