use*_*879 7 amazon-ec2 amazon-web-services aws-cloudformation
我找不到使用cloudformation附加和装载卷的方法.
我可以使用VolumeAttachment附加卷; 但是,当我lsblk在EC2实例处于运行状态后执行操作时,我将此附加实例视为已卸载.
有没有办法从Cloudformation文件挂载此实例?我可以使用linux命令安装它,但是更好地处理来自cloudformation的所有内容.
这是我到目前为止:
"MyEc2Instance" : {
"Type" : "AWS::EC2::Instance",
"Properties" : {
"KeyName" : { "Ref" : "KeyName" }
}
},
"MyVolume" : {
"Type" : "AWS::EC2::Volume",
"Properties" : {
"Size" : "50",
"AvailabilityZone" : "xyz"
}
},
"attachment" : {
"Type" : "AWS::EC2::VolumeAttachment",
"Properties" : {
"InstanceId" : { "Ref" : "MyEc2Instance" },
"VolumeId" : { "Ref" : "MyVolume" },
"Device" : "/dev/sdh"
}
}
Run Code Online (Sandbox Code Playgroud)
当我lsblk在实例上做的时候,这是我看到的结果:
xvda 202:0 0 8G 0 disk
??xvda1 202:1 0 8G 0 part /
xvdh 202:112 0 50G 0 disk
Run Code Online (Sandbox Code Playgroud)
请注意,即使我将设备名称指定为'sdh',它也会显示为'xvdh'.这是为什么?正如你所看到的,这是未安装的.我该怎么装?
NHo*_*Hol 12
正如helloV所提到的,当使用UserData启动实例时,您需要安装它.我发现CloudFormation模板的新YAML格式要容易得多,但我也把这个例子放在了JSON中.
JSON:
"UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [
"#!/bin/bash -xe\n",
"# create mount point directory\n",
"mkdir /mnt/xvdh\n",
"# create ext4 filesystem on new volume\n",
"mkfs -t ext4 /dev/xvdh\n",
"# add an entry to fstab to mount volume during boot\n",
"echo \"/dev/xvdh /mnt/xvdh ext4 defaults,nofail 0 2\" >> /etc/fstab\n",
"# mount the volume on current boot\n",
"mount -a\n"
]]}}
Run Code Online (Sandbox Code Playgroud)
YAML:
UserData:
'Fn::Base64': !Sub
- |
#!/bin/bash -xe
# create mount point directory
mkdir /mnt/xvdh
# create ext4 filesystem on new volume
mkfs -t ext4 /dev/xvdh
# add an entry to fstab to mount volume during boot
echo "/dev/xvdh /mnt/xvdh ext4 defaults,nofail 0 2" >> /etc/fstab
# mount the volume on current boot
mount -a
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6889 次 |
| 最近记录: |