How to use the command 'qm create' (with examples)
The command ‘qm create’ is used to create or restore a virtual machine on QEMU/KVM Virtual Machine Manager. It provides various options to customize the creation process and configure the virtual machine according to specific requirements.
Use case 1: Create a virtual machine
Code:
qm create 100
Motivation: The command ‘qm create’ is used to create a new virtual machine. By providing the ID of the virtual machine (in this case, 100), the command will create a new virtual machine with the default configuration.
Explanation: The ‘create’ subcommand followed by the virtual machine ID is used to create a new virtual machine. The ID should be unique and not conflict with existing virtual machines.
Example output: The command will create a new virtual machine with the specified ID (100), and it will have the default configuration settings.
Use case 2: Automatically start the machine after creation
Code:
qm create 100 --start 1
Motivation: By automatically starting the virtual machine after creation, the user can avoid the extra step of manually starting it.
Explanation: The ‘–start’ argument followed by a value of 1 is used to specify that the virtual machine should be started automatically after creation. A value of 0 would mean not to start the virtual machine automatically.
Example output: The command will create a new virtual machine with the specified ID (100) and start it automatically, ensuring the virtual machine is ready for use without any additional steps.
Use case 3: Specify the type of operating system on the machine
Code:
qm create 100 --ostype win10
Motivation: By specifying the type of operating system on the machine, the virtual machine can be configured with the appropriate settings and optimizations for that specific OS.
Explanation: The ‘–ostype’ argument followed by the OS type (in this case, ‘win10’ for Windows 10) is used to specify the type of operating system running on the virtual machine. This information helps in configuring the virtual machine correctly.
Example output: The command will create a new virtual machine with the specified ID (100) and configure it with the settings and optimizations suitable for Windows 10.
Use case 4: Replace an existing machine (requires archiving it)
Code:
qm create 100 --archive path/to/backup_file.tar --force 1
Motivation: This example is useful when there is a need to replace an existing virtual machine with a new one while preserving its data and configuration.
Explanation: The ‘–archive’ argument followed by the path to a backup file (in this case, ‘path/to/backup_file.tar’) is used to specify the archive file that contains the data and configuration of the virtual machine to be replaced. The ‘–force’ argument followed by a value of 1 is used to override any warnings or prompts during the replacement process.
Example output: The command will create a new virtual machine with the specified ID (100) while replacing an existing virtual machine that is represented by the backup archive file. Any necessary data and configuration will be restored, and the new virtual machine will take its place.
Use case 5: Specify a script that is executed automatically depending on the state of the virtual machine
Code:
qm create 100 --hookscript path/to/script.pl
Motivation: By specifying a script to be executed depending on the state of the virtual machine, custom actions can be performed to automate certain tasks or adapt the behavior of the virtual machine.
Explanation: The ‘–hookscript’ argument followed by the path to a script (in this case, ‘path/to/script.pl’) is used to specify the script that should be executed when certain events occur or the state of the virtual machine changes. This can be used to perform custom actions or automate tasks.
Example output: The command will create a new virtual machine with the specified ID (100) and associate the specified script with it. The script will be executed when specified events occur or the state of the virtual machine changes.
Conclusion:
The ‘qm create’ command is a powerful tool for creating and restoring virtual machines on QEMU/KVM Virtual Machine Manager. By exploring the various use cases, users can tailor the creation process according to their specific needs and efficiently manage virtual machines.