How to launch a new EC2 instance with the New-EC2Instance but with increased volume size (greater than the 8GB standard). I tried it with:
...
$blockDeviceMapping = New-Object -TypeName Amazon.EC2.Model.BlockDeviceMapping
$ebsBlockDevice = New-Object -TypeName Amazon.EC2.Model.EbsBlockDevice
$blockDeviceMapping.DeviceName = '/dev/sda1'
$ebsBlockDevice.VolumeSize = '50'
$ebsBlockDevice.VolumeType = 'standard'
$blockDeviceMapping.Ebs = $ebsBlockDevice
...
$NewInstanceResponse = New-EC2Instance <...> -BlockDeviceMapping $blockDeviceMapping
But it creates an instance with an unmounted volume. I am trying to create an instance with 1 storage volume with the size of 50GB.
Remove Single Quote of 50. It should be Integer , like below.
"VolumeSize": 50
I accomplished it in the way that I first created an instance with 50GB of root storage, and then created an image of that instance, so I could use the AMI with the increased root storage. It is maybe an workaround, but worked for me. If there is an cleaner solutions, I would like to hear it.
Make sure that your volume name matches the root volume name of your instance type. In my case it is /dev/xvda
.
I have an example from the ASG LaunchTemplateData, but the solution should be the same:
BlockDeviceMappings:
- DeviceName: /dev/xvda
Ebs:
DeleteOnTermination: true
VolumeSize: 16
VolumeType: "gp2"
If I remember correctly, when I used a different name, just another volume was created - like in your case.
Then, when you start your instance with a regular 8GB AMI you will still see an 8GB filesystem. Depending on your filesystem type, you should be able to grow it in the metadata on the first start. I do the following:
BLCKDEVICE=`lsblk -l | egrep 'part /$' | awk '{ print $1}' `
DEVICE=`echo $BLCKDEVICE | cut -dp -f1`
PARTID=`echo $BLCKDEVICE | cut -dp -f2`
growpart /dev/$DEVICE $PARTID
xfs_growfs -d /
Make sure your script matches your AMI configuration like the filesystem type (in my case it is XFS, but ext4 should work as well).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.