VM User Data
ZStack ZSphere supports importing User Data (custom user-defined data). By providing custom parameters or scripts, you can perform customized configurations or accomplish specific tasks on the VMs.
Import User Data to Linux VMs
Before you begin
- Before importing User Data, ensure the VM image has cloud-init installed. Recommended version: 0.7.9, 17.1, 19.4, or later version.
- When setting hostname and SSH password via User Data, avoid configuring these parameters again on the platform to prevent conflicts.
- For Linux VMs created from images with pre-installed cloud-init, you must import User Data. Otherwise, cloud-init task will wait until timeout.
Procedure
-
Prepare the User Data script for your desired functionality.
Example script:
#cloud-config users: - name: test shell: /bin/bash groups: users sudo: ['ALL=(ALL) NOPASSWD:ALL'] ssh-authorized-keys: - ssh-rsa AAAAB3NzaC1LXCJfjroD1lT root@10-0-0-18 bootcmd: - mkdir /tmp/temp write_files: - path: /tmp/Cloud_config content: | Hello,world! permissions: '0755' fqdn: Perf-test disable_root: false ssh_pwauth: yes chpasswd: list: | root:word expire: False runcmd: - echo ls -l / >/root/list.shThis example script performs the following actions:- Create user "test" with SSH Key authentication during VM creation.
- Write to /etc/hosts, create directory /tmp/temp, and generate files with specified content during boot.
- Set hostname, enable root user, allow SSH password authentication, and change root password.
- Run the
echo ls -l /command.
- In the navigation pane, choose Inventory.
- In the inventory, right-click a cluster, host, or image, then select New Virtual Machine
- In the New Virtual Machine dialog, select .
- Paste your script into the User Data input field.
- Complete the VM creation process to import the User Data.
Import User Data to Windows VMs
Before you begin
- Before importing User Data, ensure the VM image has Cloudbase-init installed. Recommended version: 0.9.11. For more information about Cloudbase-init, see Cloudbase Documentation.
- When setting hostname and SSH password via User Data, avoid configuring these parameters again on the platform to prevent conflicts.
- For Windows VMs created from images with pre-installed Cloudbase-init, you must import User Data. Otherwise, Cloudbase-init task will wait until timeout.
Procedure
-
Prepare the User Data script for your desired functionality.
Example script:
#cloud-config write_files: - encoding: b64 content: NDI= path: C:\b64 permissions: '0644' - encoding: base64 content: NDI= path: C:\b64_1 permissions: '0644' - encoding: gzip content: !!binary | H4sIAGUfoFQC/zMxAgCIsCQyAgAAAA== path: C:\gzip permissions: '0644'This example script creates three files during VM startup: b64, b64_1, gzip on the C drive.
- In the navigation pane, choose Inventory.
- In the inventory, right-click a cluster, host, or image, then select New Virtual Machine
- In the New Virtual Machine dialog, select .
- Paste your script into the User Data input field.
- Complete the VM creation process to import the User Data.
