如何彻底删除kvm虚拟机_虚拟机命令怎么删除

如何彻底删除kvm虚拟机_虚拟机命令怎么删除(转)virsh命令速查表VirshVirshconnectVirshdisplaynodeinformation:VirshlistalldomainsListonlyactivedomainsVirshstartvmVirshautostartvmVirshautostartdisableVirshstopvm,virshshutd…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

(转)virsh命令速查表

virsh commands cheatsheet 原文链接

Virsh

Virsh connect

The virsh connect [hostname-or-URI] [–readonly] command begins a local hypervisor session using virsh. After the first time you run this command it will run automatically each time the virsh shell runs. The hypervisor connection URI specifies how to connect to the hypervisor. The most commonly used URIs are:

qemu:///system – connects locally as the root user to the daemon supervising guest virtual machines on the KVM hypervisor. qemu:///session – connects locally as a user to the user’s set of guest local machines using the KVM hypervisor.

virsh connect qemu:///system 

Virsh display node information:

This displays the host node information and the machines that support the virtualization process.

virsh nodeinfo

Virsh list all domains

To list both inactive and active domains, use the command:

virsh list --all 

List only active domains

virsh list 

Virsh start vm

virsh start test 

Virsh autostart vm

To set a vm to start automatically on system startup, do:

virsh autostart test
virsh dominfo test
  • Keep an eye on the option Autostart: enable.

Virsh autostart disable

To disable autostart feature for a vm:

virsh autostart --disable test

Virsh stop vm, virsh shutdown vm

To shutdown a running vm gracefully use:

virsh shutdown test

Virsh force shutdown vm

You can do a forceful shutdown of active domain using the command:

virsh destroy test

Virsh stop all running vms

In case you would like to shutdown all running domains, just issue the command below:

for i in ` virsh list | grep running | awk '{print $2}'` do
     virsh shutdown $i
done

Virsh reboot vm

To restart a vm named test, the command used is:

virsh reboot test

Virsh remove vm

To cleanly remove a vm including its storage columes, use the commands shown below. The domain test should be replaced with the actual domain to be removed.

virsh destroy test 2> /dev/null
virsh undefine  test
virsh pool-refresh default
virsh vol-delete --pool default test.qcow2

In this example, storage volume is named /var/lib/libvirt/images/test.qcow2

Virsh create a vm

If you would like to create a new virtual machine with virsh, the relevant command to use is `virt-install. This is crucial and can’t miss on virsh commands cheatsheet arsenal. The example below will install a new operating system from CentOS 7 ISO Image.

 virt-install \
--name centos7 \
--description "Test VM with CentOS 7" \
--ram=1024 \
--vcpus=2 \
--os-type=Linux \
--os-variant=rhel7 \
--disk path=/var/lib/libvirt/images/centos7.qcow2,bus=virtio,size=10 \
--graphics none \
--location $HOME/iso/CentOS-7-x86_64-Everything-1611.iso \
--network bridge:virbr0  \
--console pty,target_type=serial -x 'console=ttyS0,115200n8 serial'

Virsh connect to vm console

To connect to the guest console, use the command:

virsh console test

This will return a fail message if an active console session exists for the provided domain.

Virsh edit vm xml file

To edit a vm xml file, use:

virsh edit test

Virsh suspend vm, virsh resume vm

To suspend a guest called testwith virsh command, run:

virsh suspend test
  • Domain test suspended

NOTE: When a domain is in a suspended state, it still consumes system RAM. Disk and network I/O will not occur while the guest is suspended.

Resuming a guest vm:

To restore a suspended guest with virsh using the resume option:

virsh resume test

Domain test resumed

Virsh save vm

To save the current state of a vm to a file using the virsh command :

The syntax is:

virsh save test test.saved

Domain test saved to test.save

$ ls -l test.save 
-rw------- 1 root root 328645215 Mar 18 01:35 test.saved

Restoring a saved vm

To restore saved vm from the file:

virsh restore test.save 

Domain restored from test.save

Virsh Manage Volumes

Virsh create volume

To create a 2GB volume named testvol2 on the default storage pool, use:

virsh vol-create-as default  test_vol2.qcow2  2G
du -sh /var/lib/libvirt/images/test_vol2.qcow2
  • default: Is the pool name.
  • testvol2: This is the name of the volume.
  • 2G: This is the storage capacity of the volume.

Virsh attach a volume to vm

To attach created volume above to vm test, run:

virsh attach-disk --domain test \
--source /var/lib/libvirt/images/test_vol2.qcow2  \
--persistent --target vdb
  • –persistent: Make live change persistent
  • –target vdb: Target of a disk device

Virsh detach volume on vm

To detach above volume testvol2 from the vm test:

virsh detach-disk --domain test --persistent --live --target vdb

resize disk

Please note that you can directly grow disk image for the vm using qemu-img command, this will look something like this:

qemu-img resize /var/lib/libvirt/images/test.qcow2 +1G
  • The main shortcoming of above command is that you cannot resize an image which has snapshots.

Virsh delete volume

To delete volume with virsh command, use:

virsh vol-delete test_vol2.qcow2  --pool default
virsh pool-refresh  default
virsh vol-list default

Virsh Manage Snapshots

In this second last section of managing kvm guest machines with virsh command, we’ll have a look at managing VM snapshots.

Virsh Create Snapshot for a vm

virsh snapshot-create-as --domain test \
--name "test_vm_snapshot1" \
--description "test vm snapshot 1-working"

Virsh list Snapshots for a vm

virsh snapshot-list test

Virsh display info about a snapshot

To retrieve more information about a domain, use:

virsh snapshot-info --domain test --snapshotname test_vm_snapshot1

Virsh revert vm snapshot

Here we’ll create another snapshot called testvmsnapshot2, then revert to snapshot testvmsnapshot1

virsh snapshot-create-as \
--domain test --name "test_vm_snapshot2" \
--description "test vm snapshot 2-working"

Domain snapshot testvmsnapshot2 created Let’s revert the snapshot we created before:

virsh snapshot-list test
virsh snapshot-revert --domain test  --snapshotname test_vm_snapshot1  --running

Virsh delete snapshot

virsh snapshot-delete --domain test --snapshotname  test_vm_snapshot2
virsh snapshot-delete --domain test --snapshotname  test_vm_snapshot1

Virsh clone a vm

virt-clone --connect qemu:///system \
--original test \
--name test_clone \
--file /var/lib/libvirt/images/test_clone.qcow2 

Virsh manage VM vcpus

This virsh commands cheatsheet section covers how to add additional virtual cpus to a virtual machine:

virsh setvcpus --domain test --maximum 2 --config
virsh setvcpus --domain test --count 2 --config
virsh reboot test

Virsh manage VM ram

  • 单位是 KB

To adjust the total ram used by the guest operating system, the following commands are used: Also on virsh commands cheatsheet is managing RAM with virsh.

virsh setmaxmem test 2048 --config
virsh setmem test 2048 --config
virsh reboot test
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/169813.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • VBA编程基础和编程环境(二)

    VBA编程基础和编程环境(二)    上一节中认识了Excel宏的基本样子,明白了VBA就是一门类似于C、JAVA、Python等编程语言,了解了VBA与宏的关系,本节开始学习VBA编程的基础知识和编程环境,是整个学习编程的基础。    一、VBA编程的几个重要概念    0、过程    把VBA代码按照一定顺序和逻辑排列用来完成Excel某个任务的过程,其实就是用VBA代码按照先后…

    2022年6月7日
    33
  • 【STM32】HAL库 STM32CubeMX教程十三—RTC时钟

    【STM32】HAL库 STM32CubeMX教程十三—RTC时钟前言:本系列教程将对应外设原理,HAL库与STM32CubeMX结合在一起讲解,使您可以更快速的学会各个模块的使用所用工具:1、芯片:STM32F407ZET6/STM32F103ZET62、STM32CubeMx软件3、IDE:MDK-Keil软件4、STM32F1xx/STM32F4xxHAL库知识概括:通过本篇博客您将学到:RTC时钟原理STM32CubeMX创建…

    2022年6月2日
    233
  • pycharm使用小技巧_pycharm学笨办法

    pycharm使用小技巧_pycharm学笨办法一、常用小技巧1.设置代码字体点击左上角的“File”(文件),选择“Settings”(设置),输入“font”(字体)找到“Font”,在“Size”(大小)里面设置数字,默认是13,建议15或者18就可以了。2.设置菜单界面文字大小这里跟上面有些区别,上面是调整代码文字大小,但并没有改变菜单界面的文字大小,如果你的菜单界面文字比较小。那么你就需要去调整一下菜单界面的文字大小了,点击左上角的“File”,选择“Settings”,输入“font”,找到“Appearance”,在“Use

    2022年8月26日
    3
  • Delphi中QuotedStr介绍及使用

    Delphi中QuotedStr介绍及使用delphi函数给字符串两边加单引号并返回.声明:functionQuotedStr(constS:string):string;用函数QuotedStr把字符串S转换成为用引号括起来的字符串。单引号”‘”将被插入到字符串s的最前和最后。例如:abc->’abc’

    2022年10月18日
    0
  • python 下载百度文库_百度文库随便下载,解除限制「建议收藏」

    阅读须知:文章介绍的软件下载地址载文末,需要复制链接到浏览器打开今天有小伙伴在群里问有没有百度文库的下载工具,其实之前推荐过,但目前有新的工具出现了,而且更加好用,所以给大家更新一下百度文档0.95吾爱大神力作,软件是用python写的,跟其他下载器相比,优点就是能下载源文档,以前的冰点也很好用,但缺点是下载的是pdf文件,还需要转换,而这款软件相对来说方便多了纯文字文档下载之后是doc文件,图文…

    2022年4月13日
    59
  • 免费已备案二级域名_二级免备案域名

    免费已备案二级域名_二级免备案域名今天给大家推荐一个免备案的免费二级域名注册平台。DYUNS域名网-永久免费域名_免备案域名只需要一个邮箱,就能注册到自己的二级域名,非常方便。提供”icu.ltd”等超短域名注册服务,非常有利于用户访问与记忆。平台还提供了免费的CDN+防御+免备案服务,这是其他平台都没有的,也是我选择它的理由之一。管理也非常方便,后台一键就能完成自助删改解析等操作。官方客服的服务也是十分的到位,体验很好。大家也可以自行注册体验哦!…

    2022年9月10日
    0

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号