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:

    #cloud-config
    user: '.$username.'
    ssh_pwauth: True
    chpasswd:
    list: |
     root:'.$rootPW.'
     '.$username.':'.$userPW.'
    expire: False
    resize_rootfs: true
    disk_setup:
    /dev/sda:
      table_type: mbr
      layout: [75, [25, 82]]
      overwrite: True
    fs_setup:
        - device: /dev/sda1
          filesystem: ext4
        - device: /dev/sda2
          filesystem: swap
    mounts:
         - ["/dev/sda1", "/mnt"]
         - ["/dev/sda2", "none", "swap", "sw", "0", "0"]"
    bootcmd:
         - 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:

    bootcmd:

    • 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:

    bootcmd:
    - mkswap /dev/xvdb
    - swapon /dev/xvdb
    

The ssh login issue still persists.

Any suggestions or help is appreciated.

Thanks,

Prashant

-Edit-

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?

Regards,

edit retag flag offensive close merge delete

Comments

HI Prashant,

First ensure the cloudinit script is with proper syntax using online YAML validator.Also to get ssh login check this link: https://ask.openstack.org/en/question... 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