Results 1 to 14 of 14

Thread: Start and stop KVM VM from command line

  1. #1
    Join Date
    Aug 2008
    Posts
    2

    Default Start and stop KVM VM from command line

    Hello! Great work guys !

    I have a small problem, I want make a small bash script for backup qcow2 files, how can I stop from command line (no web interface) an KVM machine ?

    Like vmctl stop/start, but for KVM VMs.

    Thanks.

  2. #2
    Join Date
    Aug 2006
    Posts
    9,745

    Default

    Quote Originally Posted by steno View Post
    Hello! Great work guys !

    I have a small problem, I want make a small bash script for backup qcow2 files, how can I stop from command line (no web interface) an KVM machine ?

    Like vmctl stop/start, but for KVM VMs.

    Thanks.
    just type

    qm

    and you will see the options:

    Code:
    qm <command> <vmid> [OPTIONS]
    qm [create|set] <vmid>
            --memory  <MBYTES>    memory in MB (64 - 8192)
            --smp  <N>            set number of CPUs to <N>
            --ostype NAME         specify OS type
            --onboot [yes|no]     start at boot
            --keyboard XX         set vnc keyboard layout
            --cpuunits <num>      CPU weight for a VM
            --name <text>         Add a name for the VM
            --boot [a|c|d|n]      specify boot order
            --bootdisk <disk>     enable booting from <disk>
            --acpi (yes|no)       enable/disable ACPI
            --localtime (yes|no)  set the RTC to local time
    
            --vlan[0-9u] MODEL=XX:XX:XX:XX:XX:XX[,MODEL=YY:YY:YY:YY:YY:YY]
    
            --ide<N>    [file=]file,][,media=d]
                        [,cyls=c,heads=h,secs=s[,trans=t]]
                        [,snapshot=on|off][,cache=on|off][,format=f]
            --ide<N> <GBYTES>     create new disk
            --ide<N> delete       delete disk
            --cdrom <file>        is an alias for --ide2 <file>,media=cdrom
    
            --scsi<N>   [file=]file,][,media=d]
                        [,cyls=c,heads=h,secs=s[,trans=t]]
                        [,snapshot=on|off][,cache=on|off][,format=f]
            --scsi<N> <GBYTES>    create new disk
            --scsi<N> delete      delete disk
    
            --virtio<N> [file=]file,][,media=d]
                        [,cyls=c,heads=h,secs=s[,trans=t]]
                        [,snapshot=on|off][,cache=on|off][,format=f]
            --virtio<N> <GBYTES>  create new disk
            --virtio<N> delete    delete disk
    
    qm monitor <vmid>       connect to vm control monitor
    qm start <vmid>         start vm
    qm reboot <vmid>        reboot vm (shutdown, start)
    qm shutdown <vmid>      gracefully stop vm (send poweroff)
    qm stop <vmid>          kill vm (immediate stop)
    qm reset <vmid>         reset vm (stop, start)
    qm suspend <vmid>       suspend vm
    qm resume <vmid>        resume vm
    qm destroy <vmid>       destroy vm (delete all files)
    
    qm cdrom <vmid> [<device>] <path>  set cdrom path. <device is ide2 by default>
    qm cdrom <vmid> [<device>] eject   eject cdrom
    
    qm unlink <vmid> <file>  delete unused disk images
    qm vncproxy <vmid> <ticket>  open vnc proxy
    qm list                 list all virtual machines
    one problem: if you run a win2003 server you cannot shutdown if no admin is logged in. maybe a windows guy out there have a solution for this? on XP its no problem.
    Best regards,
    Tom

    Do you have already a Commercial Support Subscription? - If not, Buy now

  3. #3
    Join Date
    Aug 2008
    Posts
    2

    Default

    Thanks, Tom.

    For problem with Windows 2003 server, i'm not a windows guy but on local policy you must allow shutdown without logon.

    1. Start / Run / gpedit.msc
    2. Drill into Computer Configuration / Windows Settings / Security Settings / Local Policies / Security Options. Find the entry named "Shutdown: Allow system to be shut down without having to log on". Double click on it, change it to "Enabled".
    3. Drill into Computer Configuration / Administrative Templates / System. Find the entry named "Display Shutdown Event Tracker". Double click on it, change it to "Disabled".

    Now "qm shutdown VMID" works fine.

    Enjoy

    Warning! Remeber, this "hack" enable shutdown button on login dialog ...

    Byez.

  4. #4
    Join Date
    Apr 2009
    Location
    Berkeley, CA
    Posts
    163

    Default Re: Start and stop KVM VM from command line

    I've tried to run:
    Code:
    qm shutdown <vmid>
    ... but it doesn't seem to shutdown my VMs.

    If I run:
    Code:
    qm stop <vmid>
    ... it works just fine, though.

    But I'd rather not need to kill my machines that way. Any ideas/suggestions?

  5. #5
    Join Date
    Aug 2006
    Posts
    9,745

    Default Re: Start and stop KVM VM from command line

    Quote Originally Posted by mlanner View Post
    I've tried to run:
    Code:
    qm shutdown <vmid>
    ... but it doesn't seem to shutdown my VMs.

    If I run:
    Code:
    qm stop <vmid>
    ... it works just fine, though.

    But I'd rather not need to kill my machines that way. Any ideas/suggestions?
    does your guest accept anonymous acpi shutdowns? what OS do you run?
    Best regards,
    Tom

    Do you have already a Commercial Support Subscription? - If not, Buy now

  6. #6
    Join Date
    Apr 2009
    Location
    Berkeley, CA
    Posts
    163

    Default Re: Start and stop KVM VM from command line

    Sorry about that. I should've included that info. The guests I was trying to shutdown were all Ubuntu 10.04 server.

  7. #7
    Join Date
    Aug 2006
    Posts
    9,745

    Default Re: Start and stop KVM VM from command line

    install acpid.

    Code:
    apt-get install acpid
    Best regards,
    Tom

    Do you have already a Commercial Support Subscription? - If not, Buy now

  8. #8
    Join Date
    Apr 2009
    Location
    Berkeley, CA
    Posts
    163

    Default

    Thanks Tom. Works beautifully.

    Out of curiosity, would:

    qm shutdown all

    ... work?

  9. #9
    Join Date
    Apr 2005
    Location
    Austria
    Posts
    11,820

    Default Re: Start and stop KVM VM from command line

    Quote Originally Posted by mlanner View Post
    qm shutdown all
    That is called 'qm stopall' (that tries to shutdown first).

  10. #10
    Join Date
    Apr 2009
    Location
    Berkeley, CA
    Posts
    163

    Default

    Dietmar,

    Thanks. I tried your suggestion and it works fine.

  11. #11
    Join Date
    Apr 2009
    Location
    Berkeley, CA
    Posts
    163

    Default Re: Start and stop KVM VM from command line

    Quote Originally Posted by dietmar View Post
    That is called 'qm stopall' (that tries to shutdown first).
    Has the qm stopall command been deprecated?

  12. #12
    Join Date
    Apr 2005
    Location
    Austria
    Posts
    11,820

    Default Re: Start and stop KVM VM from command line

    Quote Originally Posted by mlanner View Post
    Has the qm stopall command been deprecated?
    Yes, please use

    # service pve-manager stop

    This stops all VMs and all Containers (we have start/stop ordering now).
    Best regards,
    Dietmar

    Do you have already a Commercial Support Subscription? - If not, Buy now

  13. #13
    Join Date
    Apr 2014
    Posts
    11

    Default Re: Start and stop KVM VM from command line

    I know this is a very old thread but as I can't find a better one, here comes my question:

    I'M busy setting up my backup of the proxmox machine with duply and duplicity and duply has a file called pre and one post - I planned to insert "service pve-manager stop" into pre and "service pve-manager start" into post but it only worked half-way:

    I manually executed duply from the command line as root and it successfully stopped all VMs but failed to start them. When I re-connected to my screen session, the command service pve-manager start was just displayed on the display without any apparent result. Any ideas?
    My next try will be to insert "/etc/init.d/pve-manager start" into post and see if that makes any difference...

    Quote Originally Posted by dietmar View Post
    Yes, please use

    # service pve-manager stop

    This stops all VMs and all Containers (we have start/stop ordering now).

  14. #14
    Join Date
    Apr 2014
    Posts
    11

    Default Re: Start and stop KVM VM from command line

    sorry, please disregard my last reply, I only realized now this is a proxmox 1.x thread. I'm running proxmox 3.2 :-/

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •