Introduction to Proxmox
Proxmox is an open-source virtualization platform based on Debian Linux, allowing users to run multiple virtual machines on a single physical host. It offers many advanced features, such as high availability, backup and restore, cluster management, and more. Proxmox supports various virtualization technologies, including KVM and LXC, and it also provides an easy-to-use web interface, enabling users to manage virtual machines, storage, and networks with ease. The main goal of Proxmox is to provide a powerful virtualization solution for both enterprise and individual users, while maintaining ease of use and reliability. In the Proxmox system, the “qm” command is the command-line tool for managing virtual machines, with key functionalities including creating, starting, stopping, deleting, cloning, migrating, backing up, and more.
Command Usage Examples
0. Command Syntax
The command refers to operations such as “create”, “stop”, “start” for virtual machines. The basic usage is “qm command vmid”, with different commands having different parameter options.
# qm <COMMAND> [ARGS] [OPTIONS]
1. List Virtual Machines
qm list
2. Create a Virtual Machine
When creating a virtual machine, parameters such as memory size and CPU count need to be specified. The following command creates a virtual machine with 8GB memory, 2 cores, and a VM ID of 182. Since many parameters need to be set when creating a virtual machine, it is recommended to complete the creation through the graphical interface.
qm create –memory 8192 –sockets 1 –cores 2 182
3. Start a Virtual Machine
qm start 180
4. Stop a Virtual Machine
qm stop 180
5. Check Virtual Machine Status
qm status 180
6. Unlock a Virtual Machine
If a virtual machine encounters errors during backup, cloning, migration, or snapshot operations, it may become locked, making it impossible to shut down or restart from the interface. To unlock the virtual machine, use the following command. If this command does not unlock it, you may need to delete the lock file under “/run/lock/qemu-server/lock-180.conf”.
qm unlock 180
7. Suspend a Virtual Machine
qm suspend 180
8. Resume a Virtual Machine
qm resume 180
9. Reset a Virtual Machine
qm reset 180
10. List Virtual Machine Snapshots
If you need to restore a virtual machine snapshot, you can first use `qm listsnapshot` to view the current snapshot list.
qm listsnapshot 180
11. Rollback Virtual Machine to a Specific Snapshot
root@s129:~# qm rollback 180 init0
Logical volume “vm-180-disk-0” successfully removed
Logical volume “vm-180-disk-0” created.
12. View Virtual Machine Configuration Information
root@s129:~# qm config 180
boot: order=scsi0;ide2;net0
cores: 1
ide2: local:iso/CentOS-8-x86_64-1905-dvd1.iso,media=cdrom
memory: 4096
name: s180
net0: virtio=AE:DB:1A:1B:65:D5,bridge=vmbr0
numa: 0
ostype: l26
parent: init1
scsi0: local-lvm:vm-180-disk-0,size=60G
scsihw: virtio-scsi-pci
smbios1: uuid=c3751a2f-6ebe-4e8c-aeba-26949f6d7e83
sockets: 2
vmgenid: 95e6f105-d92e-4546-80df-10ca3d7cdcf0
13. Delete a Virtual Machine
qm destroy 182
14. Create a Virtual Machine Snapshot
root@s129:~# qm snapshot 180 init3 -description snapshot-test
snapshotting ‘drive-scsi0’ (local-lvm:vm-180-disk-0)
Logical volume “snap_vm-180-disk-0_init3” created.
root@s129:~# qm listsnapshot 180
Wide character in printf at /usr/share/perl5/PVE/GuestHelpers.pm line 160.
`-> init0 2023-01-03 16:25:08 centos8 initialization completed
Wide character in printf at /usr/share/perl5/PVE/GuestHelpers.pm line 160.
`-> init1 2023-04-12 16:21:39 system upgraded to centos8-stream stable version
`-> init2 2023-04-14 16:29:14 no-description
`-> init3 2023-04-14 16:34:49 snapshot-test
`-> current You are here!
15. Delete a Snapshot
root@s129:~# qm delsnapshot 180 init2
Logical volume “snap_vm-180-disk-0_init2” successfully removed
root@s129:~# qm listsnapshot 180
Wide character in printf at /usr/share/perl5/PVE/GuestHelpers.pm line 160.
`-> init0 2023-01-03 16:25:08 centos8 initialization completed
Wide character in printf at /usr/share/perl5/PVE/GuestHelpers.pm line 160.
`-> init1 2023-04-12 16:21:39 system upgraded to centos8-stream stable version
`-> init3 2023-04-14 16:34:49 snapshot-test
`-> current You are here!
16. Clone a Virtual Machine
root@s129:~# qm clone 180 182
create full clone of drive scsi0 (local-lvm:vm-180-disk-0)
Logical volume “vm-182-disk-0” created.
drive mirror is starting for drive-scsi0
drive-scsi0: transferred 0.0 B of 60.0 GiB (0.00%) in 0s
…
drive-scsi0: transferred 60.0 GiB of 60.0 GiB (100.00%) in 7m 23s, ready
all ‘mirror’ jobs are ready
suspend vm
trying to acquire lock…
drive-scsi0: Cancelling block job
drive-scsi0: Done.
resume vm
trying to acquire lock…
17. Migrate a Virtual Machine to Another Node
First, check the names of the other nodes in the cluster, then execute the migration command. If there is local host configuration, such as a local CD-ROM configuration, you may encounter the error “can’t migrate local disk ‘local:iso/CentOS-8-x86_64-1905-dvd1.iso’: local cdrom image.” You can edit the configuration file to unmount the local ISO configuration, and then execute the migration command again.
root@s129:~# pvecm nodes
Membership information
———————-
Nodeid Votes Name
1 1 s129 (local)
2 1 s130
3 1 s128
root@s129:~# qm migrate 182 s128
18. Modify Virtual Machine Parameters
root@s129:~# qm set 180 -cores 1
update VM 150: -cores 1
root@s129:~# qm set 180 -memory 8192
update VM 181: -memory 8192
19. Enter Virtual Machine Monitor
Use the “qm monitor” command to enter the virtual machine console, where you can execute commands to view virtual machine information.
root@s129:~# qm monitor 180
Entering Qemu Monitor for VM 180 – type ‘help’ for help
qm> info name
s180
qm> info version
6.0.0pve-qemu-kvm_6.0.0
qm>help
Leave a Reply