13

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'd like to increase this to 40GB. I am under the impression I can do this based on this documentation. Unfortunately the config below doesn't seem to work.

"LaunchConfig" : {
    "Type": "AWS::AutoScaling::LaunchConfiguration",
    "Properties": {
        "BlockDeviceMappings": [{
            "DeviceName": "/dev/sda1",
            "Ebs" : {"VolumeSize": "40"}
        }]
    }
}

I am using a custom ami that is based off of ami-05355a6c.

4

1 回答 1

20

您的 LaunchConfiguration 设置 EBS 卷块设备的大小。但是,文件系统仍然认为它应该只使用 8 GB。

您可以运行如下命令来告诉文件系统它应该用完整个块设备:

sudo resize2fs /dev/sda1

您可以在自定义 AMI 启动命令中自动执行此操作,也可以在 LaunchConfiguration 中传入用户数据脚本,以达到以下效果:

#!/bin/bash
resize2fs /dev/sda1

用户数据脚本在首次启动时以 root 身份运行,因此不需要 sudo。这是我介绍用户数据脚本概念的文章:http: //alestic.com/2009/06/ec2-user-data-scripts

在 CloudFormation 模板中,这可能类似于:

    "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",
      ""
    ]]}}

这是一篇文章,我解释了调试用户数据脚本的“exec”行的有用性:http: //alestic.com/2010/12/ec2-user-data-output

于 2013-10-02T20:53:44.233 回答