Scenario
When a user's Linux image cannot install cloud-init for some reason, the forced image import feature can be used to complete the image import. Since the forcibly imported image does not have cloud-init installed, Tencent Cloud cannot initialize the configuration for the user's CVM. Therefore, when using a forcibly imported image, users need to set up scripts according to the configuration files provided by Tencent Cloud to configure the CVM. This document guides users on how to configure a CVM under the premise of forcibly importing an image.
Tencent Cloud provides a CD-ROM device containing configuration information for users to configure themselves. Users need to mount the CD-ROM and read the information in
mount_point/qcloud_action/os.conf for configuration. If users need to use other configuration data or UserData, they can directly read the files under mount_point/.os.conf Configuration File
The content of os.conf is as follows.
hostname=VM_10_20_xxxxpassword=GRSgae1fw9frsG.rfrFeth0_ip_addr=10.104.62.201eth0_mac_addr=52:54:00:E1:96:EBeth0_netmask=255.255.192.0eth0_gateway=10.104.0.1dns_nameserver="10.138.224.65 10.182.20.26 10.182.24.12"
Note
The parameter names above are for reference only, and the parameter values are for illustration purposes.
The description of each parameter in the os.conf configuration file is as follows:
Parameter name | Description |
hostname | Host name |
password | Encrypted password |
eth0_ip_addr | Local area network IP of eth0 network interface |
eth0_mac_addr | MAC address of the eth0 network interface |
eth0_netmask | Subnet mask of eth0 network interface |
eth0_gateway | Gateway for eth0 network interface |
dns_nameserver | DNS Resolution Server |
Limits
The image still needs to meet the requirements for Linux image import in Importing Images (excluding cloud-init).
The system partition for importing the image is not full.
The imported image contains no vulnerability that can be exploited remotely.
We recommend you change the password immediately after the instance is created successfully with the forcibly imported image.
Supports and Limits
Note the following when configuring script parsing:
The script is executed automatically at startup. Please implement this requirement based on your operating system.
The script must mount
/dev/cdrom and read the qcloud_action/os.conf file under the mount point to obtain configuration information.The password placed in the CD-ROM by Tencent Cloud is encrypted. Users can set it using
chpasswd -e.
Since the encrypted password may contain special characters, it is recommended to place it in a file first and then set it using chpasswd -e < passwd_file.When creating an image from an instance made using a forcibly imported image, ensure that the script is still executed to guarantee the correct configuration of the instance. Alternatively, you can install cloud-init within the instance.
Instructions
Note
Tencent Cloud provides a sample script based on CentOS. Users can create a configuration script for their own image according to the sample script. During the creation process, please pay attention to the following points:
Place the script correctly in the system before importing the image.
This script may not be suitable for all operating systems. Users need to make appropriate modifications according to their own operating system to meet the requirements.
1. Create the
os_config script based on the following example.
Users can modify the os_config script according to their actual situation.#!/bin/bash### BEGIN INIT INFO# Provides: os-config# Required-Start: $local_fs $network $named $remote_fs# Required-Stop:# Should-Stop:# Default-Start: 2 3 4 5# Default-Stop: 0 1 6# Short-Description: config of os-init job# Description: run the config phase without cloud-init### END INIT INFO###################user settings#####################cdrom_path=blkid-L config-2load_os_config() {mount_path=$(mktemp -d /mnt/tmp.XXXX)mount /dev/cdrom $mount_pathif [[ -f $mount_path/qcloud_action/os.conf ]]; then. $mount_path/qcloud_action/os.confif [[ -n $password ]]; thenpasswd_file=$(mktemp /mnt/pass.XXXX)passwd_line=$(grep password $mount_path/qcloud_action/os.conf)echo root:${passwd_line#*=} > $passwd_filefireturn 0elsereturn 1fi}cleanup() {umount /dev/cdromif [[ -f $passwd_file ]]; thenecho $passwd_filerm -f $passwd_filefiif [[ -d $mount_path ]]; thenecho $mount_pathrm -rf $mount_pathfi}config_password() {if [[ -f $passwd_file ]]; thenchpasswd -e < $passwd_filefi}config_hostname(){if [[ -n $hostname ]]; thensed -i "/^HOSTNAME=.*/d" /etc/sysconfig/networkecho "HOSTNAME=$hostname" >> /etc/sysconfig/networkfi}config_dns() {if [[ -n $dns_nameserver ]]; thendns_conf=/etc/resolv.confsed -i '/^nameserver.*/d' $dns_conffor i in $dns_nameserver; doecho "nameserver $i" >> $dns_confdonefi}config_network() {/etc/init.d/network stopcat << EOF > /etc/sysconfig/network-scripts/ifcfg-eth0DEVICE=eth0IPADDR=$eth0_ip_addrNETMASK=$eth0_netmaskHWADDR=$eth0_mac_addrONBOOT=yesGATEWAY=$eth0_gatewayBOOTPROTO=staticEOFif [[ -n $hostname ]]; thensed -i "/^${eth0_ip_addr}.*/d" /etc/hostsecho "${eth0_ip_addr} $hostname" >> /etc/hostsfi/etc/init.d/network start}config_gateway() {sed -i "s/^GATEWAY=.*/GATEWAY=$eth0_gateway" /etc/sysconfig/network}###################init#####################start() {if load_os_config ; thenconfig_passwordconfig_hostnameconfig_dnsconfig_networkcleanupexit 0elseecho "mount ${cdrom_path} failed"exit 1fi}RETVAL=0case "$1" instart)startRETVAL=$?;;*)echo "Usage: $0 {start}"RETVAL=3;;esacexit $RETVAL
2. Place the
os_config script in the /etc/init.d/ directory and run the following command.chmod +x /etc/init.d/os_configchkconfig --add os_config
3. Run the following command to check whether
os_config has been added to the startup services.chkconfig --list
Note
Users need to ensure the correct execution of the script. If issues such as inability to connect to the instance via SSH or lack of network connection are encountered after importing the image, try connecting to the instance through the console and re-executing the script to troubleshoot the problem. If the issue persists, please contact customer support.