Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of selecting Customized Linux when importing a custom image

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

How to select Customized Linux when importing custom images? This problem may be often seen in our daily study or work. I hope you can gain a lot from this question. The following is the reference content that the editor brings to you, let's take a look at it!

Custom Linux Custom Image

When your image operating system is not in the existing platform supported by Aliyun, and cloud-init cannot be installed, you can select Customized Linux (customized image) when importing custom images. Aliyun regards the customized Linux image as an unrecognized operating system type, and lacks the standard configuration information necessary to start the ECS instance for the first time. You need to add a resolution script to the customized image before importing the image, so as to automatically configure the instance when starting for the first time.

Restriction condition

The first partition of the Customized Linux image must be writable.

The first partition type of a Customized Linux image supports FAT32, EXT2, EXT3, EXT4, or UFS.

The virtual file size of the Customized Linux image must be greater than 5 GiB.

Customized Linux images have the following security requirements:

There can be no high-risk vulnerabilities that can be exploited remotely.

When using the management terminal of the console to log in to the instance, if there is an initial default password, it must be modified when logging in for the first time. No operation is allowed to enter the instance before changing the password.

The default SSH key pair is not supported. The initial SSH key pair must be randomly generated by Aliyun.

Configuration method

Create a new directory aliyun_custom_image under the root of the first partition of the mirror.

When the instance created using this Customized Linux image is started for the first time, Aliyun will write the configuration information related to the instance in the os.conf file of the aliyun_custom_image directory. If no os.conf file exists, the system creates it automatically.

Create a parsing script in the image to parse the system configuration of the os.conf file. See parsing script considerations and parsing script examples to write a script.

Os.conf file exampl

Examples of classic network types

Hostname=iZ23r29djmjZpassword=cXdlcjEyMzQKeth0_ip_addr=10.171.254.123eth0_mac_addr=00:8c:fa:5e:14:23eth0_netmask=255.255.255.0eth0_gateway=10.171.254.1eth0_route= "10.0.0.0amp 8 10.171.254.1 172.16.0.0Universe 12 10.171.254.1 "eth2_ip_addr=42.120.74.105eth2_mac_addr=00:8c:fa:5e:14:24eth2_netmask=255.255.255.0eth2_gateway=42.120.74.1eth2_route=" 0.0.0.0Universe 0 42.120.74.1 "dns_nameserver=" 7.7.7.7 8.8.8.8 "

The parameter description is shown in the following table:

Proprietary network VPC type instance

Hostname=iZ23r29djmjZpassword=cXdlcjEyMzQKeth0_ip_addr=10.171.254.123eth0_mac_addr=00:8c:fa:5e:14:23eth0_netmask=255.255.255.0eth0_gateway=10.171.254.1eth0_route= "0.0.0.0amp 0 10.171.254.1" dns_nameserver= "7.7.7.7 8.8.8.8"

The parameter description is shown in the following table:

Parsing script considerations

When the instance is started for the first time, Ali Cloud automatically writes the relevant information about the configuration item to the os.conf file in the aliyun_custom_image directory under the root directory of the first partition. To configure a Customized Linux image, you must create a predefined resolution script in the image to read the instance configuration information from the os.conf file and complete the instance configuration. The following are the conditions that need to be met for parsing scripts.

Boot: the parsing script needs to be set to boot itself, for example, to store the parsing script in the / etc/init.d/ directory.

Configuration item value rules: as described in the configuration item in the example of os.conf file, the number of configuration items and the value rules of some configuration items are different between VPC and classic network instances.

Configuration file read path: the device name assigned to the first partition is not the same by default when the Customized Linux image creates an Icano-optimized instance or a non-IZP O-optimized instance. So it's best to use uuid or label to identify the device of the first partition in the parsing script. The user password is a string encoded by Base64, which needs to be dealt with when setting the password.

Determine VPC or Classic Network: when parsing scripts determine this network type, you can check to see if there are eth2_route or other eth2-related configuration items. After judging the network type of the current instance, it is analyzed and processed pertinently.

The VPC instance configures the default public network route in the eth0_route parameter of the os.conf file.

The example of classic network type configures the default public network route in the eth2_route parameter of the os.conf file, and the private network route is configured in eth0_route.

Configuration optimization: the configuration in the os.conf file can be executed once throughout the life cycle of the instance. It is recommended to delete the os.conf file after successful execution of the parsing script. At the same time, if the parsing script does not read the os.conf file configuration, it does not execute the configuration in the file.

Custom image processing: this boot script will also be included in the image when you create a custom image based on the instance created by the Customized Linux image. Ali Cloud writes the os.conf configuration when the instance is started for the first time, and the parsing script can execute the relevant configuration when it detects the configuration.

What to do when modifying relevant configurations: when the configuration information of an instance is changed through Aliyun's console or API, Aliyun writes the relevant information to the os.conf file, and the parsing script will be executed again to issue these changes.

Parse script example

The following is an example of a parsing script taking the CentOS operating system as an example, for reference only. You need to adjust the content of the script according to the actual operating system type. Before using the script, be sure to debug the script in the image and make sure the debugging passes.

#! / bin/bash### BEGIN INIT INFO# Provides: os-conf# Required-Start: $local_fs $network $named $remote_fs# Required-Stop:# Should-Stop:# Default-Start: 2 3 4 "Default-Stop: 0 1" Short-Description: The initial os-conf job Config the system.### END INIT INFOfirst_partition_dir='/boot/'os_conf_dir=$ {first_partition_dir} / aliyun_custom_imageos_conf_file=$ {os_conf_dir} / os.confload_os_conf () {if [[- f $os_conf_file]] Then. $os_conf_filereturn 0elsereturn 1fi} cleanup () {# ensure $os_conf_file is deleted, to avoid repeating config systemrm $os_conf_file > & / dev/null# ensure $os_conf_dir is exitstmkdir-p $os_conf_dir} config_password () {if [[- n $password]]; thenpassword=$ (echo $password | base64-d) if [[$? = = 0 &-n $password]]; thenecho "root:$password" | chpasswdfifi} config_hostname () {if [- n $hostname]] Thensed-I "s / ^ hostname =. * / HOSTNAME=$hostname/" / etc/sysconfig/networkhostname $hostnamefi} 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} is_classic_network () {# vpc: eth0# classic: eth0 eth2grep-Q 'eth2' $os_conf_file} config_network () {/ etc/init.d/network stopconfig_interface eth0 ${eth0_ip_addr} ${eth0_netmask} ${eth0_mac_addr} config_route eth0 ${eth0_route} if is_classic_network Thenconfig_interface eth2 ${eth2_ip_addr} ${eth2_netmask} ${eth2_mac_addr} config_route eth2 ${eth2_route} fi/etc/init.d/network start} config_interface () {local interface=$1local ip=$2local netmask=$3local mac=$4inteface_cfg= "/ etc/sysconfig/network-scripts/ifcfg-$ {interface}" cat $inteface_cfgDEVICE=$interfaceIPADDR=$ipNETMASK=$netmaskHWADDR=$macONBOOT=yesBOOTPROTO=staticEOF} config_default_gateway () {local gateway=$1sed-I "s / ^ Gateway =. * / GATEWAY=$gateway/" / etc/sysconfig/network} config_route () {local interface=$1local route=$2route_conf=/etc/sysconfig/network-scripts/route-$ {interface} > $route_confecho $route | sed's / /\ while read line; dodst=$'|\ while read line; dodst=$ (echo $line | awk'{print $1}') gw=$ (echo $line | awk'{print $2}') if! Grep-Q "$dst" $route_conf 2 > / dev/null; thenecho "$dst via $gw dev $interface" > $route_conffiif [["$dst" = "0.0.0.0Mab 0"]]; thenconfig_default_gateway $gwfidone} # sysvinit service portal # start () {if load_os_conf Thenconfig_passwordconfig_networkconfig_hostnameconfig_dnscleanupreturn 0elseecho "not load $os_conf_file" return 0fi} RETVAL=0case "$1" in start) start RETVAL=$?; *) echo "Usage: $0 {start}" RETVAL=3;; esacexit $RETVAL Thank you for reading! After reading the above, do you have a general idea of how to select Customized Linux when importing custom images? I hope the content of the article will be helpful to all of you. If you want to know more about the relevant articles, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report