Configuring size of root volume on EC2

10,210 views
Skip to first unread message

Sean Mackrory

unread,
Sep 6, 2013, 6:12:01 PM9/6/13
to packe...@googlegroups.com
Is it possible in packer to edit the size of the root volume in the EC2 builders in Packer? This is an option when launching an instance using the Classic Wizard in the AWS Web Console, but I don't see any options that apply to the root volume in the documentation.

Sean Mackrory

unread,
Sep 7, 2013, 1:00:12 AM9/7/13
to packe...@googlegroups.com
After more reading, I found that the (ami|launch)_block_device_mappings options accomplish this. As an example if anyone else has the same question, to make sure my AMI had a 64 GiB root device both when provisioning it and when launching the AMI after it was packaged, I specified the following configuration for the EBS builder:

        "ami_block_device_mappings": [ {
            "device_name": "/dev/sda1",
            "volume_size": 64,
            "delete_on_termination": true
        } ],
        "launch_block_device_mappings": [ {
            "device_name": "/dev/sda1",
            "volume_size": 64,
            "delete_on_termination": true
        } ]

Emil Sit

unread,
Sep 10, 2013, 5:11:59 PM9/10/13
to packe...@googlegroups.com
I'm trying to do this right now but it is not working for me (using packer-0.3.7). It sends the following request:

2013/09/10 17:09:53 /opt/packer-0.3.7/packer-builder-amazon-ebs: 2013/09/10 17:09:53 Config: {PackerConfig:{PackerBuildName:amazon-ebs PackerBuilderType:amazon-ebs PackerDebug:false PackerForce:false PackerUserVars:map[]} AccessConfig:{AccessKey:AKIAJ6ZH3V44PA5FIVBQ SecretKey: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 RawRegion:us-east-1} AMIConfig:{AMIName:hadapt-automation centos 1378847393 AMIDescription: AMIUsers:[] AMIGroups:[] AMIProductCodes:[] AMIRegions:[] AMITags:map[]} BlockDevices:{AMIMappings:[{DeviceName:/dev/sda1 VirtualName: SnapshotId: VolumeType: VolumeSize:16 DeleteOnTermination:true IOPS:0 NoDevice:false}] LaunchMappings:[{DeviceName:/dev/sda1 VirtualName:/dev/sda1 SnapshotId: VolumeType: VolumeSize:16 DeleteOnTermination:true IOPS:0 NoDevice:false} {DeviceName:/dev/sdb VirtualName:ephemeral0 SnapshotId: VolumeType: VolumeSize:0 DeleteOnTermination:false IOPS:0 NoDevice:false} {DeviceName:/dev/sdc VirtualName:ephemeral1 SnapshotId: VolumeType: VolumeSize:0 DeleteOnTermination:false IOPS:0 NoDevice:false} {DeviceName:/dev/sdd VirtualName:ephemeral2 SnapshotId: VolumeType: VolumeSize:0 DeleteOnTermination:false IOPS:0 NoDevice:false} {DeviceName:/dev/sde VirtualName:ephemeral3 SnapshotId: VolumeType: VolumeSize:0 DeleteOnTermination:false IOPS:0 NoDevice:false}]} RunConfig:{SourceAmi:ami-eb6b0182 IamInstanceProfile: InstanceType:m1.large UserData: UserDataFile: RawSSHTimeout:5m SSHUsername:ec2-user SSHPort:22 SecurityGroupId: SubnetId: TemporaryKeyPairName:packer f6b5c7414c98409420f09d0abadce966 VpcId: sshTimeout:300000000000} tpl:0xc20013cfc0}

And gets the following error:

2013/09/10 17:09:54 ui: ==> amazon-ebs: Launching a source AWS instance...
==> amazon-ebs: Error launching source instance: logicalType cannot be modified on root device (InvalidBlockDeviceMapping)

Has anyone seen something similar?

Thanks!




--
You received this message because you are subscribed to the Google Groups "Packer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Emil Sit / http://www.emilsit.net/

maven....@gmail.com

unread,
Sep 27, 2013, 4:16:37 PM9/27/13
to packe...@googlegroups.com
Where did you find that?

I can't find that in the documentation anywhere :-(

Sean Mackrory

unread,
Nov 7, 2013, 5:55:51 PM11/7/13
to packe...@googlegroups.com
>> Has anyone seen something similar?

I know someone who just ran into this. The problem turned out to be that the device name on their guest OS was just "/dev/sda". Maybe yours is also different.


>> Where did you find that?

The existence of these options is documented here: http://www.packer.io/docs/builders/amazon.html. However I had to consult Amazon's API documentation and do a bit of guessing to fill in the fields.

Anton Ryabchenko

unread,
Jul 9, 2015, 12:42:42 PM7/9/15
to packe...@googlegroups.com
It's great, but we need also resize the fs. First we need to change the partitioning table, then rebbot, then resize.
For that purpose I used:

"provisioners": [
  {
    "type": "shell",
    "script": "/root/ext_disk.sh"
  },
  {
    "type": "shell",
    "inline": [
      "reboot",
      "sleep 30",
      "resize2fs /dev/xvda1"
    ]
  }]

where /root/ext_disk.sh just deletes the first partition and creates a new one. Its content:

#!/bin/bash
fdisk /dev/xvda <<EEOF
d
n
p
1
1

w
EEOF
exit 0

Nikolai Zujev

unread,
Jul 20, 2015, 12:27:45 PM7/20/15
to packe...@googlegroups.com
Hi there,

Could you pls expose full working configuration, as I am wasting tooooo.... much time to make it working. :)
I need to have 50gb root partition.

Thank you very much in advance

Regards
Nick

Ethan Fahy

unread,
Mar 9, 2016, 1:46:38 PM3/9/16
to Packer
I know this is an old thread but for what it's worth I would also love to see some sort of holistic guide to how to resize the root volume/partition for the EBS AMI Builder.  It would also be awesome if this were a native option within Packer.  I'm trying to piece the solution together from different threads and github issue trackers but I'm spending a lot of time and so far have been unsuccessful.

-Ethan

Alvaro Miranda Aguilera

unread,
Mar 9, 2016, 7:50:10 PM3/9/16
to packe...@googlegroups.com
Hello,

Packer will do the disk part and that works fine.

From there, if the AMI has autoresize with cloud-init it will work.

if the AMI you are not using, then a shell provider will do the trick. This will be too specific for each OS (lvm? ext3? ext4? xfs? btrfs? zfs? ) that it doesn't sound doable in packer.

Thanks
Alvaro.

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/packer/issues
IRC: #packer-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Packer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool...@googlegroups.com.

craig.o...@topng.net

unread,
Apr 7, 2016, 10:34:53 AM4/7/16
to Packer
When I do this, I am no longer able to ssh into my server

craig.o...@topng.net

unread,
Apr 7, 2016, 11:33:47 AM4/7/16
to Packer
Hey,

so I am using a centos os and after hours of trying to solve this, I found that all I needed to do was run the following
growpart /dev/xdva 1
reboot

I found it here - https://www.elastic.co/blog/autoresize-ebs-root-volume-on-aws-amis

Bob Henkel

unread,
Aug 2, 2016, 12:08:43 AM8/2/16
to Packer
Thanks so much! As of August 2016 I was not able to figure this out reading Packer docs, but your post got me going.

Alessandro Surace

unread,
Jun 14, 2017, 4:50:53 AM6/14/17
to Packer
I did it a bit differently. Because I don't mind if the FS is not expanded at AMI creation time I just expand it. And the next AMI boot it will be ready and expanded.

Therefore I added the follow code in the packer user_data_file:
# resize root fs if the volume is bigger
echo
"ROOT DISK RESIZING" > /tmp/root_disk_resize.log
# wait for facter
while ( ! /usr/bin/facter ); do sleep 15 ; done >> /tmp/root_disk_resize.log 2>&1
OS_RELEASE
=$(facter operatingsystemmajrelease 2>&1 )
ROOT_DEVICE
=$(facter ec2_block_device_mapping_root 2>&1 )
# Install epel
rpm
-ivh https://ftp.fau.de/epel/epel-release-latest-${OS_RELEASE}.noarch.rpm >> /tmp/root_disk_resize.log 2>&1
yum install
-y cloud-utils-growpart gdisk >> /tmp/root_disk_resize.log 2>&1
# resize partition
growpart
-v  ${ROOT_DEVICE} 1   >> /tmp/root_disk_resize.log 2>&1
# resize filesystem
resize2fs
-p ${ROOT_DEVICE}1    >> /tmp/root_disk_resize.log 2>&1
# remove epel to avoid to interfere with the rest of the installation
rpm
-e epel-release        >> /tmp/root_disk_resize.log 2>&1
...
Reply all
Reply to author
Forward
0 new messages