Document navigation

Environment Preparation

Prerequisites

To encapsulate a CentOS Stream 10 template, obtain an ISO image in advance and add it to ZStack Cloud. Notice the following points when you perform this operation:
  • Obtain a CentOS Stream 10 installation image from the official website. Ensure compliance with relevant authorizations and permissions.
  • This tutorial references CentOS-Stream-10-20260901.0-x86_64-boot.iso.

Procedure

  1. Add an installation image.

    On the main menu of ZStack Cloud, choose Resource Center > Resource Pool > Compute Configuration > Image. On the Image page, click Add Image. Then, the Add Image page is displayed.

    On the displayed page, set the following parameters:
    • Name: Enter a name for the image.
    • Description: Enter a description for the image.
    • Image Type: Select System Image.
    • Image Format: Select iso.
    • CPU Architecture: Select x86_64.
    • Platform: Select Linux.
    • OS: Select CentOS Stream 10.
    • VirtIO: Enable VirtIO.
    • Image Storage: Select an image storage added before.
    • Image Path: Specify an image URL or upload a local file. Here, upload the local ISO file.
      Note: Your local browser serves as a transit point to upload the image. Do not refresh or close the browser or stop the management node service. Otherwise, the operation may fail.
    • BIOS Mode: Select UEFI.
    Figure 1. Check the ISO image status and configuration

    Check the ISO image status and configuration
    Note: The x86_64 edition requires x86-64-v3. Select a host and VM CPU mode that meet this requirement.

Encapsulate a Template

Install the Operating System

About this task

To install the operating system, follow these steps:
  1. Create a VM instance.
  2. Install CentOS Stream 10.

Procedure

  1. Create a VM instance.

    Create a VM instance in ZStack Cloud and boot it from the installation image. For details, see the Create a VM Instance section in the User Guide. This example uses 2 vCPUs, 4 GiB memory, and a 40 GiB root volume. Use the same boot mode as the installation image.

  2. Install CentOS Stream 10.

    The boot ISO downloads installation packages over the network. The installation NIC must be able to access the BaseOS and AppStream repositories. This verified example uses the CentOS Stream 10 BaseOS installation source at Tsinghua University TUNA. Verify DNS resolution and repository access, then wait for the installation source to load before selecting a minimal installation.

    1. Select the installation language.

      Select English (United States) and click Continue.

      Figure 2. Select the installation language

      Select the installation language
    2. Configure the installation network.

      On the NETWORK & HOST NAME page, enable the NIC and check its IP address, default route, and DNS. This example uses enp1s0 with an address assigned by DHCP. Verify that DNS resolves the installation source domain and that the source and its BaseOS and AppStream repositories are accessible. A connected NIC alone does not establish repository access. If the DNS provided by DHCP cannot resolve the domain, configure a working DNS server according to your environment requirements and check the installation source again. Click Done.

      Figure 3. Check DNS and network connectivity

      Check DNS and network connectivity
    3. Select the installation disk.

      On the INSTALLATION DESTINATION page, select only the 40 GiB Virtio disk vda of the source VM instance. Select Automatic for automatic partitioning and click Done.

      Figure 4. Select the installation disk and automatic partitioning

      Select the installation disk and automatic partitioning
    4. Configure the network installation source.

      On the INSTALLATION SOURCE page, select On the network, the https:// protocol, and repository URL as the URL type. Enter mirrors.tuna.tsinghua.edu.cn/centos-stream/10-stream/BaseOS/x86_64/os/ in the address field, click Done, and wait for the metadata to load.

      Figure 5. Configure the TUNA HTTPS installation source

      Configure the TUNA HTTPS installation source
    5. Select a minimal installation.

      After the installation source has loaded, select Minimal Install on the SOFTWARE SELECTION page. Leave additional software unselected and click Done.

      Figure 6. Select Minimal Install

      Select Minimal Install
    6. Check the installation summary and start installation.

      Check the time and time zone. This example uses Asia/Shanghai. Configure temporary administrative credentials according to your environment policy; this example sets a root password. On the INSTALLATION SUMMARY page, check the installation source, minimal installation, network, and automatic partitioning. Confirm that all required settings are complete and Begin Installation is available, then click it to start installation.

      Figure 7. Check the installation summary

      Check the installation summary

      After installation completes, detach the installation ISO, set HardDisk first in the boot order, restart the VM Instance, and sign in through the console.

Configure the Template System

About this task

To configure the template system, follow these steps:
  1. Specify the hostname.
  2. Configure the network.
  3. (Optional) Install GuestTools.
  4. (Optional) Install cloud-init.

Procedure

  1. Specify the hostname.
    Run the following command to specify the hostname:
    sudo hostnamectl set-hostname localhost.localdomain
  2. Configure the network.

    This tutorial uses one Ethernet NIC with IPv4 DHCP. Select its connection UUID and clear source-specific static addresses, DNS settings, and NIC bindings. Changes are persistent by default.

    nmcli -f NAME,UUID,TYPE,DEVICE connection show --active
    PROFILE="REPLACE_WITH_CONNECTION_UUID"
    sudo nmcli connection modify "$PROFILE" \
      connection.autoconnect yes connection.interface-name "" \
      ipv4.method auto ipv4.addresses "" ipv4.gateway "" \
      ipv4.routes "" ipv4.dns "" ipv4.dns-search "" \
      ipv4.ignore-auto-dns no ipv4.ignore-auto-routes no \
      ipv4.dhcp-client-id mac \
      802-3-ethernet.mac-address "" \
      802-3-ethernet.cloned-mac-address permanent
    sudo nmcli connection up "$PROFILE"
    nmcli device show
    Note: Run these commands through the console because reactivating networking can interrupt SSH. Confirm that the DHCP-provided DNS works and disable obsolete autoconnect profiles.
  3. (Optional) Install GuestTools.
    sudo dnf install -y tar

    Attach the GuestTools ISO from the source VM instance details page. Replace DEVICE with the actual optical device, such as /dev/sr0, and run the following commands. Resolve installation errors before continuing. If the media remains mounted, confirm that it is unused before unmounting it.

    (
        set -e
        DEVICE="REPLACE_WITH_OPTICAL_DEVICE"
        test -b "$DEVICE"
        sudo mkdir -p /mnt/guesttools
        if mountpoint -q /mnt/guesttools; then
            printf '%s\n' 'Mount point already in use; inspect it before continuing.'
            exit 1
        fi
        sudo mount -o ro "$DEVICE" /mnt/guesttools
        test -f /mnt/guesttools/zs-tools-install.sh
        cd /mnt/guesttools
        sudo bash ./zs-tools-install.sh
        cd /
        sudo umount /mnt/guesttools
    )
    Figure 8. Check the GuestTools installation result and warning

    Check the GuestTools installation result and warning
    Note: The installer may report zs-tools is not verified for os: centos10. Confirm GuestTools support for the target release on your platform. Do not change distribution identifiers to bypass detection.
  4. (Optional) Install cloud-init.

    Install cloud-init if you need User Data or SSH public key initialization. Use root or an account with sudo privileges to install the following packages from the official repositories.

    sudo dnf install -y cloud-init openssh-server &&
      sudo systemctl enable --now sshd

    Retain SELinux and firewall policies. Add the following settings to /etc/cloud/cloud.cfg.d/99-template.cfg so that NetworkManager manages networking and cloud-init handles initialization. Merge changes if the file already exists.

    network:
      config: disabled
    preserve_hostname: false
    ssh_deletekeys: true
    ssh_pwauth: false
    Note: SSH password authentication is disabled. Check the cloud-init default login user and provide an SSH public key for that user when creating VM instances from the image.

    Save the changes and reboot the source VM instance.

    sudo systemctl reboot

Create a System Template

About this task

To create a system template, follow these steps:
  1. Create an image.
  2. Export the image.

Procedure

  1. Create an image.

    Remove temporary files, credentials in installation answer files, temporary accounts, and command history. Keep the login accounts and authentication settings required to use the image. cloud-init cleanup does not remove local account passwords.

    If cloud-init is installed, confirm that it supports these cleanup options and is configured to generate SSH host keys on first boot as described above. Without cloud-init, the following commands only reset the machine ID, preserve the existing network configuration and SSH host keys, and shut down the VM instance. For images without cloud-init, arrange SSH host-key regeneration separately for each VM Instance.

    sudo bash <<'CLEANUP'
    set -e
    if command -v cloud-init >/dev/null 2>&1; then
        cloud-init clean --logs --machine-id --seed
        rm -f /etc/ssh/ssh_host_*_key /etc/ssh/ssh_host_*_key.pub
    else
        truncate -s 0 /etc/machine-id
    fi
    if [ -d /var/lib/dbus ]; then
        rm -f /var/lib/dbus/machine-id
        ln -s /etc/machine-id /var/lib/dbus/machine-id
    fi
    sync
    systemctl poweroff
    CLEANUP
    Note: Run only on the template source VM instance. Resolve cleanup errors before proceeding. Do not restart the source after cleanup; if restarted, repeat cleanup before creating the image.

    Confirm that the VM instance is stopped and detach the installation ISO and GuestTools ISO.

    On the details page of the VM instance created, choose Actions > Image and ISO > Create Image. Then, the Create Image page is displayed.

    On the displayed page, set the following parameters:
    • Name: Enter a name for the image.
    • Description: Optional. Enter a description for the image.
    • Image Type: Select System Image here.
    • Image Storage: Select an image storage created before.
    Figure 9. Create a System Image

    System Image type, name, description, and image storage fields
  2. Export the image.
    You can use the image exported to create VM instances on other cloud platforms directly. The method to export images varies according to image storage types.
    • ImageStore image storage.

      On the Image page, choose Actions > Export Image. This button helps export the image.

      After generating the image, you can copy the URL of the image exported on the Overview page to download the image. Or, you can copy the URL of the exported image on the Exported page. You can also click Download on the page to download the image directly.

    • Ceph image storage. If you use a Ceph image storage, you can export the image on the UI or from the image storage.
      • Export on the UI:

        On the Image page, choose Actions > Export Image. This button helps export the image.

        After generating the image, you can copy the URL of the image exported on the Overview page to download the image. Or, you can copy the URL of the exported image on the Exported page. You can also click Download on the page to download the image directly.

      • Export from the image storage:
        1. On the Overview page of the created image, copy Installation Path.
        2. Login to the terminal of the Ceph image storage, run rbd export to export the image. For example:
          If you obtain the installation path ceph://bak-t-cac5eee23a204c1a914d1743f1584644/7232237c0059409babcd1c7a69452b98, you can run the following commands to export the image:
          [root@ceph-node1 ~]# rbd export bak-t-cac5eee23a204c1a914d1743f1584644/7232237c0059409babcd1c7a69452b98 /root/export-test.qcow2
          [root@ceph-node1 ~]# # bak-t indicates the installation path of the image
          [root@ceph-node1 ~]# # /root/export-test.qcow2 indicates the target path and the file name of the exported image
          Note: The command rbd export does not include such a prefix as ceph://.

What to do next

The CentOS Stream 10 system template is now created. You can use this image to create VM instances in batches.
CentOS Stream 10 Template Tutorial | 5.5.38 | ZStack Cloud · ZCF | ZStack Resource Center