KVM常用操作命令

  • 查看虚拟机
$ virsh list --all
 Id    Name                           State
----------------------------------------------------
 -     userver                        shut off
 -     win7                           shut off
  • 显示虚拟机信息
$ virsh dominfo userver
Id:             -
Name:           userver
UUID:           2677045a-35a2-4730-99f7-ec8ed2a453da
OS Type:        hvm
State:          shut off
CPU(s):         2
Max memory:     2097152 KiB
Used memory:    2097152 KiB
Persistent:     yes
Autostart:      disable
Managed save:   no
Security model: apparmor
Security DOI:   0
  • 启动虚拟机
$ virsh start userver
Domain userver started
  • 显示虚拟机内存和CUP

    $ virt-top
    virt-top 09:39:42 - x86_64 4/4CPU 2537MHz 7899MB 0.2% 0.2% 0.1% 0.1%
    2 domains, 1 active, 1 running, 0 sleeping, 0 paused, 1 inactive D:0 O:0 X:0
    CPU: 0.1%  Mem: 2048 MB (2048 MB by guests)
    
  • 显示虚拟机分区信息

    $ sudo virt-df userver
    Filesystem                           1K-blocks       Used  Available  Use%
    userver:/dev/sda2                    102684600    4446164   92979328    5%
    
    
  • 设置虚拟机开机启动

$ virsh autostart userver
  • 关闭开机启动

    $ virsh autostart --disable userver
    
  • 关闭虚拟机

    $ virsh shutdown userver
    
  • 删除虚拟机

    $ virsh undefine userver
    
  • 通过控制窗口登录虚拟机

    $ virsh console userver
    
  • 更改虚拟机参数

    #查看当前内容
    $ eric@ray:~
    $ virsh dominfo userver | grep memory
    Max memory:     2097152 KiB
    Used memory:    2097152 KiB
    
    #动态设置内存 512MB 单位必须是KB
    eric@ray:~
    $ virsh setmem userver 524288 
    
    #查看内存变化
    eric@ray:~
    $ virsh dominfo userver | grep memory
    Max memory: 14194304 KiB
    Used memory: 524288 kiB
    
    #增加内存
    eric@ray:~
    $ virsh shutdown userver
    $ virsh edit userver #直接更改内存
    $ virsh create /etc/libvirt/demu/userver/xml
    
    
  • 删除虚拟机

    # 停止虚拟机
    $ virsh shutdown userver
    $ virsh destroy userver
    $ virsh undefine userver
    # 删除硬盘 不建议操作
    $ rm /dev/vg_userver/userver
    

你可能感兴趣的:(Linux)