包装工无法连接EBS卷



我正试图将额外的卷附加到我的ami,这是我的构建器部分,

"launch_block_device_mappings": [
{
"device_name": "/dev/sda1",
"volume_size": 8,
"volume_type": "gp2",
"delete_on_termination": true
},
{
"device_name": "/dev/sdb",
"volume_size": 10,
"volume_type": "gp2",
"delete_on_termination": true
}
],
"ami_block_device_mappings": [
{
"device_name": "/dev/sdb",
"virtual_name": "ephemeral0"
}
]

请帮忙。

这为您提供了额外的10Gb磁盘可供配置:

{
"builders" : [
{
"type" : "amazon-ebs",
"instance_type" : "t2.micro",
"ssh_username" : "ubuntu",
"ami_name" : "packer-ES-{{timestamp}}",
"source_ami_filter": {
"filters": {
"virtualization-type": "hvm",
"name": "ubuntu/images/*ubuntu-xenial-16.04-amd64-server-*",
"root-device-type": "ebs"
},
"owners": ["099720109477"],
"most_recent": true
},
"launch_block_device_mappings" : [
{
"device_name" : "/dev/sdb",
"delete_on_termination" : true,
"volume_size" : 10,
"volume_type" : "gp2"
}
],
"ami_block_device_mappings" : [
{
"device_name" : "/dev/sdb",
"delete_on_termination" : true,
"volume_type" : "gp2"
}
]
}
],
"provisioners": [
{
"type": "shell",
"inline": [
"lsblk",
"df -h"
]
}
]
}

运行这个你会看到:

==> amazon-ebs: Connected to SSH!
==> amazon-ebs: Provisioning with shell script: /var/folders/_t/lsk64yf93xs3slvvtc6b_6mr0000gn/T/packer-shell591343041
amazon-ebs: NAME    MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
amazon-ebs: xvda    202:0    0   8G  0 disk
amazon-ebs: └─xvda1 202:1    0   8G  0 part /
amazon-ebs: xvdb    202:16   0  10G  0 disk
amazon-ebs: Filesystem      Size  Used Avail Use% Mounted on
amazon-ebs: udev            488M     0  488M   0% /dev
amazon-ebs: tmpfs           100M  3.0M   97M   3% /run
amazon-ebs: /dev/xvda1      7.7G  956M  6.8G  13% /
amazon-ebs: tmpfs           496M     0  496M   0% /dev/shm
amazon-ebs: tmpfs           5.0M     0  5.0M   0% /run/lock
amazon-ebs: tmpfs           496M     0  496M   0% /sys/fs/cgroup
amazon-ebs: tmpfs           100M     0  100M   0% /run/user/1000
==> amazon-ebs: Stopping the source instance...
amazon-ebs: Stopping instance, attempt 1

验证结果:

env AWS_PROFILE=packer-demo AWS_DEFAULT_REGION=eu-west-1 aws ec2 describe-images --image-ids ami-0a53
cb1f4541b55d4
{
"Images": [
{
"Architecture": "x86_64",
"CreationDate": "2018-07-19T09:52:53.000Z",
"ImageId": "ami-0a53cb1f4541b55d4",
"ImageLocation": "965990659467/packer-ES-1531993870",
"ImageType": "machine",
"Public": false,
"OwnerId": "965990659467",
"State": "available",
"BlockDeviceMappings": [
{
"DeviceName": "/dev/sda1",
"Ebs": {
"Encrypted": false,
"DeleteOnTermination": true,
"SnapshotId": "snap-0e622d809cf0e148a",
"VolumeSize": 8,
"VolumeType": "gp2"
}
},
{
"DeviceName": "/dev/sdb",
"Ebs": {
"Encrypted": false,
"DeleteOnTermination": false,
"SnapshotId": "snap-0c65cdcdb579f21b4",
"VolumeSize": 10,
"VolumeType": "standard"
}
},
{
"DeviceName": "/dev/sdc",
"VirtualName": "ephemeral1"
}
],
"EnaSupport": true,
"Hypervisor": "xen",
"Name": "packer-ES-1531993870",
"RootDeviceName": "/dev/sda1",
"RootDeviceType": "ebs",
"SriovNetSupport": "simple",
"VirtualizationType": "hvm"
}
]
}

如果您不需要在sdb上提供任何内容,您可以完全删除launch_device_mappings部分,并将volume_size移到ami_device_mappings中。

相关内容

  • 没有找到相关文章

最新更新