阅读背景:

增加cloudformation自动缩放组中的根设备大小

来源:互联网 

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.

我试图从我的cloudformation AutoScaling :: LaunchConfiguration增加我的ebs支持的ec2实例上的硬盘空间。最初,根设备以8GB开头。我想把它增加到40GB。我的印象是我可以根据这个文档做到这一点。不幸的是,下面的配置似乎不起作用。

"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.

我使用的是基于ami-05355a6c的自定义ami。

1 个解决方案

#1


17  

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.

您的LaunchConfiguration设置EBS卷块设备的大小。但是,文件系统仍然认为它应该只使用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:

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

#!/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: https://alestic.com/2009/06/ec2-user-data-scripts

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

In a CloudFormation template, this might look something like:

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

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

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


分享到: