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.
To attach an EBS volume to an instance using the consoleOpen the Amazon EC2 console at https://console.aws.amazon.com/ec2/ . In the navigation pane, choose Elastic Block Store, Volumes. Select an available volume and choose Actions, Attach Volume. For Instance, start typing the name or ID of the instance.
You can use a block device mapping to specify additional EBS volumes when you launch your instance, or you can attach additional EBS volumes after your instance is running. For more information, see Amazon EBS volumes. You can specify the instance store volumes for your instance only when you launch it.
The Step-By-Step Re-Mounting Process Select the EBS Volume that you want to attach to an EC2 instance. The EBS volume should be in available status. Enter the Instance ID or the Instance name. Make sure that the Amazon EBS volume and the Amazon EC2 instance are in the same availability zone.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With