Document navigation

Environment Preparation

Prerequisites

To encapsulate a Rocky Linux 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 Rocky Linux 10 installation image from the official website. Ensure compliance with relevant authorizations and permissions.
  • This tutorial references Rocky-10.2-x86_64-minimal.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 Rocky Linux 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.
    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 Rocky Linux 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 Rocky Linux 10.
    1. Select the installation language.

      In the Rocky Linux Minimal 10.2 installer, select English (United States) and click Continue.

      Figure 1. Select the Installation Language

      Select the Installation Language
    2. Partition the disk.

      On the Installation Destination page, select the 40 GiB root volume vda, select Automatic, and click Done. Check the installation target against its actual device name and size.

      Figure 2. Select the Installation Disk and Automatic Partitioning

      Select the Installation Disk and Automatic Partitioning
    3. Configure the network.

      On the Network & Host Name page, enable the NIC, confirm that it is Connected, and check its IP address, default route, and DNS. This example uses enp1s0; use your actual device name. Click Done.

      Figure 3. Enable the Installation NIC

      Enable the Installation NIC
    4. Installation summary.

      Select Minimal Install, check the time and time zone, and configure an administrator account. On the Root Account page, use the Enable or Disable radio option for the root account. Set a password when enabling root; when disabling root, ensure that an administrator with privilege escalation is configured. Confirm the installation target and all settings, then click Begin Installation.

      Figure 4. Confirm the Installation Settings

      Confirm the Installation Settings
    5. Complete the installation.

      Wait until the installer displays Complete!.

      Figure 5. Installation Complete

      Installation Complete

      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 6. GuestTools Installer Warning

    GuestTools Installer Warning
    Note: The installer may report zs-tools is not verified for os: rocky10. Confirm GuestTools support for the target release on your platform. Do not change distribution identifiers to bypass detection.

    If QGA is missing, install it from the official repositories and confirm that its channel exists before starting it:

    sudo dnf install -y qemu-guest-agent &&
      test -e /dev/virtio-ports/org.qemu.guest_agent.0 &&
      sudo systemctl start qemu-guest-agent
  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 7. 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 Rocky Linux 10 system template is now created. You can use this image to create VM instances in batches.
Rocky Linux 10 Template Tutorial | 5.5.38 | ZStack Cloud · ZCF | ZStack Resource Center