Root disk not getting partitioned via cloud-init

asked 2016-08-02 05:45:47 -0500

prashant_tiwari1 gravatar image

updated 2016-08-03 07:03:55 -0500

Hi All,

  1. I am trying to add a swap of 4GB within root disk of 20 GB via cloud-init in Ubuntu 14.04. The instance is getting created in openstack, however I am not able to ssh to it.

    Following is the cloud-init configuration I am using in perl:

    user: '.$username.'
    ssh_pwauth: True
    list: |
    expire: False
    resize_rootfs: true
      table_type: mbr
      layout: [75, [25, 82]]
      overwrite: True
        - device: /dev/sda1
          filesystem: ext4
        - device: /dev/sda2
          filesystem: swap
         - ["/dev/sda1", "/mnt"]
         - ["/dev/sda2", "none", "swap", "sw", "0", "0"]"
         - sed -i \'/rootfs/s/defaults\t/defaults,discard\t/\' /etc/fstab
         - mount -o remount /
  2. There is a bootcmd which includes sed & mount commands in cloud-init configurations for ubuntu 14.04 as below:


    • sed -i '/rootfs/s/defaults\t/defaults,discard\t/' /etc/fstab
    • mount -o remount /

      The sed command is being used here to make the swap partition permanent.

  3. As the above sed command was giving compilation errors in my perl script, I tried following options:

    i) Escaping single quotes to make the syntax right as below:

    sed -i \'/rootfs/s/defaults\t/defaults,discard\t/\' /etc/fstab

    ii) Tried with double quotes however I am not sure the sed command executed.

    sed -i "/rootfs/s/defaults\t/defaults,discard\t/\" /etc/fstab

    iii) Directly providing mkswap and swapon options under bootcmd as below:

    - mkswap /dev/xvdb
    - swapon /dev/xvdb

The ssh login issue still persists.

Any suggestions or help is appreciated.




I checked the cloudinit script using online YAML validator and removed the extra spaces. Now I am able to create the instance and connect to it through ssh. However, the root disk is not partitioned as required. I could see below entries in /etc/fstab:

LABEL=cloudimg-rootfs   /        ext4   defaults,discard        0 0
/dev/sda1       /mnt    auto    defaults,nobootwait,comment=cloudconfig 0       2
/dev/sda2       none    swap    sw,comment=cloudconfig  0       0

To view all devices marked as swap in the /etc/fstab I used the swapon --all option as below:

swapon --all
swapon: /dev/sda2: stat failed: No such file or directory

Am I missing any configurations?


edit retag flag offensive close merge delete


HI Prashant,

First ensure the cloudinit script is with proper syntax using online YAML validator.Also to get ssh login check this link: Regards

Praveen N gravatar imagePraveen N ( 2016-08-02 08:47:20 -0500 )edit

Hi Praveen, Thanks for your reply. I have edited my question. Regards

prashant_tiwari1 gravatar imageprashant_tiwari1 ( 2016-08-03 05:45:48 -0500 )edit