在linux-ec2实例中使用云arrays自动挂载ebs卷?

写了一个CFT创build两个ebs卷附加的红帽实例。 并且需要从cft本身自动挂载或格式化ebs卷。

CFT:

"BlockDeviceMappings": [ { "DeviceName": "/dev/sda1", "Ebs": { "DeleteOnTermination": "true", "VolumeSize": "150", "VolumeType": "standard" } }, { "DeviceName": "/dev/sdm", "Ebs": { "DeleteOnTermination": "true", "VolumeSize": "1000", "VolumeType": "standard" } } ] 

需要自动挂载“DeviceName”:“/ dev / sdm”,这个卷。

您需要将一个小脚本添加到您的实例的UserData属性或此BlockDeviceMappings所关联的启动配置中。 UserData在实例首次引导时执行。 使用/ etc / fstab重启实例时,设备将自动重新挂载。

  "UserData" : { "Fn::Base64" : { "Fn::Join" : [ "", [ "#!/bin/bash -v\n", "mkfs -t ext4 /dev/xvdm\n", "mkfs -t ext4 /dev/xvda1\n", "mkdir /opt/mount1 /opt/mount2\n", "mount /dev/xvdm /opt/mount1\n", "mount /dev/xvda1 /opt/mount2\n", "echo \"/dev/xvdm /opt/mount1 ext4 defaults,nofail 0 2\" >> /etc/fstab\n" "echo \"/dev/xvda1 /opt/mount2 ext4 defaults,nofail 0 2\" >> /etc/fstab\n" ]]}} 

更多信息: http : //docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-using-volumes.html

我不喜欢明确地在用户数据脚本中安装,我更喜欢以下方法:

 "UserData" : { "Fn::Base64" : { "Fn::Join" : [ "", [ "#!/bin/bash -v\n", "mkfs -t ext4 /dev/xvdm\n", "echo \"/dev/xvdm /opt/mount1 ext4 defaults,nofail 0 2\" >> /etc/fstab\n", "mount -a\n" ]]}} 

“mount -a”将尝试挂载/ etc / fstab中的所有条目,并依次验证以前的附加操作。