mount_point/qcloud_action/os.conf
for configuration. If other configuration data or UserData needs to be used, the user can directly read files under mount_point/
.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"
Parameter Name | Description |
hostname | CVM name |
password | Encrypted password |
eth0_ip_addr | LAN IP of eth0 |
eth0_mac_addr | MAC address of eth0 |
eth0_netmask | Subnet mask of eth0 |
eth0_gateway | Gateway of eth0 |
dns_nameserver | DNS resolution server |
/dev/cdrom
and read qcloud_action/os.conf
file under the mount point to obtain the configuration information.chpasswd -e
.
Note that the encrypted password may contain special characters. We recommend you place it in a file and then set the password with chpasswd -e < passwd_file
.os_config
script based on the following script sample.
You can modify the script as needed.#!/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_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
os_config
script in the /etc/init.d/
directory and execute the following command.chmod +x /etc/init.d/os_configchkconfig --add os_config
os_config
has been added to the startup service.chkconfig --list
Was this page helpful?