Libvirt, virsh, virt-manager summary

Background

Libvirt is an open-source API, daemon and management tool for managing platform virtualization.
It can be used to manage KVM, Xen, VMware ESXi, QEMU and other virtualization technologies.
These APIs are widely used in the orchestration layer of hypervisors in the development of a cloud-based solution.

  • Supported Hypervisors for libvirt

在这里插入图片描述

  • Relationship between Qemu, KVM and libvirt, virt-manager

    • About virt-manager’s supporting tools

    virt-manager is a GUI that can be used to create, destroy, stop, start and edit virtual machines and configure the virtual environment (such as virtual networks etc).

    virt-install is a command line tool which provides an easy way to provision operating systems into virtual machines.

    virt-viewer is a lightweight UI interface for interacting with the graphical display of virtualized guest OS. It can display VNC or SPICE, and uses libvirt to lookup the graphical connection details.

    virt-clone is a command line tool for cloning existing inactive guests. It copies the disk images, and defines a config with new name, UUID and MAC address pointing to the copied disks.

    virt-xml is a command line tool for easily editing libvirt domain XML using virt-install’s command line options.

    virt-bootstrap is a command line tool providing an easy way to setup the root file system for libvirt-based containers.

    • About virsh

    virsh is a command line interface that can be used to create, destroy, stop start and edit virtual machines and configure the virtual environment (such as virtual networks etc)

在这里插入图片描述

Best Practices

  • Use virt-install to create a new VM
#~/bin/bash

OS_NAME=sgx-worker-node1
OS_IMAGE=<path-to>/ubuntu-20.04.3-desktop-amd64.iso
DISK_IMAGE=<path-to>/sgx-worker-node1.img
DISK_SIZE=200

virt-install \
    --name $OS_NAME \
    --memory 8192 \
    --vcpus=8 \
    --cpu host \
    --qemu-commandline='-enable-kvm' \
    --qemu-commandline='-cpu host,+sgx-provisionkey,+sgx2,+sgxlc,+sgx-kss' \
    --qemu-commandline='-object memory-backend-epc,id=mem1,size=128M,prealloc=on' \
    --qemu-commandline='-M sgx-epc.0.memdev=mem1,sgx-epc.0.node=0' \
    --disk path=$DISK_IMAGE,size=$DISK_SIZE \
    --os-variant ubuntu20.04 \
    --location=$OS_IMAGE \
    --network type=direct,source=enp6s0f0,source_mode=bridge,model=virtio \
    --graphics vnc \
    --autostart \
    --accelerate \
    --hvm &
  • Clone VM to new one
#!/bin/sh

OLD_VM=sgx-develop-node1
NEW_VM=sgx-develop-node2

NEW_DISK_IMAGE=<path-to>/sgx-develop-node2.img

virt-clone --original $OLD_VM --name $NEW_VM --file $NEW_DISK_IMAGE
  • Rename KVM VM with virsh
The syntax is:
# virsh domrename {domain} {new-name}

# To rename VM from foo to bar, type:
$ virsh shutdown foo
> Domain foo is being shutdown

# Now rename a VM, run:
$ virsh domrename foo bar
> Domain successfully renamed

# Start a VM/domain, enter:
$ virsh start bar
  • Use virt-viewer to connect the guest VM
The syntax is:
# virt-viewer <domain> or <id>

# List the VM status
virsh list --all
 Id   Name               State
-----------------------------------
 8    sgx-worker-node1   running
 9    sgx-worker-node2   running
 -    test-vm            shut off

# View the runing vm
virt-viewer sgx-worker-node1
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值