All Products
Search
Document Center

Elastic Compute Service:Install cloud-init

Last Updated:May 21, 2026

Install cloud-init on a Linux server to enable automatic hostname, network, and user data initialization for ECS instances.

See the official cloud-init documentation.

Use cases

cloud-init is pre-installed on all Alibaba Cloud public images. For custom images, follow the suggestions for your scenario.

  • Linux servers without cloud-init that you plan to migrate to the cloud

    Install cloud-init before migrating a server to Alibaba Cloud so that the resulting ECS instance can run initialization tasks at startup.

    Note

    For servers not being migrated to the cloud, cloud-init may add unnecessary complexity. Decide based on your environment.

  • Linux servers with cloud-init versions earlier than 0.7.9

    Newer versions include more features and bug fixes. Upgrade to a later version for better compatibility and security.

  • ECS instances on Alibaba Cloud that do not have cloud-init installed

    Manually install cloud-init to enable initialization configuration on the instance.

Step 1: Check the cloud-init version

  1. Log on to the source server.

  2. Check whether cloud-init is installed.

    CentOS series

    rpm -qa | grep -i cloud-init 
    pip list | grep -i cloud-init

    Ubuntu series

    dpkg -l | grep -i cloud-init 
    pip list | grep -i cloud-init
    • If no output is returned or the version is earlier than 0.7.9, see Step 2: Install cloud-init.

      Important

      Version 0.7.9 is an early community version not suitable for ECS initialization. Upgrade to a later version.

    • If the version is 18 or later, no installation is needed. To customize the default network configuration, see Disable automatic network initialization by Alibaba Cloud.

    • If the version is 19.1.21, upgrade to Alibaba Cloud cloud-init 23.2.2. Key improvements over 19.1.21:

      • Supports metadata access in security hardening mode. See Instance metadata.

      • Other changes include feature enhancements, performance improvements, and bug fixes. See the ChangeLog file.

    • Other versions: no installation needed. See Next steps.

  3. To prevent data loss, back up your source server data before installation. For example, create a snapshot.

Step 2: Install cloud-init

  • (Recommended) Alibaba Cloud cloud-init 23.2.2: Requires Python 3.6 or later. Data source: Aliyun.

  • Alibaba Cloud cloud-init 19.1.21: Requires Python 3.6 or later. Data source: Aliyun.

  • Alibaba Cloud cloud-init 0.7.6a18: This version is required for some earlier operating systems, such as CentOS 6, Debian 9, and SUSE Linux Enterprise Server 12. It requires Python 2.7 and uses the Aliyun data source.

    Important

    The Python community no longer supports Python 2.7. Use a later version of cloud-init to avoid potential dependency library issues.

  • Community version of cloud-init: Maintained by the cloud-init community. The latest Alibaba Cloud version is 23.2.2. For a later version, install the community version from the official cloud-init website.

The Alibaba Cloud version is optimized for Alibaba Cloud services. Use the Alibaba Cloud version unless you need a later community release.

(Recommended) Alibaba Cloud cloud-init 23.2.2

Alibaba Cloud cloud-init 23.2.2 is distributed as a software package. Install the package for your operating system or build from source.

The following table lists the download links for the packages for different operating systems.

Operating system type

Operating system version

Binary package

MD5SUM check

Source package

Debian

12

https://ecs-image-tools.oss-cn-hangzhou.aliyuncs.com/cloudinit/debian12/cloud-init_23.2.2-8_all.deb

https://ecs-image-tools.oss-cn-hangzhou.aliyuncs.com/cloudinit/debian12/cloud-init_23.2.2-8_all.deb.md5sum

https://ecs-image-tools.oss-cn-hangzhou.aliyuncs.com/cloudinit/cloud-init-23.2.2-8.tar.gz

11

https://ecs-image-tools.oss-cn-hangzhou.aliyuncs.com/cloudinit/debian11/cloud-init_23.2.2-8_all.deb

https://ecs-image-tools.oss-cn-hangzhou.aliyuncs.com/cloudinit/debian11/cloud-init_23.2.2-8_all.deb.md5sum

CentOS Stream

9

https://ecs-image-tools.oss-cn-hangzhou.aliyuncs.com/cloudinit/centosstream9/cloud-init-23.2.2-8.el9.noarch.rpm

https://ecs-image-tools.oss-cn-hangzhou.aliyuncs.com/cloudinit/centosstream9/cloud-init-23.2.2-8.el9.noarch.rpm.md5sum

8

https://ecs-image-tools.oss-cn-hangzhou.aliyuncs.com/cloudinit/centosstream8/cloud-init-23.2.2-8.el8.noarch.rpm

https://ecs-image-tools.oss-cn-hangzhou.aliyuncs.com/cloudinit/centosstream8/cloud-init-23.2.2-8.el8.noarch.rpm.md5sum

Fedora

40

https://ecs-image-tools.oss-cn-hangzhou.aliyuncs.com/cloudinit/fedora40/cloud-init-23.2.2-8.fc40.noarch.rpm

https://ecs-image-tools.oss-cn-hangzhou.aliyuncs.com/cloudinit/fedora40/cloud-init-23.2.2-8.fc40.noarch.rpm.md5sum

39

https://ecs-image-tools.oss-cn-hangzhou.aliyuncs.com/cloudinit/fedora39/cloud-init-23.2.2-8.fc39.noarch.rpm

https://ecs-image-tools.oss-cn-hangzhou.aliyuncs.com/cloudinit/fedora39/cloud-init-23.2.2-8.fc39.noarch.rpm.md5sum

38

https://ecs-image-tools.oss-cn-hangzhou.aliyuncs.com/cloudinit/fedora38/cloud-init-23.2.2-8.fc38.noarch.rpm

https://ecs-image-tools.oss-cn-hangzhou.aliyuncs.com/cloudinit/fedora38/cloud-init-23.2.2-8.fc38.noarch.rpm.md5sum

AlmaLinux

9

https://ecs-image-tools.oss-cn-hangzhou.aliyuncs.com/cloudinit/almalinux9/cloud-init-23.2.2-8.el9.noarch.rpm

https://ecs-image-tools.oss-cn-hangzhou.aliyuncs.com/cloudinit/almalinux9/cloud-init-23.2.2-8.el9.noarch.rpm.md5sum

8

https://ecs-image-tools.oss-cn-hangzhou.aliyuncs.com/cloudinit/almalinux8/cloud-init-23.2.2-8.el8.noarch.rpm

https://ecs-image-tools.oss-cn-hangzhou.aliyuncs.com/cloudinit/almalinux8/cloud-init-23.2.2-8.el8.noarch.rpm.md5sum

Rocky Linux

9

https://ecs-image-tools.oss-cn-hangzhou.aliyuncs.com/cloudinit/rockylinux9/cloud-init-23.2.2-8.el9.noarch.rpm

https://ecs-image-tools.oss-cn-hangzhou.aliyuncs.com/cloudinit/rockylinux9/cloud-init-23.2.2-8.el9.noarch.rpm.md5sum

8

https://ecs-image-tools.oss-cn-hangzhou.aliyuncs.com/cloudinit/rockylinux8/cloud-init-23.2.2-8.el8.noarch.rpm

https://ecs-image-tools.oss-cn-hangzhou.aliyuncs.com/cloudinit/rockylinux8/cloud-init-23.2.2-8.el8.noarch.rpm.md5sum

Ubuntu

24

https://ecs-image-tools.oss-cn-hangzhou.aliyuncs.com/cloudinit/ubuntu24/cloud-init_23.2.2-8_all.deb

https://ecs-image-tools.oss-cn-hangzhou.aliyuncs.com/cloudinit/ubuntu24/cloud-init_23.2.2-8_all.deb.md5sum

22

https://ecs-image-tools.oss-cn-hangzhou.aliyuncs.com/cloudinit/ubuntu22/cloud-init_23.2.2-8_all.deb

https://ecs-image-tools.oss-cn-hangzhou.aliyuncs.com/cloudinit/ubuntu22/cloud-init_23.2.2-8_all.deb.md5sum

20

https://ecs-image-tools.oss-cn-hangzhou.aliyuncs.com/cloudinit/ubuntu20/cloud-init_23.2.2-8_all.deb

https://ecs-image-tools.oss-cn-hangzhou.aliyuncs.com/cloudinit/ubuntu20/cloud-init_23.2.2-8_all.deb.md5sum

The following examples use Debian 12 and CentOS Stream 9 to demonstrate binary package installation.

Debian 12

  1. Download the cloud-init package.

    wget https://ecs-image-tools.oss-cn-hangzhou.aliyuncs.com/cloudinit/debian12/cloud-init_23.2.2-5_all.deb
  2. Install the package.

    sudo apt-get install -y ./cloud-init_23.2.2-5_all.deb
  3. (Optional) To prevent upgrades to a later open source version, hold the cloud-init package at its current version.

    sudo apt-mark hold cloud-init
  4. Verify the cloud-init version.

    cloud-init --version

CentOS Stream 9

  1. Download the cloud-init package.

    wget https://ecs-image-tools.oss-cn-hangzhou.aliyuncs.com/cloudinit/centosstream9/cloud-init-23.2.2-5.el9.noarch.rpm
  2. Install the package.

    sudo yum install -y ./cloud-init-23.2.2-5.el9.noarch.rpm
  3. (Optional) To prevent upgrades to a later open source version, lock the cloud-init package at its current version.

    sudo sh -c 'echo "exclude=cloud-init" >> /etc/dnf/dnf.conf'
  4. Verify the cloud-init version.

    cloud-init --version
Note

By default, Alibaba Cloud cloud-init 23.2.2 no longer maps the hostname to the private IPv4 address in the /etc/hosts file. If your business requires this mapping, configure it manually. Later OS versions use the nss-myhostname component for hostname connectivity. This component is provided by the systemd-libs package (Red Hat series) or the libnss-myhostname package (Debian series) and enabled through the /etc/nsswitch.conf file. See the nss-myhostname manual.

Alibaba Cloud cloud-init 19.1.21

  1. Ensure the Python PIP dependency library is installed.

    Install the python3-pip dependency library on your Linux distribution:

    CentOS/Red Hat Enterprise Linux

    sudo yum -y install python3-pip

    Ubuntu/Debian

    sudo apt-get -y install python3-pip

    OpenSUSE/SUSE

    sudo zypper -n install python3-pip
  2. Download Alibaba Cloud cloud-init.

    wget https://ecs-image-tools.oss-cn-hangzhou.aliyuncs.com/cloudinit/cloud-init-19.1.21.tgz
  3. Decompress the cloud-init package.

    tar -zxvf cloud-init-19.1.21.tgz
  4. Go to the cloud-init directory and install the dependency libraries.

    cd ./cloud-init-19.1.21
    pip3 install -r ./requirements.txt
  5. Go to the tools subdirectory of the cloud-init directory.

    cd ./tools
  6. Run the deploy.sh script to install cloud-init.

    sudo bash ./deploy.sh <issue> <major_version>

    Parameters of the deploy.sh script:

    Parameter

    Description

    Example

    <issue>

    The operating system platform type. Valid values: centos, redhat, rhel, debian, ubuntu, opensuse, and sles. The parameter values are case-sensitive. sles specifies SUSE/SLES.

    Note

    If the operating system is CentOS Stream, set this parameter to centos.

    centos

    <major_version>

    The major version number of the operating system platform.

    Note

    You cannot install Alibaba Cloud cloud-init 19.1.21 on Ubuntu 14.

    The major version number of CentOS 7.6 is 7.

    For example, if your current operating system is CentOS 7, run the command sudo bash ./deploy.sh centos 7.

  7. Verify cloud-init is installed.

    If "description": "success" is returned, the installation succeeded.Alibaba Cloud cloud-init installation successful

  8. Verify the cloud-init version.

    cloud-init --version

Sample shell scripts to install Alibaba Cloud cloud-init on different Linux distributions. Modify the script for your operating system.

CentOS 7/8

# Check and install python3-pip.
if ! python3 -c 'import setuptools' >& /dev/null; then
  yum -y install python3-pip
fi
# Back up the old version of cloud-init.
test -d /etc/cloud && mv /etc/cloud /etc/cloud-old
# Download and decompress the Alibaba Cloud cloud-init package.
wget https://ecs-image-tools.oss-cn-hangzhou.aliyuncs.com/cloudinit/cloud-init-19.1.21.tgz
tar -zxvf ./cloud-init-19.1.21.tgz
# Install cloud-init.
issue_major=$( cat /etc/redhat-release | grep -Eo '[0-9]+\.?[0-9]+' | head -1 | awk -F'.' '{printf $1}')
bash ./cloud-init-*/tools/deploy.sh centos "$issue_major"

Red Hat Enterprise Linux 7/8

# Check and install python3-pip.
if ! python3 -c 'import setuptools' >& /dev/null; then
  yum -y install python3-pip
fi
# Back up the old version of cloud-init.
test -d /etc/cloud && mv /etc/cloud /etc/cloud-old
# Download and decompress the Alibaba Cloud cloud-init package.
wget https://ecs-image-tools.oss-cn-hangzhou.aliyuncs.com/cloudinit/cloud-init-19.1.21.tgz
tar -zxvf ./cloud-init-19.1.21.tgz
# Install cloud-init.
issue_major=$( cat /etc/os-release | grep VERSION_ID | grep -Eo '[0-9]+\.?[0-9]+' | head -1 | awk -F'.' '{printf $1}')
bash ./cloud-init-*/tools/deploy.sh rhel "$issue_major"

Ubuntu 16/18/20

# Check and install python3-pip.
if ! python3 -c 'import setuptools' >& /dev/null; then
  apt-get install python36 python3-pip -y
fi
# Back up the old version of cloud-init.
test -d /etc/cloud && mv /etc/cloud /etc/cloud-old
# Download and decompress the Alibaba Cloud cloud-init package.
wget https://ecs-image-tools.oss-cn-hangzhou.aliyuncs.com/cloudinit/cloud-init-19.1.21.tgz
tar -zxvf ./cloud-init-19.1.21.tgz
# Install cloud-init.
issue_major=$( cat /etc/os-release | grep VERSION_ID | grep -Eo '[0-9]+\.?[0-9]+' | head -1 | awk -F'.' '{printf $1}')
bash ./cloud-init-*/tools/deploy.sh ubuntu "$issue_major"

Debian 9/10

# Check and install python3-pip.
if ! python3 -c 'import setuptools' >& /dev/null; then
  apt-get -y install python3-pip
fi
# Back up the old version of cloud-init.
test -d /etc/cloud && mv /etc/cloud /etc/cloud-old
# Download and decompress the Alibaba Cloud cloud-init package.
wget https://ecs-image-tools.oss-cn-hangzhou.aliyuncs.com/cloudinit/cloud-init-19.1.21.tgz
tar -zxvf ./cloud-init-19.1.21.tgz
# Install cloud-init.
issue_major=$( cat /etc/os-release | grep VERSION_ID | grep -Eo '[0-9]+\.?[0-9]+' | head -1 | awk -F'.' '{printf $1}')
bash ./cloud-init-*/tools/deploy.sh debian "$issue_major"

SUSE 12/15

# Check and install python3-pip.
if ! python3 -c 'import setuptools'>& /dev/null; then
  zypper -n install python3-pip
fi
# Back up the old version of cloud-init.
test -d /etc/cloud && mv /etc/cloud /etc/cloud-old
# Download and decompress the Alibaba Cloud cloud-init package.
wget https://ecs-image-tools.oss-cn-hangzhou.aliyuncs.com/cloudinit/cloud-init-19.1.21.tgz
tar -zxvf ./cloud-init-19.1.21.tgz
# Install cloud-init.
issue_major=$( cat /etc/os-release | grep VERSION_ID | grep -Eo '[0-9]+\.?[0-9]+' | head -1 | awk -F'.' '{printf $1}')
bash ./cloud-init-*/tools/deploy.sh sles "$issue_major"

OpenSUSE 15

# Check and install python3-pip.
if ! python3 -c 'import setuptools'>& /dev/null; then
  zypper -n install python3-pip
fi
# Back up the old version of cloud-init.
test -d /etc/cloud && mv /etc/cloud /etc/cloud-old
# Download and decompress the Alibaba Cloud cloud-init package.
wget https://ecs-image-tools.oss-cn-hangzhou.aliyuncs.com/cloudinit/cloud-init-19.1.21.tgz
tar -zxvf ./cloud-init-19.1.21.tgz
# Install cloud-init.
issue_major=$( cat /etc/os-release | grep VERSION_ID | grep -Eo '[0-9]+\.?[0-9]+' | head -1 | awk -F'.' '{printf $1}')
bash ./cloud-init-*/tools/deploy.sh opensuse "$issue_major"

Alibaba Cloud cloud-init 0.7.6a18

Note

The Alibaba Cloud public images for CentOS 6, Debian 9, and SUSE Linux Enterprise Server 12 have cloud-init-0.7.6a18 installed by default. If you need to perform testing, first run the sudo mv /etc/cloud/cloud.cfg /etc/cloud/cloud.cfg_bak command to back up the configuration file.

  1. Check whether the operating system is CentOS 6, Debian 9, or SUSE Linux Enterprise Server 12.

    cat /etc/issue
  2. Ensure the Python PIP dependency library is installed.

    Install the Python 2-pip dependency library:

    CentOS 6/SUSE Linux Enterprise Server 12

    sudo yum -y install python2-pip

    Debian 9

    sudo apt-get -y install python2-pip
  3. Run the following commands to download and decompress the Alibaba Cloud cloud-init 0.7.6a18 package.

    wget https://ecs-image-tools.oss-cn-hangzhou.aliyuncs.com/cloud-init-0.7.6a18.tgz
    tar -zxvf cloud-init-0.7.6a18.tgz
  4. Go to the tools subdirectory of the cloud-init directory.

    cd cloud-init-0.7.6a18/tools/
  5. Install cloud-init.

    sudo bash ./deploy.sh <issue> <major_version>

    For example, if your current operating system is CentOS 6, run the command sudo bash ./deploy.sh centos 6.

    Parameters of the deploy.sh script:

    Parameter

    Description

    Example

    <issue>

    The operating system platform type. Valid values: centos, debian, and sles. The parameter values are case-sensitive. sles specifies SUSE/SLES.

    centos

    <major_version>

    The major version number of the operating system platform.

    The major version number of CentOS 6.5 is 6.

  6. Verify the cloud-init version.

    cloud-init --version

Community version of cloud-init

  1. Ensure Git, Python, and Python PIP dependency libraries are installed.

    Install the Git, Python 3.6, and python3-pip dependency libraries:

    CentOS/Red Hat Enterprise Linux

    sudo yum -y install git python36 python3-pip

    Ubuntu/Debian

    sudo apt-get -y install git python36 python3-pip

    OpenSUSE/SUSE

    sudo zypper -n install git python36 python3-pip
  2. Download the cloud-init source package using Git.

    git clone https://git.launchpad.net/cloud-init
  3. Go to the cloud-init directory.

    cd ./cloud-init
  4. Install all dependency libraries.

    sudo pip3 install -r ./requirements.txt
  5. Install cloud-init.

    python3 setup.py install
  6. Modify the cloud.cfg configuration file.

    1. Open the configuration file.

      sudo vi /etc/cloud/cloud.cfg

      vi /etc/cloud/cloud.cfg

    2. Replace the configuration before cloud_init_modules: with the following content.

      # Example datasource 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
      user:
          name: root
          lock_passwd: False
      # 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
      disable_root: false
      # This will cause the set+update hostname module to not operate (if true)
      preserve_hostname: false
      syslog_fix_perms: root:root
      datasource_list: [ AliYun ]
      # Example datasource config
      datasource:
          AliYun:
              support_xen: false
              timeout: 5 # (defaults to 50 seconds)
              max_wait: 60 # (defaults to 120 seconds)
      #      metadata_urls: [ 'blah.com' ]
      # The modules that run in the 'init' stage
      cloud_init_modules:
  7. Verify the cloud-init version.

    cloud-init --version

(Optional) Step 3: Configure cloud-init

Disable automatic network initialization by Alibaba Cloud

If your cloud-init version is 18 or later, it automatically initializes the network with: BOOTPROTO=dhcp DEVICE=eth0 ONBOOT=yes STARTMODE=auto TYPE=Ethernet USERCTL=no. To customize the network configuration, modify the cloud-init configuration file.

  1. Open the default cloud-init configuration file. Press the i key to enter insert mode.

    sudo vim /etc/cloud/cloud.cfg
  2. Before Example datasource config, add the disabled configuration to disable the automatic network configuration feature of cloud-init.

    network:
      config: disabled

    image

    After adding this configuration, cloud-init no longer manages network configuration files, such as ifcfg-eth0, in the /etc/sysconfig/network-scripts/ directory. Manage these files yourself.

  3. Press the Esc key, enter :wq, and press the Enter key to save and close the file.

  4. Customize the network configurations in the /etc/sysconfig/network-scripts/ directory, such as the IP address, subnet mask, and gateway.

Disable automatic hostname setting by Alibaba Cloud

By default, cloud-init sets the hostname and updates the /etc/hostname file at instance startup. To prevent hostname changes, modify the cloud-init configuration file.

  1. Open the default cloud-init configuration file. Press the i key to enter edit mode.

    sudo vim /etc/cloud/cloud.cfg
  2. In the configuration file, change preserve_hostname: false to preserve_hostname: true.

    image

  3. Press the Esc key, enter :wq, and press the Enter key to save and close the file.

Next steps

  • To migrate Linux servers to the cloud, use Server Migration Center (SMC). See Migrate servers to ECS instances.

  • For ECS instances running a Linux custom image on Alibaba Cloud, restart the system to verify the installation. If the hostname, network, and NTP are automatically configured, cloud-init was installed successfully. View the network configuration file:

    sudo reboot
    cat /etc/sysconfig/network-scripts/ifcfg-eth0

    The following output indicates that cloud-init has configured network settings such as the DHCP protocol, network device, and device type.

    BOOTPROTO=dhcp
    DEVICE=eth0
    ONBOOT=yes
    STARTMODE=auto
    TYPE=Ethernet
    USERCTL=no

FAQ

  • What should I do if dependency libraries are missing when I install cloud-init using Python 3?

    The missing libraries vary by image. Install them using pip, then install cloud-init again.

  • What should I do if cloud-init runs abnormally and returns an error message?

    If the default package manager (such as yum) and pip installed different versions of the same dependency library, version conflicts may cause cloud-init to run abnormally. Download the required dependency libraries based on the error message.

    Error message

    Cause

    Troubleshooting command

    no setuptools module in python

    The python setuptools module is missing.

    For Python 3.6:

    • CentOS/Red Hat: yum -y install python3-pip

    • Ubuntu/Debian: apt-get -y install python3-pip

    • OpenSUSE/SUSE: zypper -n install python3-pip

    File "/home/testuser/cloud-init/cloudinit/log.py", line 19, in <module>
          import six
      ImportError: No module named six  )

    The six dependency library is missing.

    pip3 install six
    File "/home/testuser/cloud-init/cloudinit/url_helper.py", line 20, in <module>
          import oauthlib.oauth1 as oauth1
      ImportError: No module named oauthlib.oauth1  )

    The oauthlib dependency library is missing.

    pip3 install oauthlib

    The error message does not specify a missing dependency library.

    The related error message is not mapped.

    Based on the libraries listed in the requirements.txt file, install all dependency libraries:

    pip3 install -r requirements.txt
  • What should I do if cloud-init runs abnormally after a new version of Python 3 is installed on the instance?

    If you install a new version of Python 3, such as Python 3.9, and set it as the default version by creating a symbolic link (for example, ln -s /usr/bin/python3.9 /usr/bin/python3), the installed cloud-init may run abnormally. For example, running cloud-init --version returns an error:

    $cloud-init --version
    Traceback (most recent call last):
      File "/usr/local/bin/cloud-init", line 33, in <module>
        sys.exit(load_entry_point('cloud-init==19.1.9', 'console_scripts', 'cloud-init')())
      File "/usr/local/bin/cloud-init", line 22, in importlib_load_entry_point
        for entry_point in distribution(dist_name).entry_points
      File "/usr/lib64/python3.9/importlib/metadata.py", line 524, in distribution
        return Distribution.from_name(distribution_name)
      File "/usr/lib64/python3.9/importlib/metadata.py", line 187, in from_name
        raise PackageNotFoundError(name)
    importlib.metadata.PackageNotFoundError: cloud-init

    Use one of the following methods to resolve this issue:

    • Method 1: Reinstall cloud-init using the new version of Python 3.

    • Method 2: Modify the cloud-init executable file to change the Python interpreter path to the previous Python 3 version. The following example changes the interpreter to Python 3.6:

      1. Open the cloud-init file.

        vim   /usr/local/bin/cloud-init
      2. Press i to enter edit mode. At the beginning of the file, change the content after #! to the Python 3.6 path.

        After modification, the line starting with #! reads:

        #!/usr/bin/python3.6
      3. Press the Esc key to exit edit mode. Enter :wq and press Enter to save and close the file.

  • After I install cloud-init, why does the instance user data that I set during instance creation fail to run?

    1. Check whether user data exists in the instance metadata.

      curl http://100.100.100.200/latest/user-data

      Result:

      • If user data is returned, proceed to the next step to troubleshoot.

      • If no data is returned, user data was not set.

    2. Use one of the following methods to identify the cause.

      • Check whether the user data format is correct.

        User data is executed by cloud-init and must be in the correct format. For example, the first line must start with #!. See Customize instance initialization configurations.

      • Check the /var/log/cloud-init.log log file for errors and troubleshoot based on the error message.

        Example log entry:

         util.py[DEBUG]: Running command ['/var/lib/cloud/instance/scripts/part-001'] with allowed return codes [0] (shell=False, capture=False)
      • View the standard output and standard error output of the user data execution.

        In systemd, user data runs through the cloud-final.service. View its standard output and error output to troubleshoot:

        journalctl -u cloud-final.service
      • If the preceding methods do not identify the issue, copy the user data to a local host for debugging.

  • After I install cloud-init, why don't the system initialization configurations and instance user data script run as expected?

    1. Check whether the four cloud-init services are enabled at boot.

      systemctl is-enabled cloud-init-local.service
      systemctl is-enabled cloud-init.service
      systemctl is-enabled cloud-config.service
      systemctl is-enabled cloud-final.service

      If an error or disabled is returned, cloud-init is not enabled at boot.

    2. Enable cloud-init at boot.

      systemctl enable cloud-init-local.service
      systemctl enable cloud-init.service
      systemctl enable cloud-config.service
      systemctl enable cloud-final.service
  • I resized the system disk when I created an instance, but the root partition was not automatically resized. What should I do?

    Automatic partition resizing for Linux instances requires cloud-init. Ensure growpart is installed and the cloud.cfg file is correctly configured.

    1. Check whether growpart is installed.

      which growpart
    2. (Required if applicable) If not installed, install it.

      • For RHEL series:

        sudo yum -y install cloud-utils-growpart
      • For Debian series:

        sudo apt -y install cloud-guest-utils
    3. Check whether the /etc/cloud/cloud.cfg file contains the content shown below.

      cat /etc/cloud/cloud.cfg

      Configuration content

    4. (Required if applicable) If the content is missing, add it to the /etc/cloud/cloud.cfg file.

  • For an ECS instance with cloud-init 0.7.6a16 or earlier, the hostname is not updated after I change it in the console and restart the instance. What should I do?

    • Problem description

      After you update the hostname in the ECS console and restart the instance, the new hostname does not take effect. The cloud-init --version command shows version 0.7.6a16 or earlier.

    • Cause

      When cloud-init uses the update_hostname module to update the hostname, it runs the hostname command to get the current system hostname and reads /var/lib/cloud/data/previous-hostname for the cached hostname. It compares the two: if they match, it updates the hostname; if they differ, it assumes the hostname was manually changed and skips the update.

      In Red Hat-based operating systems, the content read from /var/lib/cloud/data/previous-hostname contains a line feed, but the hostname command output does not. This mismatch prevents the hostname from being updated.

    • Solution

      Use one of the following solutions:

      • Upgrade the cloud-init version. See Step 2: Install cloud-init.

        • For CentOS 6 and earlier, use cloud-init 0.7.6a18.

        • For CentOS 7, use cloud-init 19.1.21.

        • For CentOS 8 or later, use cloud-init 23.2.2 or a later version.

      • Manually handle the line feed.

        Manually fix the defective file cloudinit/distros/rhel.py in cloud-init (use find / -name rhel.py to locate the file). Refer to distros/rhel.py: _read_hostname() missing strip on "hostname" to process the line feed in the hostname command output:

        diff --git a/cloudinit/distros/rhel.py b/cloudinit/distros/rhel.py
        index 0b68414e..65176e99 100644
        --- a/cloudinit/distros/rhel.py
        +++ b/cloudinit/distros/rhel.py
        @@ -143,6 +143,7 @@ class Distro(distros.Distro):
                     return util.load_file(filename).strip()
                 elif self.uses_systemd():
                     (out, _err) = util.subp(['hostname'])
        +            out = out.strip()
                     if len(out):
                         return out
                     else: