cloud-init is an open source initialization tool that automates initialization operations for Linux operating systems, such as generating an initial password, configuring the hostname, and running user data scripts. If you want to migrate an on-premises custom image on which cloud-init is not installed to Alibaba Cloud, you can manually install cloud-init. If you do not install cloud-init, Elastic Compute Service (ECS) instances created from the custom image cannot automatically perform initialization tasks such as configuring the hostname and network settings. This may affect the efficiency of automated deployment and configuration of the ECS instances. This topic describes how to install cloud-init in Linux operating systems.
Scenarios
By default, cloud-init is installed on all Alibaba Cloud public images. To ensure that ECS instances created from on-premises custom images can automatically initialize system configurations, we recommend that you refer to the following suggestions and perform related operations based on your actual scenarios:
Cloud-init is not installed on the Linux servers that you want to migrate to Alibaba Cloud.
Before you migrate a Linux server on which cloud-init is not installed to Alibaba Cloud, install cloud-init on the server. This way, ECS instances that are created based on the Linux server can be automatically initialized during system boot.
Note
If you do not want to migrate a Linux server to Alibaba Cloud, installing cloud-init on the server may cause unnecessary complexity or resource usage. Determine whether to install cloud-init based on your actual environment.
Cloud-init 0.7.9 or earlier is installed on Linux servers.
In most cases, more recent cloud-init versions include more features and fixes to ensure compatibility with the latest cloud platform features. If cloud-init of an outdated version is installed on your Linux server, we recommend that you upgrade cloud-init to a version later than 0.7.9 to maximize compatibility and security.
Cloud-init is not installed on ECS instances.
If cloud-init is not installed on an ECS instance, we recommend that you install cloud-init on the instance to ensure that the instance can be automatically initialized.
Step 1: Check whether cloud-init needs to be installed or upgraded
Log on to the source server.
Check whether cloud-init is installed on the source server.
CentOS series
Ubuntu series
rpm -qa | grep -i cloud-init
pip list | grep -i cloud-init
dpkg -l | grep -i cloud-init
pip list | grep -i cloud-init
If no version number is returned or the version of cloud-init is 0.7.9 or earlier, proceed to Step 2: Install cloud-init.
Important
cloud-init 0.7.9 is an initial version of the native cloud-init, which is not suitable for ECS instances and must be upgraded.
If cloud-init 18 or later is used, cloud-init can automatically configure networks during instance initialization. If the network configurations do not meet your business requirements, you can Customize network configurations based on your needs.
If cloud-init 19.1.21 is used, we recommend that you upgrade to Alibaba Cloud cloud-init 23.2.2. Compared with Alibaba Cloud cloud-init 19.1.21, Alibaba Cloud cloud-init 23.2.2 provides the following improvements and new features:
Cloud-init 23.2.2 allows you to access instance metadata in security hardening mode. For information about instance metadata, see Obtain instance metadata.
Other feature enhancements, performance improvements, error fixes, and community contributions. For more information, see ChangeLog.
If other version numbers of cloud-init are returned, perform the operations that are described in the What to do next section of this topic.
To prevent data loss caused by misoperations during cloud-init installation, we recommend that you back up the data of the source server in advance. For example, you can create snapshots to back up the data of the source server.
Step 2: Install cloud-init
(Recommended) Alibaba Cloud cloud-init 23.2.2: This version requires Python 3.6 or later and uses Aliyun
as the data source.
Alibaba Cloud cloud-init 19.1.21: This version requires Python 3.6 or later and uses Aliyun
as the data source.
Alibaba Cloud cloud-init 0.7.6a17: Install this version of cloud-init on specific earlier operating system versions, such as CentOS 6, Debian 9, and SUSE Linux Enterprise Server (SLES) 12. Alibaba Cloud cloud-init 0.7.6a17 requires Python 2.7 and uses Aliyun
as the data source.
Important
The Python community no longer provides technical support for Python 2.7. To prevent risks that are associated with dependency libraries, we recommend that you use more recent versions of cloud-init.
Native cloud-init: The community versions of cloud-init are official versions that are publicly available and maintained by the community of developers who contribute to the project. The most recent version of Alibaba Cloud cloud-init is 23.2.2. If you want to use a more recent version of cloud-init, install a community version of cloud-init. For more information, visit the official cloud-init website.
Alibaba Cloud cloud-init is optimized for and can provide better support for Alibaba Cloud services. To ensure compatibility, we recommend that you use Alibaba Cloud cloud-init. Select a cloud-init version to install based on your business requirements.
(Recommended) Install Alibaba Cloud cloud-init 23.2.2
Install Alibaba Cloud cloud-init 19.1.21
Install Alibaba Cloud cloud-init 0.7.6a17
Install native cloud-init
The most recent version of Alibaba Cloud cloud-init is 23.2.2. Alibaba Cloud cloud-init 23.2.2 is maintained as a package. You can download a package that is suitable for your operating system version or use the source code package to install Alibaba Cloud cloud-init 23.2.2.
Download links of Alibaba Cloud cloud-init 23.2.2 packages for different operating systems
The following sections describe how to download the binary packages of cloud-init and install cloud-init on Debian 12 and CentOS Stream 9.
Run the following command to download the Alibaba Cloud cloud-init package:
wget https://ecs-image-tools.oss-cn-hangzhou.aliyuncs.com/cloudinit/debian12/cloud-init_23.2.2-5_all.deb
Run the following command to install the Alibaba Cloud cloud-init package:
sudo apt-get install -y ./cloud-init_23.2.2-5_all.deb
(Optional) To prevent the Alibaba Cloud cloud-init package from being automatically updated or upgraded to a more recent open source version, we recommend that you run the following command to hold the package at the current version:
sudo apt-mark hold cloud-init
Run the following command to check whether the cloud-init version is as expected:
Run the following command to download the Alibaba Cloud cloud-init package:
wget https://ecs-image-tools.oss-cn-hangzhou.aliyuncs.com/cloudinit/centosstream9/cloud-init-23.2.2-5.el9.noarch.rpm
Run the following command to install the Alibaba Cloud cloud-init package:
sudo yum install -y ./cloud-init-23.2.2-5.el9.noarch.rpm
(Optional) To prevent the Alibaba Cloud cloud-init package from being automatically updated or upgraded to a more recent open source version, we recommend that you run the following command to hold the package at the current version:
sudo sh -c 'echo "exclude=cloud-init" >> /etc/dnf/dnf.conf'
Run the following command to check whether the cloud-init version is as expected:
Note
Alibaba Cloud cloud-init 23.2.2 no longer automatically adds hostname-to-private IPv4 address mappings to the /etc/hosts file. You can manually add the mappings to the file based on your business requirements. In recent operating system versions, the nss-myhostname module is used to provide hostname resolution. In Red Hat operating systems, the nss-myhostname module is included in the systemd-libs package. In Debian operating systems, the nss-myhostname module is included in the libnss-myhostname package. The /etc/nsswitch.conf configuration file is used to enable the nss-myhostname module. For more information, see nss-myhostname(8) - Linux manual page.
Make sure that the python-pip dependency library is installed on the source server.
In the examples, the python3-pip dependency library is used. Run one of the following commands to install the python-pip dependency library based on the operating system of the source server.
CentOS and Red Hat Enterprise Linux (RHEL)
Ubuntu and Debian
openSUSE and SUSE
sudo yum -y install python3-pip
sudo apt-get -y install python3-pip
sudo zypper -n install python3-pip
Run the following command to download the Alibaba Cloud cloud-init installation package:
wget https://ecs-image-tools.oss-cn-hangzhou.aliyuncs.com/cloudinit/cloud-init-19.1.21.tgz
Run the following command to decompress the Alibaba Cloud cloud-init installation package to the current directory:
tar -zxvf cloud-init-19.1.21.tgz
Run the following commands to go to the cloud-init directory and install the dependency library:
cd ./cloud-init-19.1.21
pip3 install -r ./requirements.txt
Run the following command to go to the tools subdirectory of the cloud-init directory:
Run the following command to execute the deploy.sh script to install Alibaba Cloud cloud-init:
sudo bash ./deploy.sh <issue> <major_version>
The following table describes the parameters and the corresponding values in the deploy.sh script.
Parameter | Description | Example |
<issue> | The type of the operating system. Valid values: centos, redhat, rhel, debian, ubuntu, opensuse, and sles. The value of this parameter is case-sensitive. sles specifies SUSE or 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. 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 the current operating system is CentOS 7, run the sudo bash ./deploy.sh centos 7
command.
Check whether Alibaba Cloud cloud-init is installed.
If Alibaba Cloud cloud-init is installed, "description": "success"
is returned.
Run the following command to check whether the cloud-init version is as expected:
The following section provides sample shell scripts that you can use to install Alibaba Cloud cloud-init on different Linux distributions. Modify the shell script based on the operating system.
CentOS 7 and CentOS 8
RHEL 7 and RHEL 8
Ubuntu 16, Ubuntu 18, and Ubuntu 20
Debian 9 and Debian 10
SUSE 12 and SUSE 15
openSUSE 15
# Check whether the python3-pip dependency library is installed. If the python3-pip dependency library is not installed, install the dependency library.
if ! python3 -c 'import setuptools' >& /dev/null; then
yum -y install python3-pip
fi
# Back up cloud-init of an earlier version.
test -d /etc/cloud && mv /etc/cloud /etc/cloud-old
# Download and decompress the Alibaba Cloud cloud-init installation 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 Alibaba Cloud 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"
# Check whether the python3-pip dependency library is installed. If the python3-pip dependency library is not installed, install the dependency library.
if ! python3 -c 'import setuptools' >& /dev/null; then
yum -y install python3-pip
fi
# Back up cloud-init of an earlier version.
test -d /etc/cloud && mv /etc/cloud /etc/cloud-old
# Download and decompress the Alibaba Cloud cloud-init installation 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 Alibaba Cloud 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"
# Check whether the python3-pip dependency library is installed. If the python3-pip dependency library is not installed, install the dependency library.
if ! python3 -c 'import setuptools' >& /dev/null; then
apt-get install python36 python3-pip -y
fi
# Back up cloud-init of an earlier version.
test -d /etc/cloud && mv /etc/cloud /etc/cloud-old
# Download and decompress the Alibaba Cloud cloud-init installation 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 Alibaba Cloud 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"
# Check whether the python3-pip dependency library is installed. If the python3-pip dependency library is not installed, install the dependency library.
if ! python3 -c 'import setuptools' >& /dev/null; then
apt-get -y install python3-pip
fi
# Back up cloud-init of an earlier version.
test -d /etc/cloud && mv /etc/cloud /etc/cloud-old
# Download and decompress the Alibaba Cloud cloud-init installation 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 Alibaba Cloud 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"
# Check whether the python3-pip dependency library is installed. If the python3-pip dependency library is not installed, install the dependency library.
if ! python3 -c 'import setuptools'>& /dev/null; then
zypper -n install python3-pip
fi
# Back up cloud-init of an earlier version.
test -d /etc/cloud && mv /etc/cloud/etc/cloud-old
# Download and decompress the Alibaba Cloud cloud-init installation 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 Alibaba Cloud 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"
# Check whether the python3-pip dependency library is installed. If the python3-pip dependency library is not installed, install the dependency library.
if ! python3 -c 'import setuptools'>& /dev/null; then
zypper -n install python3-pip
fi
# Back up cloud-init of an earlier version.
test -d /etc/cloud && mv /etc/cloud/etc/cloud-old
# Download and decompress the Alibaba Cloud cloud-init installation 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 Alibaba Cloud 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"
Note
By default, Alibaba Cloud cloud-init-0.7.6a17
is installed on Alibaba Cloud public images for CentOS 6, Debian 9, and SLES 12. If you want to test Alibaba Cloud cloud-init 0.7.6a17, run the sudo mv /etc/cloud/cloud.cfg /etc/cloud/cloud.cfg_bak
command to back up the configuration file first.
Run the following command to check whether the operating system version is CentOS 6, Debian 9, or SLES 12:
Make sure that the python-pip dependency library is installed on the source server.
In this example, the python2-pip dependency library is used. Run the following command to install the python2-pip dependency library:
CentOS 6 and SLES 12
Debian 9
sudo yum -y install python2-pip
sudo apt-get -y install python2-pip
Run the following commands to download and decompress the Alibaba Cloud cloud-init 0.7.6a17 installation package:
wget https://ecs-image-tools.oss-cn-hangzhou.aliyuncs.com/cloud-init-0.7.6a17.tgz
tar -zxvf cloud-init-0.7.6a17.tgz
Run the following command to go to the tools subdirectory of the cloud-init directory:
cd cloud-init-0.7.6a17/tools/
Run the following command to execute the deploy.sh script to install Alibaba Cloud cloud-init:
sudo bash ./deploy.sh <issue> <major_version>
For example, if the current operating system is CentOS 6, run the sudo bash ./deploy.sh centos 6
command to install Alibaba Cloud cloud-init.
The following table describes the parameters and the corresponding values in the deploy.sh script.
Parameter | Description | Example |
<issue> | The type of the operating system. Valid values: centos, debian, and sles. The value of this parameter is case-sensitive. sles specifies SUSE or SLES. | centos |
<major_version> | The major version number of the operating system. | The major version number of CentOS 6.5 is 6. |
Run the following command to check whether the cloud-init version is as expected:
Make sure that the Git, Python, and python-pip dependency libraries are installed on the source server.
In the examples, Git, Python 3.6, and python3-pip are used. Run the following commands to install Git, Python, and python-pip dependency libraries for specific Linux distributions.
CentOS and RHEL
Ubuntu and Debian
openSUSE and SUSE
sudo yum -y install git python36 python3-pip
sudo apt-get -y install git python36 python3-pip
sudo zypper -n install git python36 python3-pip
Run the following command to download the cloud-init source code repository from Git:
git clone https://git.launchpad.net/cloud-init
Run the following command to go to the cloud-init directory:
Run the following command to install all required dependency libraries:
sudo pip3 install -r ./requirements.txt
Run the following command to install cloud-init:
Modify the cloud.cfg configuration file.
Open the cloud.cfg configuration file.
sudo vi /etc/cloud/cloud.cfg

Replace the content that precedes 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:
Run the following command to check whether the cloud-init version is as expected:
(Optional) Step 3: Configure cloud-init
Customize network configurations
In cloud-init 18 and later versions, initialization is performed to automatically apply the following network settings: BOOTPROTO=dhcp DEVICE=eth0 ONBOOT=yes STARTMODE=auto TYPE=Ethernet USERCTL=no
. If the default network settings do not meet your business requirements, you can perform the following operations to modify the cloud-init configuration file to customize the network settings:
Run the following command to open the cloud-init
default configuration file. Press the I
key to enter the insert mode.
sudo vim /etc/cloud/cloud.cfg
Add the following disabled configuration before Example datasource config
to disable automatic network configuration:
network:
config: disabled

After you add the configuration, you must manually manage the network configuration files such as ifcfg-eth0
in the /etc/sysconfig/network-scripts/ directory because cloud-init does not manage the network configurations.
Press the Esc
key to exit the insert mode, enter :wq
, and then press the Enter
key to save and close the cloud-init configuration file.
Customize the network settings in the /etc/sysconfig/network-scripts/ directory, such as the IP address, subnet mask, and gateway, based on your business requirements.
Disable automatic hostname settings
By default, cloud-init automatically modifies the hostname and /etc/hostname
file of an ECS instance on instance startup. If you do not want to modify the hostname or /etc/hosts file of your ECS instance, you can perform the following operations to modify the cloud-init configuration file:
Run the following command to open the cloud-init
default configuration file. Press the I
key to enter the insert mode.
sudo vim /etc/cloud/cloud.cfg
Change preserve_hostname: false
to preserve_hostname: true
.
Press the Esc
key to exit the insert mode, enter :wq
, and then press the Enter key to save and close the cloud-init configuration file.
What to do next
You can use Server Migration Center (SMC) to migrate Linux servers to Alibaba Cloud. For more information, see Migrate a server to an ECS instance.
After you install cloud-init on an ECS instance that runs a Linux custom image, you can restart the instance to check whether cloud-init is installed as expected. If the hostname, network settings, and Network Time Protocol (NTP) settings of the ECS instance can be automatically configured, cloud-init is installed as expected. For example, run the following cat command to view the network configuration file after the ECS instance is restarted:
sudo reboot
cat /etc/sysconfig/network-scripts/ifcfg-eth0
The following command output shows that the system automatically configured network settings with cloud-init, such as the boot protocol, network device, and device type.
BOOTPROTO=dhcp
DEVICE=eth0
ONBOOT=yes
STARTMODE=auto
TYPE=Ethernet
USERCTL=no
FAQ
-
What do I do if the required dependency libraries are missing after I use Python 3 to install cloud-init?
The dependency libraries that are missing may vary based on the image. You can use pip to install the missing dependency libraries and then re-install cloud-init.
-
What do I do if cloud-init does not run as expected and an error message is returned?
If different versions of dependency libraries are installed by using the default software package manager (such as YUM) and the pip manager, library version conflicts may occur and cause errors in cloud-init. We recommend that you download dependency libraries based on the error message.
Error message | Cause | Troubleshooting command |
no setuptools module in python
| The python setuptools module is missing. | For example, if you use Python 3.6, run one of the following commands based on the operating system to install the python setuptools module: CentOS and Red Hat: yum -y install python3-pip Ubuntu and Debian: apt-get -y install python3-pip openSUSE and 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. |
|
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. |
|
No indication of a missing dependency library. | The error message does not indicate a cause. | Run the following command to install all dependency libraries that are displayed in the requirements.txt file of cloud-init:
pip3 install -r requirements.txt
|
-
What do I do if cloud-init does not run as expected on an ECS instance after I install a new version of Python 3 on the instance?
If you install a new version of Python 3 such as Python 3.9 on an ECS instance and create a symbolic link (such as ln -s /usr/bin/python3.9 /usr/bin/python3) for the version to configure the installed version as the default version, cloud-init does not run as expected on the instance. For example, when you run the cloud-init --version command, an error is reported.
$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
You can use one of the following methods to resolve the issue:
Method 1: Use the new version of Python 3 to re-install cloud-init.
Method 2: Modify the cloud-init executable file to set the Python interpreter path to the path of an earlier Python 3 version. In this example, Python 3.6 is used. Perform the following operations to change the Python interpreter path in the cloud-init executable file:
Run the following command to open the cloud-init executable file:
vim /usr/local/bin/cloud-init
Press the I key to enter Insert mode. At the beginning of the executable file, replace the content that follows #!
with the path of Python 3.6.
Example of the new content on the line that starts with #!
:
Press the Esc key to exit Insert mode, enter :wq
, and then press the Enter key to save and close the file.
-
What do I do if the user data that I specified for an instance during instance creation does not or cannot run after I install cloud-init on the instance?
Run the following command on the instance to check whether the user data exists in the instance metadata:
curl http://100.100.100.200/latest/user-data
Command output:
If the user data exists in the instance metadata, the command output contains the user data. In this case, perform other operations to troubleshoot the issue.
If the user data does not exist in the instance metadata, no command output is returned.
Identify the reason why the user data does not or cannot run.
Check whether the user data is in a valid format.
The user data must be in a valid format to allow cloud-init to run the user data. For example, the first line of the user data must start with #!
. For more information, see the Customize initialization configurations for an instance section of the "Instance user data" topic.
Check the execution result of the user data in the /var/log/cloud-init.log file of cloud-init and troubleshoot the issue based on the returned error message.
Example of the execution result of the user data in the log file:
util.py[DEBUG]: Running command ['/var/lib/cloud/instance/scripts/part-001'] with allowed return codes [0] (shell=False, capture=False)
Check the standard output (stdout) and standard error (stderr) generated when the user data was running.
In systemd (a system initialization tool of Linux), user data is run by the cloud-final.service system service. You can run the following command to check the stdout and stderr generated when the user data was running. Then, you can troubleshoot the issue based on the command output.
journalctl -u cloud-final.service
If you cannot identify the reason why the user data does not or cannot run after you perform the preceding operations, we recommend that you copy the user data to your on-premises computer and check whether the user data can run on the computer.
-
What do I do if the system configurations of an instance cannot be initialized and the user data script cannot run after cloud-init is installed on the instance?
Run the following commands to check whether the four cloud-init services are configured to automatically run on system startup:
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 message or disabled
is displayed for a cloud-init service, the service is not configured to automatically run on system startup.
Run the following commands to configure the four cloud-init services to automatically run on system startup:
systemctl enable cloud-init-local.service
systemctl enable cloud-init.service
systemctl enable cloud-config.service
systemctl enable cloud-final.service
-
What do I do if the root partition of the system disk is not automatically extended after I resize the disk when I create an instance?
Cloud-init automatically resizes partitions of Linux instances. Make sure that the growpart tool is installed and that the configurations in the cloud.cfg file are correct.
Run the following command to check whether the growpart tool is installed on the instance operating system:
(Conditionally required) If the growpart tool is not installed on the instance operating system, run one of the following commands based on your operating system to install the growpart tool:
RHEL series:
sudo yum -y install cloud-utils-growpart
Debian series:
sudo apt -y install cloud-guest-utils
Run the following command to check whether the /etc/cloud/cloud.cfg file contains the content shown in the following figure:

(Conditionally required) If the /etc/cloud/cloud.cfg file does not contain the content, add the content to the file.
-
What do I do if the new hostname of an ECS instance on which cloud-init 0.7.6a16 or earlier is installed does not take effect after I change the instance hostname and restart the instance in the ECS console?
Problem description
After you change the hostname of an ECS instance in the ECS console and restart the instance, the new hostname does not take effect. After you run the cloud-init --version
command on the ECS instance, the command output indicates that the version of cloud-init installed on the instance is 0.7.6a16 or earlier.
Cause
When cloud-init uses the update_hostname module to update the hostname, cloud-init runs the hostname
command to obtain the current system hostname, reads the hostname in the cloud-init cache from the /var/lib/cloud/data/previous-hostname
file, and then checks the obtained hostname against the read hostname. If the hostnames are the same, cloud-init performs the hostname update. If the hostnames are different, cloud-init determines that the hostname was manually changed and does not perform the hostname update.
In Red Hat operating systems, line feeds are added to the content that is read from the /var/lib/cloud/data/previous-hostname
file, but line feeds are not added to the hostname
command output. As a result, the read content is different from the command output, and the hostname update fails.
Solutions
You can use one of the following methods to resolve the issue:
Upgrade the cloud-init version. For more information, see the Step 2: Install cloud-init section of this topic.
For CentOS 6 or earlier, upgrade to cloud-init 0.7.6a17.
For CentOS 7, upgrade to cloud-init 19.1.21.
For CentOS 8 or later, upgrade to cloud-init 23.2.2 or later.
Add line feeds.
Modify the cloudinit/distros/rhel.py
file of cloud-init and add line feeds to the hostname
command output. You can run the find / -name rhel.py
command to obtain the path of the cloudinit/distros/rhel.py file. For information about how to add line feeds to the hostname command output, see distros/rhel.py: _read_hostname() missing strip on "hostname". Example on how to add line feeds to 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: