Images

Introduces the creation of a universal server image based on standard ISO images for all platforms.

The OneCloud image market provides some pre-made server images, if the images in the image market do not meet the needs or users have the need to customize the images, you can use this section to create images.

Images process

  1. Prepare the standard ISO image in advance, support users to import or directly upload the ISO image from the image market - ISO interface.
  2. Create server in the server list, select “Boot from ISO” and choose the corresponding ISO image, create it successfully, and follow the interface prompts to install the operating system via VNC terminal.
  1. Optimize the configuration according to the OS type of the image.
  2. (Optional) multi-platform common image configuration, such as the production of images need to be used in the public cloud platform, in addition to the above optimization configuration, you also need to Linux installation configuration cloud-init, Windows installation configuration cloudbase-init.
  3. After the image optimization is completed, you need to shut down the server.
  4. Click the “More” button on the right side of the shutdown server and select the drop-down menu “Save Image” menu item to save the server as a system image. After the image is saved, users can create a new server in the server list, select “Custom Image” and choose the image saved in the previous step to create a server using the created image and verify whether the image is created successfully.

CentOS image optimization

Take CentOS 7 minimal image as an example to introduce the image optimization method.

  1. After CentOS 7 Minimal is installed, the server cannot be networked by default, you need to modify the file /etc/sysconfig/network-scripts/ifcfg-eth0 and change “ONBOOT=no” to “ONBOOT=yes”.

    # Please modify the corresponding configuration file according to the actual NIC name
    $ vi /etc/sysconfig/network-scripts/ifcfg-eth0 # Please modify the corresponding configuration file according to the actual NIC name
    # Modify the contents of the configuration file
    ONBOOT=yes
    
  2. Disable selinux, modify /etc/selinux/config file, change “SELINUX=enforcing” to “SELINUX=disabled”. After the modification is done, reboot the system to take effect.

    $ vi /etc/selinux/config
    # Modify the contents of the configuration file, and save it after the changes are made.
    SELINUX=disabled
    # Restart to make the configuration take effect
    $ reboot
    
  3. Add the necessary kernel module to the boot initram.img.

    $ vi /etc/dracut.conf
    # Modify the configuration file by removing the # comment in front of add_drivers+ and adding the following in quotes, and save the changes when finished.
    add_drivers+=" hpsa mptsas mpt2sas mpt3sas megaraid_sas mptspi virtio virtio_ring virtio_pci virtio_scsi virtio_blk vmw_pvscsi "
    # Make the configuration take effect
    # dracut -f
    
  4. Disable NIC persistence and ensure the NIC name in CentOS 7 is of the form “eth0, eth1”. Modify the /etc/default/grub file and add “net.ifnames=0 biosdevname=0” to GRUB_CMDLINE_LINUX.

    $ vi /etc/default/grub
    # Modify the configuration file, and save it after the changes are done.
    GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet net.ifnames=0 biosdevname=0"
    # Make the configuration take effect
    $ grub2-mkconfig -o /boot/grub2/grub.cfg
    
  5. Install common software as required.

    # For example only, please install common software according to your needs.
    $ yum install net-tools git wget vim pcre-tools ntp epel-release -y
    
  6. disable firewalld and NetworkManager services.

    $ systemctl disable firewalld NetworkManager
    
  7. Enable time network synchronization and support using ntp or chrony to keep time synchronized.

    # Install ntp or chrony software
    $ yum install ntp/chrony -y
    # Enable ntp or chronyd service
    $ systemctl enable ntpd/chronyd
    
  8. Modify the time zone to CST.

    $ timedatectl set-timezone Asia/Shanghai
    # View the current time zone
    $ timedatectl status
    
  9. ssh service optimization, modify /etc/ssh/sshd_config file, change PermitRootLogin attribute to yes Change UseDNS attribute to no.

    $ vi /etc/ssh/sshd_config
    
    # Find the PermitRootLogin attribute and UseDNS attribute respectively
    PermitRootLogin yes
    UseDNS no
    

Ubuntu/Debian image optimization

Ubuntu and Debian images are optimized using ubuntu-16.04.6-server-amd64.iso as an example.

  1. ssh service optimization, modify /etc/ssh/sshd_config file, change PermitRootLogin attribute to yes Change UseDNS attribute to no, if you don’t have the above attribute, please add the attribute.

    $ sudo vi /etc/ssh/sshd_config
    # Find the PermitRootLogin attribute and UseDNS attribute respectively
    PermitRootLogin yes
    UseDNS no
    UseDNS no
    
  2. Create a self-starting script named ssh-initkey in the /etc/init.d/ directory.

    $ sudo touch /etc/init.d/ssh-initkey
    $ sudo vi /etc/init.d/ssh-initkey
    #! /bin/sh
    ### BEGIN INIT INFO
    # Provides:          ssh-initkey
    # Required-Start:
    # Required-Stop:
    # X-Start-Before:    ssh
    # Default-Start:     2 3 4 5
    # Default-Stop:
    # Short-Description: Init ssh host keys
    ### END INIT INFO
    
    PATH=/sbin:/usr/sbin:/bin:/usr/bin
    . /lib/init/vars.sh
    . /lib/lsb/init-functions
    do_start() {
        ls /etc/ssh/ssh_host_* > /dev/null 2>&1
        if [ $? -ne 0 ]; then
            dpkg-reconfigure openssh-server
        fi
    }
    case "$1" in
        start)
        do_start
            ;;
        restart|reload|force-reload)
            echo "Error: argument '$1' not supported" >&2
            exit 3
            ;;
        stop)
            ;;
        *)
            echo "Usage: $0 start|stop" >&2
            exit 3
            ;;
    esac
    
  3. After the ssh-initkey script is configured, you also need to add executable permissions and add the script to the system boot script directory.

    $ sudo chmod +x /etc/init.d/ssh-initkey
    
    $ sudo /usr/sbin/update-rc.d ssh-initkey defaults
    
    $ sudo /usr/sbin/update-rc.d ssh-initkey enable
    
  4. (Ubuntu 16.04 or above) Disable NIC persistence and ensure that the NIC name is of the form “eth0, eth1”. Modify the /etc/default/grub file and add the parameter “net.ifnames=0 biosdevname=0” to GRUB_CMDLINE_LINUX.

    $ sudo vi /etc/default/grub
    # Configure GRUB_CMDLINE_LINUX parameters
    GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0"
    
    # Make the configuration take effect
    $ sudo /usr/sbin/update-grub
    
  5. (If Ubuntu does not turn off automatic updates) To turn off automatic updates, modify the /etc/apt/apt.conf.d/10periodic file and set the “Update-Package-Lists” parameter to 0.

  6. (If Ubuntu does not turn off automatic updates) To turn off automatic updates, you need to modify the /etc/apt/apt.conf.d/10periodic file and set the “Update-Package-Lists” parameter in the file to 0.

    $ sudo vi /etc/apt/apt.conf.d/10periodic
    # Configuration changes
    APT:Periodic:Update-Package-Lists "1";
    
  7. At this point, the server optimization is complete.

Windows image optimization

Install Virtio driver

OS version Corresponding name in Virtio driver
Windows XP xp
Windows 7 w7
Windows 8 w8
Windows 8.1 w8.1
Windows 10 w10
Windows Server 2003 2K3
Windows Server 2008 2K8
Windows Server 2008 R2 2k8R2
Windows Server 2012 2k12
Windows Server 2012 R2 2k12R2
Windows Server 2016 2k16
  1. Import the Virtio driver from the ISO page of the image market and mount it on the server.

  2. Open the mounted driver folder in the server, search for “2k16” in the search box on the driver folder page according to the OS version of the server (e.g. Windows server 2016 in this case), and copy all the folders containing 2k16 to other folders in the server (e.g. Documents folder).

  3. Open the “2k16>amd64” folder in the Documents folder, which contains all the driver files for Windows Server 2016. Type cmd in the address box of the folder or press the “shift” key and right mouse button at the same time to open a command window and open the Command Prompt dialog box.

  4. Use the following command to install all the drivers.

    pnputil -i -a *.inf
    

Set the system time

The time on the Windows server will be 8 hours different from Beijing time by default, you need to configure the system to display it as Beijing time.

  1. Type regedit in the run bar to open the registry.
  2. Under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation, right mouse button to create a new DWORD (32-bit), name it RealTimeIsUniversal, and set the value to 1.

Disable Quick Start

(Optional) If the server of Windows 10 OS needs to disable fast startup. Please see Disable method.

System activation

Please activate the Windows system through the proper channel.

sysprep packaging

Run sysprep to eliminate personalized information.

  1. Open the %WINDIR%/system32/sysprep directory and create the unattend.xml file in the directory with the following contents.
<?xml version="1.0" encoding="utf-8"? >
<unattend xmlns="urn:schemas-microsoft-com:unattend">
    <settings pass="generalize">
        <component name="Microsoft-Windows-Security-SPP" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral " versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema- instance">
            <SkipRearm>0</SkipRearm
        </component
        <component name="Microsoft-Windows-PnpSysprep" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema- instance">
            <PersistAllDeviceInstalls>true</PersistAllDeviceInstalls
            <DoNotCleanUpNonPresentDevices>true</DoNotCleanUpNonPresentDevices>
        </component
    </settings
    <settings pass="oobeSystem">
        <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State">
            <UserAccounts>
                <AdministratorPassword
                    <Value>123@yunion</Value>
                    <PlainText>true</PlainText
                </AdministratorPassword
            </UserAccounts>
            <Display
                <ColorDepth>32</ColorDepth
                <HorizontalResolution>1024</HorizontalResolution
                <RefreshRate>60</RefreshRate>
                <VerticalResolution>768</VerticalResolution
            </Display
            <OOBE
                <HideEULAPage>true</HideEULAPage>
                 <NetworkLocation>Work</NetworkLocation>
                <ProtectYourPC>1</ProtectYourPC>
                <SkipMachineOOBE>true</SkipMachineOOBE>
                <SkipUserOOBE>true</SkipUserOOBE
            </OOBE
        </component
    </settings>
</unattend>
  1. Type cmd in the address display box of the directory or press the “shift” key and right mouse button at the same time to open the command window and open the command prompt dialog box. Enter the following command to execute the sysprep package and shut down the server.
> sysprep /generalize /oobe /shutdown /unattend:unattend.xml
  1. This completes the server optimization.

Linux installation and configuration of Cloud-init

Cloud-init is used to configure the system initialization for Linux OS servers. Please see the cloud-init official website for details.

Installing cloud-init

Execute the following command to install cloud-init in the Linux operating system.

$ apt-get/yum install cloud-init

For offline installation method, please see Tencent Cloud Documentation Center - Install cloud-init on Linux system or [Alibaba Cloud Documentation Center - Install cloud-init](https://help. aliyun.com/document_detail/57803.html?spm=5176.10695662.1996646101.searchclickresult.9b2c5db8X8v4Tq&aly_as=gOLD2vtr), etc.

Configure cloud-init

Modify the /etc/cloud/cloud.cfg file to set disabled_root to 0 and ssh_pwauth to 1.

$ vi /etc/cloud/cloud.cfg
# Modify the configuration file, and save it after the changes are done.
disable_root: 0
ssh_pwauth: 1

Windows installation and configuration of Cloudbase-init

Please see Tencent Cloud Documentation Center - Installing Cloudbase-Init on Windows OS.