Document navigation

Environment Preparation

Prerequisites

To encapsulate a Rocky Linux 9 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 9 installation image from the official website. Ensure compliance with relevant authorizations and permissions.
  • This tutorial references Rocky-9.8-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 9.
    • 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 Legacy.

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 9.

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 9.
    1. Select the installation language.

      In the installer, select English (United States) as the installation language, then click Continue to open the installation summary.

      Figure 1. Select the Installation Language

      Installation language selection for Rocky Linux minimal 9.8
    2. Partition the disk.

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

      Figure 2. Select the Installation Disk and Automatic Partitioning

      Select the Installation Disk and Automatic Partitioning
    3. Select the installation type.

      On the Software Selection page, select Minimal Install, leave additional software unselected, then click Done.

      Figure 3. Select Minimal Install

      Select Minimal Install
    4. Configure the network.

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

      Figure 4. Enable the Installation NIC

      Enable the Installation NIC
    5. Configure the network.

      Click Configure. On the IPv4 Settings tab, set Method to Automatic (DHCP), then click Save. Return to the network page and click Done.

      Figure 5. Configure DHCP in the Installer

      Configure DHCP in the Installer
    6. Installation summary.

      Check the time and time zone, set the root password, and create an administrator if needed. Confirm the installation target and all settings, then click Begin Installation to start installation.

      Figure 6. Review the Installation Summary

      Minimal Install, automatic partitioning, connected ens3, and configured root password

      Set the time and time zone for your environment.

      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 7. GuestTools Installation Complete

    GuestTools Installation Complete

    If prompted to link python3 as python, check the current Python environment before accepting the change.

  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 8. Enter the System Image Name

    System image name field
  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 9 system template is now created. You can use this image to create VM instances in batches.
Rocky Linux 9 Template Tutorial | 5.5.38 | ZStack Cloud · ZCF | ZStack Resource Center