Reputation: 63
Wrote one CFT to create redhat instance with two ebs volume attached. And need automount or formatted the ebs volume from the cft itself.
CFT:
"BlockDeviceMappings": [
{
"DeviceName": "/dev/sda1",
"Ebs": {
"DeleteOnTermination": "true",
"VolumeSize": "150",
"VolumeType": "standard"
}
},
{
"DeviceName": "/dev/sdm",
"Ebs": {
"DeleteOnTermination": "true",
"VolumeSize": "1000",
"VolumeType": "standard"
}
}
]
Need to mount "DeviceName" : "/dev/sdm", this volume automatically.
Upvotes: 6
Views: 8925
Reputation: 1248
Rather than mounting explicitly in the user-data script, I prefer the following approach:
"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" will try to mount all the entries in /etc/fstab and in turn verify the previous append operation.
Upvotes: 3
Reputation: 2105
You will need to add a small script to the UserData property of your instance or launch configuration that this BlockDeviceMappings is associated with. UserData is executed the first time the instance boots. The devices will automatically be remounted when the instance reboots using /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"
]]}}
More information: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-using-volumes.html
Upvotes: 9