I have a Packer template that I
thought would specify the volume size of the root volume on the resulting instance. It sort of does, but not quite.
What I mean is
1) user template, create AMI
2) Launch instance from that new AMI
3) Expected result: root volume on that instance is the size specfied in template
Template has EBS options like so:
"ami_block_device_mappings": [{
"device_name": "/dev/sda1",
"volume_type": "gp2",
"delete_on_termination": true,
"volume_size": 20
}],
"launch_block_device_mappings": [{
"device_name": "/dev/sda1",
"volume_type": "gp2",
"delete_on_termination": true,
"volume_size": 20
}],
The resulting instance, launched with the option "--block-device-mappings "[{\"DeviceName\":\"/dev/sda1\",\"Ebs\":{\"VolumeSize\":20,\"DeleteOnTermination\":true}}]"", looks like this:
[root@ip-10-78-0-43 ~]# fdisk -l
Disk /dev/xvda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xeafa2de4
Device Boot Start End Blocks Id System
/dev/xvda1 1 652 5237158+ 83 Linux
[root@ip-10-78-0-43 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda 202:0 0 20G 0 disk
└─xvda1 202:1 0 5G 0 part /
(I bolded the important bits)
In other words, I am launching the instance and specifying 20G root volume at launch. The instance does get a 20G root volume, but the extents of the root partition are only the 5G that is set in the original AMI I used to build via Packer.
I was able to use fidsk and resize2fs to resize the partition to the full extent of the volume, but only manually. I want Packer to take care of this.
I am probably a little confused. For example: what is the difference between "ami_block_device_mappings" and "launch_block_device_mappings"? From the names, I expect that the former is what is baked into the AMI; the latter is what is used when instances are launched from the AMI.
Also, I have been using "/dev/sda1" in my Packer template, but the resulting AMI gets "/dev/xvda1" as the root device. Should I use "xvda1" instead?
Finally, should Packer be the one doing this resizing? Or should some scripted process do it on my end?
Please make recommendations.
Thanks,
JDS