Installation and configuration of cloud-init on the Linux server

IBM® Cloud Infrastructure Center uses cloud-init as its activation engine. It works well with cloud-init 18.5 for RHEL7.7 RHEL7.8, RHEL8.1 and RHEL8.2, cloud-init 18.4 for SLES15 SP1, cloud-init 19.4 for SLES 15 SP2 and clould-init 20.1 for UBUNTU20.04.

If you are using a different version of cloud-init, specify the commands below as required for your version of cloud-init.

During cloud-init installation, some dependency packages might be required. You can use yum, zypper or apt-get to easily resolve these dependencies.

Follow these steps to install and configure the cloud-init service:

Installing and configuring cloud-init on RHEL

  1. ssh to the Linux® server, then run the following to install cloud-init:

    yum install cloud-init    
  2. IBM Cloud Infrastructure Center uses ConfigDrive as the data source for cloud-init. Remember to disable network configure module of cloud-init because the virtual machine network is configured by zvmguestconfigure service in IBM Cloud Infrastructure Center.

    • Add the following lines to the default configuration file /etc/cloud/cloud.cfg:

      datasource_list: [ ConfigDrive, None ]
      datasource:
          ConfigDrive:
              dsmode: local
      network: {config: disabled}
    • When making images to be used to boot virtual machine from volume, disable the mounts module from cloud-init by removing the - mounts line in the cloud_config_modules section:

      cloud_config_modules:
      - locale
      - set-passwords

    Note: Pay attention to the indentation, otherwise cloud-init might not work as expected.

  3. Optionally, the default /etc/cloud/cloud.cfg file supports login by ssh key. If you want to log in by user name and password via ssh, configure the /etc/cloud/cloud.cfg file:

    ssh_pwauth:1
  4. Optionally, to enable root login, you can configure the /etc/cloud/cloud.cfg file:

    disable_root: false
  5. Enable and start the cloud-init related services by running the following commands:

    systemctl enable cloud-init-local.service
    systemctl start cloud-init-local.service
    systemctl enable cloud-init.service
    systemctl start cloud-init.service
    systemctl enable cloud-config.service
    systemctl start cloud-config.service
    systemctl enable cloud-final.service
    systemctl start cloud-final.service

    If you experience problems the first time you start cloud-config.service and cloud-final.service, try to restart them.

  6. Ensure all cloud-init services have an active status by running the following commands:

    systemctl status cloud-init-local.service
    systemctl status cloud-init.service
    systemctl status cloud-config.service
    systemctl status cloud-final.service
  7. To verify the cloud-init configuration, issue the following command. If no errors occur, cloud-init is installed correctly:

    cloud-init init --local
  8. Remove the /var/lib/cloud directory (if it exists) so that cloud-init does not run after a restart:

    rm -rf /var/lib/cloud

Installing and configuring cloud-init on SLES 15

  1. ssh to the Linux® server, then run the following to install cloud-init:

    zypper install cloud-init    

    Note: For SLES 15 SP1 server, the cloud-init package and required dependencies are included in the Basesystem-Module 15.1-0, Public-Cloud-Module 15.1-0 and Server-Applications-Module 15.1-0, make sure you can access these modules to install cloud-init.

  2. IBM Cloud Infrastructure Center uses ConfigDrive as the data source for cloud-init. Remember to disable network configure module of cloud-init because the virtual machine network is configured by zvmguestconfigure service in IBM Cloud Infrastructure Center.

    • You must add the following lines to the default configuration file /etc/cloud/cloud.cfg:

      datasource_list: [ ConfigDrive, None ]
      datasource:
          ConfigDrive:
              dsmode: local
      network: {config: disabled}

    Note: Pay attention to the indentation, otherwise cloud-init might not work as expected.

  3. Enable and start the cloud-init related services by running the following commands:

    systemctl enable cloud-init-local.service
    systemctl start cloud-init-local.service
    systemctl enable cloud-init.service
    systemctl start cloud-init.service
    systemctl enable cloud-config.service
    systemctl start cloud-config.service
    systemctl enable cloud-final.service
    systemctl start cloud-final.service

    If you experience problems the first time you start cloud-config.service and cloud-final.service, try to restart them.

  4. Ensure all cloud-init services have an active status by running the following commands:

    systemctl status cloud-init-local.service
    systemctl status cloud-init.service
    systemctl status cloud-config.service
    systemctl status cloud-final.service
  5. To verify the cloud-init configuration, issue the following command. If no errors occur, cloud-init is installed correctly:

    cloud-init init --local
  6. Remove the /var/lib/cloud directory (if it exists) so that cloud-init does not run after a restart:

    rm -rf /var/lib/cloud

Installing and configuring cloud-init on Ubuntu 20.04

  1. If you do not install cloud-init during the installation, after the installation complete, ssh to the Linux® server, then run the following to install cloud-init:

    apt-get install cloud-init
  2. IBM Cloud Infrastructure Center uses ConfigDrive as the data source for cloud-init. Remember to disable network configure module of cloud-init because the virtual machine network is configured by zvmguestconfigure service in IBM Cloud Infrastructure Center

    • You must add the following lines to the default configuration file /etc/cloud/cloud.cfg:

      datasource_list: [ ConfigDrive, None ]
      datasource:
          ConfigDrive:
              dsmode: local
      network: {config: disabled}

    Note: Pay attention to the indentation, otherwise cloud-init might not work as expected.

  3. Check if the file /etc/cloud/ds-identity.cfg with below content existed, if not, create this file with below content.

    policy: enabled
  4. Enable and start the cloud-init related services by running the following commands:

    systemctl enable cloud-init-local.service
    systemctl start cloud-init-local.service
    systemctl enable cloud-init.service
    systemctl start cloud-init.service
    systemctl enable cloud-config.service
    systemctl start cloud-config.service
    systemctl enable cloud-final.service
    systemctl start cloud-final.service

    If you experience problems the first time you start cloud-config.service and cloud-final.service, try to restart them.

  5. Ensure all cloud-init services have an active status by running the following commands:

    systemctl status cloud-init-local.service
    systemctl status cloud-init.service
    systemctl status cloud-config.service
    systemctl status cloud-final.service
  6. To verify the cloud-init configuration, issue the following command. If no errors occur, cloud-init is installed correctly:

    cloud-init init --local
  7. Remove the /var/lib/cloud directory (if it exists) so that cloud-init does not run after a restart:

    rm -rf /var/lib/cloud