Expand/Resize Root Partition Upon First Boot Via Cloud-init

942 views
Skip to first unread message

Tarkan Erimer @F-Secure

unread,
Oct 8, 2014, 5:42:23 AM10/8/14
to euca-...@eucalyptus.com
Hi all,

For some time we're trying to make HVM images to expand their root partition size upon first boot via cloud-init and cloud-initramfs-growpart on Debian 7 without success. After launching the instance, it just attaches a secondary disk with the requested size (m1.small:5GB) instead of expanding the disk to 5 GB. The initial image is 1GB in size and we want it to be expanded upon first boot depending on the requested size (m1.small etc.) at launch time. 

Our setup is :

  1. Create an image file via "dd if=/dev/zero of=${IMAGE} bs=1M count=1024"
  2. Partition, format and mount the disk image via :
          parted -s ${IMAGE} mklabel msdos
          parted -a optimal ${IMAGE} mkpart primary 0% 100%
          parted -s ${IMAGE} set 1 boot on
          install-mbr ${IMAGE}

          BASE_DEVICE=`sudo losetup -f --show ${IMAGE}`
          DEVICE=`sudo losetup -o 0 -f --show ${BASE_DEVICE}`

          sudo mkfs.ext4 -F -m 0 ${DEVICE}
          sudo tune2fs -i 0 -c 0 -L rootfs ${DEVICE}

          [ -d ${TARGET} ] || mkdir ${TARGET}
          sudo mount -o loop ${DEVICE} ${TARGET}

      3. Then, perform "debootstrap" to install Debian 7 and perform some tweaks/config changes within the debootstrapped Debian 7 image.
      4. Finally; upload, register and launch the image via :


              euca-install-image -i ${IMAGE} -n ${NAME} -r x86_64 --virtualization-type hvm -b ${NAME} -u ${EC2_USER_ID}
              euca-run-instances -k abc -g abc-group -t m1.small emi-9999999

Also, cloud-init and cloud-initramfs-growpart installed and configure with the following settings within the image :

#cloud-config
# The top level settings are used as module and system configuration.

# A set of users which may be applied and/or used by various modules when a 'default' entry is found it will reference the 'default_user' from the distro configuration 
# specified below
users:
   - default

# If this is set, 'root' will not be able to ssh in and they will get a message to login instead as the above $user (ubuntu)
disable_root: true
# This will cause the set+update hostname module to not operate (if true)
preserve_hostname: false
# Enable hosts file management
manage_etc_hosts: True

# The modules that run in the 'init' stage
cloud_init_modules:
 - migrator
 - bootcmd
 - write-files
 - growpart
 - resizefs
 - set_hostname
 - update_hostname
 - update_etc_hosts
 - ca-certs
 - rsyslog
 - users-groups
 - ssh
# The modules that run in the 'config' stage
cloud_config_modules:
# Emit the cloud config ready event this can be used by upstart jobs for 'start on cloud-config'.
 - emit_upstart
 - mounts
 - locale
 - set-passwords
 - grub-dpkg
 - apt-pipelining
 - apt-configure
 - package-update-upgrade-install
 - timezone
 - puppet
 - chef
 - salt-minion
 - mcollective
 - disable-ec2-metadata
 - runcmd
# The modules that run in the 'final' stage
cloud_final_modules:
 - rightscale_userdata
 - scripts-per-once
 - scripts-per-boot
 - scripts-per-instance
 - scripts-user
 - ssh-authkey-fingerprints
 - keys-to-console
 - phone-home
 - final-message
 - power-state-change

A side note : cloud-init "datasource" was configured only for "EC2". All other options de-selected. 

So, what's the proper way of doing it and/or what are we missing ? I did search on the net and on Eucalyptus web page without luck. Any pointers/documents will be highly appreciated. 

Thanks,

Tarkan
Reply all
Reply to author
Forward
0 new messages