tools to management KVM
cat global.vars
vim global.vars
./cmd/generate_mac_pool.sh
declare -A MACS=([host1]="" [host2]="" [hostn]="")
./cmd/generate_mac_pool.sh
./cmd/generate_network_xmls.sh
./cmd/generate_network_xmls.sh NET_NAMES NET_MACS
ls /tmp/vir_network
virsh net-create /tmp/vir_network
virsh net-list
delete a network by: virsh net-destroy
please prepare a image for VM firstly follow these guide:
./cmd/generate_domain_xml.sh
export HOST=cloud
export BASEIMG=/var/lib/libvirt/images/$HOST.qcow2
export VM_NAME=smartcity_$HOST
export VM_MEMSIZE_G=10
export VM_VCPUS=6
./cmd/generate_domain_xml.sh NET_MACS $HOST NET_NAMES
virsh create /tmp/vir_domain/$VM_NAME.xml
virsh list
You can also install a vm by: 15 virt-install examples | KVM virtualization commands cheatsheet
./cmd/inject_tail_ifcs_script.sh
./cmd/inject_tail_ifcs_script.sh $dom
./cmd/set_hostname.sh
./cmd/set_hostname.sh $dom $hostname
./cmd/inject_ssh_key.sh
./cmd/inject_ssh_key.sh $dom $user $key_file
./cmd/resize_volume.sh
./cmd/resize_volume.sh $dom $size $disk $volume
./cmd/attach_disk.sh
./cmd/attach_disk.sh $dom $size
This command is used for extend lvm in an activity guest. Please check your guest OS support hot plugin.
# grep "CONFIG_HOTPLUG_PCI_ACPI=" /boot/config-`uname -r`
CONFIG_HOTPLUG_PCI=y
# grep "CONFIG_HOTPLUG_PCI=" /boot/config-`uname -r`
CONFIG_HOTPLUG_PCI_ACPI=y
# grep "CONFIG_MEMORY_HOTPLUG=" /boot/config-`uname -r`
CONFIG_MEMORY_HOTPLUG=y
run these commands in host:
dom=virtio_nic
./cmd/create_lvm_in_vm.sh
./cmd/run_in_vm.sh $dom lsblk
./cmd/run_in_vm.sh $dom lvdisplay
dev=vda
lv=/dev/centos/root
./cmd/create_lvm_in_vm.sh $dom $dev $lv
you can also run these commands in guest:
GUSER=root
host=
scp ./src/vm/script/create_lvm.sh $GUSER@$host:~/
ssh $GUSER@$host
./create_lvm.sh $dev $lv_path
./cmd/run_in_vm.sh
echo "cat /etc/hostname" >> guest_host.sh
chmod a+x guest_host.sh
./cmd/run_in_vm.sh $dom - ./guest_host.sh
./cmd/run_in_vm.sh $dom lsblk
host:port -> vm:port
./cmd/vm_port_proxy.sh
./cmd/vm_port_proxy.sh $dom 8080
cp ./cmd/ssh_vm.sh /usr/bin/ssh-vm
ssh-vm
# https://www.cloudsavvyit.com/1889/how-to-convert-xml-to-json-on-the-command-line/
# https://stackoverflow.com/questions/61666898/convert-xml-to-json-using-command-line-or-using-shell-script
# https://www.endpoint.com/blog/2019/12/31/making-sense-of-xml-json-in-shell
# https://unix.stackexchange.com/questions/504880/script-to-translate-xml-to-json
# http://manpages.ubuntu.com/manpages/bionic/man1/xml2json.1p.html
# https://codefaster.substack.com/p/mastering-jq-xml-and-any-other-data
# https://www.hellocodeclub.com/how-to-convert-xml-to-json-in-python-ultimate-guide/
# https://linuxhint.com/python_xml_to_json/
https_proxy=http://comany.com:xxx pip3 install yq
cat | xq . << EOF
<e>
<a>some</a>
<b>textual</b>
<a>content</a>
</e>
EOF
cat | xq -x << EOF
{
"e": {
"a": [
"some",
"content"
],
"b": "textual"
}
}
EOF
- install window guest with virtio drivers