proxmox - qm

KVM 的 VM 的設定檔放在:

/etc/pve/qemu-server/"VMID".conf

 

管理指令(qm):

qm <COMMAND> [ARGS] [OPTIONS]

qm help

例出所有 VM:

root@server:~# qm list

      VMID NAME                 STATUS     MEM(MB)    BOOTDISK(GB) PID
       101 centos0              running    512                8.00 2872
       104 centos1              running    512                4.00 7723
       105 winxp                stopped    512               32.00 0
       106 centos2              running    512                4.00 7030

 

status

server:~# qm status 110 -verbose

status: running

 

查看 VM 的設定:

server:~# qm config 101

bootdisk: virtio0
cores: 1
ide2: none,media=cdrom
memory: 512
name: centos0
net0: virtio=FE:13:F5:58:3C:58,bridge=vmbr0
ostype: l26
sockets: 1
virtio0: vps_pool-1_storage:101/vm-101-disk-1.qcow2

 

查看 VM的開機指令:

root@server:~# qm showcmd 101

/usr/bin/kvm -id 101 -chardev socket,id=monitor,path=/var/run/qemu-server/101.mon,server,nowait
-mon chardev=monitor,mode=readline -vnc unix:/var/run/qemu-server/101.vnc,x509,password
-pidfile /var/run/qemu-server/101.pid -daemonize -usbdevice tablet -name centos0 -smp sockets=1,cores=1
-nodefaults -boot menu=on -vga cirrus -k en-us -drive if=none,id=drive-ide2,media=cdrom,aio=native
-device ide-cd,bus=ide.1,unit=0,drive=drive-ide2,id=ide2,bootindex=200
-drive file=/home/vps_pool-1_storage/images/101/vm-101-disk-1.qcow2,if=none,id=drive-virtio0,aio=native
-device virtio-blk-pci,drive=drive-virtio0,id=virtio0,bus=pci.0,addr=0xa,bootindex=100 -m 512
-netdev type=tap,id=net0,ifname=tap101i0,script=/var/lib/qemu-server/pve-bridge,vhost=on
-device virtio-net-pci,mac=FE:13:F5:58:3C:58,netdev=net0,bus=pci.0,addr=0x12,id=net0,bootindex=300

 

一般操作:

  • qm suspend <vmid> 
  • qm resume <vmid>
  • qm start <vmid>
  • qm shutdown <vmid>
  • qm reset <vmid> 
  • qm stop <vmid>

 

Qemu Monitor interface

qm monitor <vmid>

 

設定:

qm set <vmid> [OPTIONS]

一般參數:

-memory 512      // MB (maximum available memory(ballooning))
-acpi 1          // default
-onboot 0       
-autostart 0
-balloon         // MB
-boot cdn
-bootdisk        // (ide|scsi|virtio)\d+
-cdrom
-cores 1
-cpu qemu64
-cpulimit        // 2 cpu = 200%, 0 = no limit
-cpuunits 1000   // weight
-hotplug 0       // disk, network
-hostpci 'bus:dev.func'
-keyboard en-us
-kvm 1
-localtime 0     // linux: 0, M$: 1
-lock
-name      string  //
-ostype            // optimization/features for specific operating systems
-watchdog  [[model=]i6300esb|ib700][,[action=]reset|shutdown|poweroff|pause|debug|none]

 

USB 設定:

-usb[n]    host=HOSTUSBDEVICE   // pass-through usb devices
                                                     // vendor_id:product_id | bus-port(.port)*

-serial[n] /dev/ttyS\d+         // Map host serial devices

 

          -virtio[n] [volume=]volume,] [,media=cdrom|disk]
                    [,cyls=c,heads=h,secs=s[,trans=t]] [,snapshot=on|off]
                    [,cache=none|writethrough|writeback|unsafe|directsync]
                    [,format=f] [,backup=yes|no] [,rerror=ignore|report|stop]
                    [,werror=enospc|ignore|report|stop] [,aio=native|threads]

          -sata[n]   [volume=]volume,] [,media=cdrom|disk]
                    [,cyls=c,heads=h,secs=s[,trans=t]] [,snapshot=on|off]
                    [,cache=none|writethrough|writeback|unsafe|directsync]
                    [,format=f] [,backup=yes|no] [,rerror=ignore|report|stop]
                    [,werror=enospc|ignore|report|stop] [,aio=native|threads]

網卡設定:

-net[n]    MODEL=XX:XX:XX:XX:XX:XX[,bridge=vmbr0][,rate=<Megabytes>][,tag=<vlanid>]

MODEL 有

  • e1000
  • rtl8139
  • virtio                   

NATed: GW: 10.0.2.2, DNS: 10.0.2.3, IP >= 10.0.2.15

 

其他:

-description string

-delete    string

-startup n+,n+                  // order,delay

-freeze 0        // Freeze CPU at startup  ( moniter 'c' to start)

-migrate_downtime integer 1         // maximum tolerated downtime
-migrate_speed integer 0            // MB/s

-digest    string                   // Prevent changes if  different SHA1 digest

qm unlink <vmid> {<idlist>}           // list of disk IDs you want to delete

qm wait <vmid>                        // Wait until the VM is stopped.

qm vncproxy <vmid>

qm unlock <vmid>                       // vzdump set a lock to prevent unintentional action

qm migrate <vmid> <target> [OPTIONS]

 

Example:

# create a new VM with 4 GB ide disk
qm create 300 -ide0 4 -net0 e1000 -cdrom proxmox-mailgateway_2.1.iso

qm shutdown 300 && qm wait 300 -timeout 40
 



建立與刪除

 

qm create <vmid>

 

刪除 VM 的 HardDisk:

qm unlink <vmid> {<idlist>}

-unused[n] string               // Reference to unused volumes

 

原全刪除整個 VM:

qm destroy <vmid>

Example:

server:~# qm destroy 112         // 不會再次確認 !!

有 task 在執行中:

task UPID:server:00024D56:0704E58B:5091D8AD:qmdestroy:112:root@pam: