Create Virtual Machine from a template

From Sea of Fate
Jump to navigationJump to search

Introduction

This is not a deep dive in to ansible or similar but a simple quick and dirty guide to creating a new VM from a template and configuring some of the networking with cloud init.


Creating VMs on Command

To create a new host from your template with the specified IP address, gateway, DNS server, and search domain, you can use the Proxmox command-line interface (CLI) with the `qm clone` command and appropriate Cloud-Init parameters.

Here's how you can do it:

Using the `qm clone` Command

qm clone <template_vmid> <new_vmid> --name <new_hostname> --ipconfig0 "ip=192.168.100.26/24,gw=192.168.100.1" --nameserver 192.168.110.11 --searchdomain seaoffate.local

Explanation:

  • qm clone <template_vmid> <new_vmid>:
   * This is the base command to clone a VM.
   * Replace `<template_vmid>` with the ID of your template VM.
   * Replace `<new_vmid>` with the desired ID for the new VM.
  • --name <new_hostname>:
   * Replace `<new_hostname>` with the desired hostname for the new VM.
  • --ipconfig0 "ip=192.168.100.26/24,gw=192.168.100.1":
   * This sets the IPv4 configuration for the first network interface (`eth0` or similar).
   * `ip=192.168.100.26/24` sets the IP address and netmask.
   * `gw=192.168.100.1` sets the gateway address.
  • --nameserver 192.168.110.11:
   * This sets the DNS server address.
  • --searchdomain seaoffate.local:
   * This sets the search domain.

Example

If your template VM ID is 100, and you want to create a new VM with ID 101 and hostname "newhost," the command would be:

qm clone 100 101 --name newhost --ipconfig0 "ip=192.168.100.26/24,gw=192.168.100.1" --nameserver 192.168.110.11 --searchdomain seaoffate.local

Important Notes

  • Cloud-Init: This command assumes that your template VM has Cloud-Init installed and configured.
  • Network Interface Name: The network interface name might vary. If your VM uses a different interface name (e.g., `ens3`), you might need to adjust the Cloud-Init configuration accordingly.
  • Testing: After creating the new VM, verify that the IP address, gateway, DNS server, and search domain are correctly configured.
  • Proxmox User Permissions: The user running this command must have sufficient permissions to create VMs.
  • Firewall: Ensure that your firewall allows network traffic to and from the new VM.
  • DHCP: Make sure that the IP address does not conflict with any IP addresses assigned by a DHCP server.

By using this command, you can easily create new VMs from your template with the desired network configuration.

1. Basic VM Configuration

  • VM ID (`<new_vmid>`): The unique identifier for the new VM.
  • VM Name (`--name <new_hostname>`): The hostname or descriptive name for the VM.
  • Target Node (`--target <node>`): The Proxmox node where the VM will be created.
  • Full Clone (`--full`): Creates a full, independent copy of the VM's disk. (Default is linked clone)

2. Hardware Configuration

  • CPU Cores (`--cores <n>`): The number of CPU cores assigned to the VM.
  • Sockets (`--sockets <n>`): The number of CPU sockets assigned to the VM.
  • Memory (`--memory <n>`): The amount of RAM (in MB) assigned to the VM.
  • NUMA (`--numa <0|1>`): Enables or disables NUMA support.
  • CPU Type (`--cpu <type>`): The CPU type (e.g., `host`, `kvm64`, `Penryn`).
  • Machine Type (`--machine <type>`): The machine type (e.g., `pc-q35-7.1`).
  • BIOS (`--bios <type>`): The BIOS type (e.g., `seabios`, `ovmf`).
  • VGA (`--vga <type>`): The VGA adapter type (e.g., `std`, `virtio`).
  • Keyboard Layout (`--keyboard <layout>`): The keyboard layout (e.g., `en-us`, `de`).

3. Storage Configuration

  • Disk Size (`--disk <disk>[,size=<n>]`): Size of the new virtual disk.
  • Storage (`--storage <storage>`): The storage location for the VM's disks.
  • Disk Type (`--disk <disk>[,format=<format>]`): The disk format (e.g., `raw`, `qcow2`).
  • Cache (`--cache <mode>`): Disk cache mode (e.g., `none`, `writethrough`, `writeback`).
  • IO Thread (`--iothread <0|1>`): Enables or disables I/O threading.

4. Network Configuration

  • Network Bridge (`--net<n> bridge=<bridge>`): The network bridge to connect the VM to.
  • Network Model (`--net<n> model=<model>`): The network adapter model (e.g., `virtio`, `e1000`).
  • MAC Address (`--net<n> macaddr=<mac>`): The MAC address for the network interface.
  • VLAN ID (`--net<n> vlan=<vlan>`): The VLAN ID for the network interface.
  • IP Configuration (`--ipconfig<n> "ip=<ip>/<cidr>,gw=<gw>"`): IPv4 or IPv6 configuration.
  • Name Server (`--nameserver <ns>`): DNS server address.
  • Search Domain (`--searchdomain <domain>`): DNS search domain.

5. Cloud-Init Configuration

  • User Data (`--ciuser <user>`): The username for Cloud-Init.
  • Password (`--cipassword <password>`): The password for Cloud-Init.
  • SSH Public Keys (`--sshkeys <keys>`): SSH public keys for Cloud-Init.
  • DNS Search Domain (`--searchdomain <domain>`): DNS search domain.
  • DNS Name Server (`--nameserver <ns>`): DNS name server.

6. Other Options

  • Start VM (`--start <0|1>`): Starts the VM after creation.
  • Description (`--description <text>`): Adds a description to the VM.
  • Tags (`--tags <tags>`): Adds tags to the VM.

Example with Multiple Options

qm clone 100 101 --name newvm --cores 4 --memory 4096 --storage local-lvm --disk 0,size=32G --net0 bridge=vmbr0,model=virtio --ipconfig0 "ip=192.168.100.27/24,gw=192.168.100.1" --nameserver 192.168.110.11 --searchdomain seaoffate.local --ciuser myuser --cipassword mypassword

This command clones VM 100 to VM 101, sets the name, CPU cores, memory, storage, disk size, network bridge, IP configuration, DNS, Cloud-Init user, and Cloud-Init password.

Remember to replace the placeholder values with your desired settings. Consult the Proxmox documentation for the most up-to-date information and options.