Overview
When the user's Linux image cannot install cloudinit for some reason, you can use the Forced Import Image feature to import the image. If the user uses the forced import image for import, Converge Cloud will not be able to initialize the configuration of the user's CVM. You need to set a script to configure the CVM according to the configuration file provided by Converge Cloud. This document guides users on how to configure the CVM under the premise of forced import image.
Limitation Factor
- The image still needs to meet the imported image limits in Import Image for Linux images (except cloudinit).
- The system partition where the image is imported is not full.
- The imported image must not have vulnerabilities that can be exploited remotely.
- It is recommended that users change the password immediately after the instance is created successfully by forced import image.
Directions
The forced import image does not use cloudinit and therefore cannot be automatically configured. Converge Cloud provides a cdrom device containing configuration information for users to configure themselves. Users need to mount cdrom and read mount_point/qcloud_action/os.conf information to configure. If the user needs to use other configuration data or UserData, they can directly read the files under mount_point/.
os.conf Configuration File Content
The basic contents of os.conf are as follows:
hostname=VM_10_20_xxxx
password=GRSgae1fw9frsG.rfrF
eth0_ip_addr=10.104.62.201
eth0_mac_addr=52:54:00:E1:96:EB
eth0_netmask=255.255.192.0
eth0_gateway=10.104.0.1
dns_nameserver="10.138.224.65 10.182.20.26 10.182.24.12"
The parameter names in the above information are for reference only, and the parameter values are only examples.
The meaning of each parameter in os.conf is as follows:
| Parameter Name | Parameter Meaning |
|---|---|
| hostname | Host name |
| password | Encrypted password |
| eth0_ip_addr | LAN IP of the eth0 network interface |
| eth0_mac_addr | MAC address of the eth0 network interface |
| eth0_netmask | Subnet mask of the eth0 network interface |
| eth0_gateway | Gateway of the eth0 network interface |
| dns_nameserver | DNS resolution server |
Configure Script Resolution
Notes
- The script is automatically executed at boot. Implement this requirement according to the type of operating system.
- The script must mount
/dev/cdrom, and reados_action/os.conffile under the mount point to obtain configuration information. - The password placed in the cdrom by Converge Cloud is an encrypted password. Users can use
chpasswd -eto set it.
The encrypted password may contain special characters. It is recommended to put it in a file first and then usechpasswd -e < passwd_fileto set it. - When recreating an image using an instance created by forced import image, you need to ensure that the script is still executed to ensure that the instance is correctly configured. You can also install cloudinit in this instance.
Example
Converge Cloud provides a sample script based on CentOS. Users can create configuration scripts for their own images based on the sample script. During the creation process, note the following points:
- This script needs to be correctly placed in the system before importing the image.
- This script is not suitable for all operating systems. Users need to modify it according to their own operating system to meet the semantics.
Create
os_configscript according to the following script example.
Users can modifyos_configscript according to actual conditions.#!/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-2` load_os_config() { mount_path=$(mktemp -d /mnt/tmp.XXXX) mount /dev/cdrom $mount_path if [[ -f $mount_path/qcloud_action/os.conf ]]; then . $mount_path/qcloud_action/os.conf if [[ -n $password ]]; then passwd_file=$(mktemp /mnt/pass.XXXX) passwd_line=$(grep password $mount_path/qcloud_action/os.conf) echo root:${passwd_line#*=} > $passwd_file fi return 0 else return 1 fi } cleanup() { umount /dev/cdrom if [[ -f $passwd_file ]]; then echo $passwd_file rm -f $passwd_file fi if [[ -d $mount_path ]]; then echo $mount_path rm -rf $mount_path fi } config_password() { if [[ -f $passwd_file ]]; then chpasswd -e < $passwd_file fi } config_hostname(){ if [[ -n $hostname ]]; then sed -i "/^HOSTNAME=.*/d" /etc/sysconfig/network echo "HOSTNAME=$hostname" >> /etc/sysconfig/network fi } config_dns() { if [[ -n $dns_nameserver ]]; then dns_conf=/etc/resolv.conf sed -i '/^nameserver.*/d' $dns_conf for i in $dns_nameserver; do echo "nameserver $i" >> $dns_conf done fi } config_network() { /etc/init.d/network stop cat << EOF > /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 IPADDR=$eth0_ip_addr NETMASK=$eth0_netmask HWADDR=$eth0_mac_addr ONBOOT=yes GATEWAY=$eth0_gateway BOOTPROTO=static EOF if [[ -n $hostname ]]; then sed -i "/^${eth0_ip_addr}.*/d" /etc/hosts echo "${eth0_ip_addr} $hostname" >> /etc/hosts fi /etc/init.d/network start } config_gateway() { sed -i "s/^GATEWAY=.*/GATEWAY=$eth0_gateway" /etc/sysconfig/network } ###################init##################### start() { if load_os_config ; then config_password config_hostname config_dns config_network cleanup exit 0 else echo "mount ${cdrom_path} failed" exit 1 fi } RETVAL=0 case "$1" in start) start RETVAL=$? ;; *) echo "Usage: $0 {start}" RETVAL=3 ;; esac exit $RETVALPlace
os_configscript in/etc/init.d/directory and execute the following command.chmod +x /etc/init.d/os_config chkconfig --add os_configExecute the following command to check whether
os_confighas been added to the startup services.chkconfig --list
Note: Users need to ensure that the script is executed correctly. If the instance cannot be connected through SSH or the network connection is unavailable after the image is imported, connect to the instance through the console and run the script again to troubleshoot. If the problem still cannot be solved, contact customer service.