Linux KVM virsh-install 安装、导入模板
工具
查看 MAC 地址 使用信息1
2
3
4
5
6
7
8
9
10
11root@debian:~/kvm# cat show_mac_address_status.sh
#!/bin/bash
grep 'mac address' /etc/libvirt/qemu/*.xml|awk -F ": " '{print $2, $1}'| sort
root@debian:~/kvm#
root@debian:~/kvm#
root@debian:~/kvm#
root@debian:~/kvm# ./show_mac_address_status.sh
<mac address='12:34:56:78:90:a1'/> /etc/libvirt/qemu/win10_21H2.xml
<mac address='12:34:56:78:90:a2'/> /etc/libvirt/qemu/blog.xml
<mac address='52:54:00:92:69:4d'/> /etc/libvirt/qemu/koolshare.xml
root@debian:~/kvm#
查看 OS与发行版信息1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17root@debian:~/kvm# cat show_os_info.sh
#!/bin/bash
find /usr/share/osinfo/os/
root@debian:~/kvm# ./show_os_info.sh
/usr/share/osinfo/os/
/usr/share/osinfo/os/debian.org
/usr/share/osinfo/os/debian.org/debian-2.0.xml
/usr/share/osinfo/os/debian.org/debian-8.xml
/usr/share/osinfo/os/debian.org/debian-2.1.xml
/usr/share/osinfo/os/debian.org/debian-4.xml
/usr/share/osinfo/os/debian.org/debian-7.xml
/usr/share/osinfo/os/debian.org/debian-1.2.xml
/usr/share/osinfo/os/debian.org/debian-9.xml
/usr/share/osinfo/os/debian.org/debian-3.xml
/usr/share/osinfo/os/debian.org/debian-3.1.xml
/usr/share/osinfo/os/debian.org/debian-1.3.xml
查看 VNC 端口使用情况1
2
3
4
5
6
7
8
9
10
11
12root@debian:~/kvm# cat show_vnc_port_status.sh
#!/bin/bash
grep 'graphics.*vnc' /etc/libvirt/qemu/*.xml | awk -F ": " '{print $2, $1}'| sort
root@debian:~/kvm#
root@debian:~/kvm# ./show_vnc_port_status.sh
<graphics type='vnc' port='5920' autoport='no' listen='0.0.0.0'> /etc/libvirt/qemu/win10_21H2.xml
<graphics type='vnc' port='5921' autoport='no' listen='0.0.0.0'> /etc/libvirt/qemu/koolshare.xml
<graphics type='vnc' port='5922' autoport='no' listen='0.0.0.0'> /etc/libvirt/qemu/blog.xml
root@debian:~/kvm#
root@debian:~/kvm#
root@debian:~/kvm#
重新定义一个 XML文件1
2
3
4
5
6
7
8root@debian:~/kvm# cat redefine
NAME="win10_21H2"
virsh destroy ${NAME}
virsh define /etc/libvirt/qemu/${win10_21H2}.xml
virsh start ${win10_21H2}
root@debian:~/kvm#
全新安装
Debian 11
1 |
|
Linux Console 控制台模板
1 |
|
Windows 10
建议安装专业版,企业版的管理功能用不上反而是累赘,消耗CPU资源.1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31root@debian:~/kvm# cat kvm_install_win10_21H2.sh
#!/bin/bash
OS_DOMAIN='win10_21H2'
OS_DISK="/home/OS_Disk_Image/${OS_DOMAIN}.disk"
OS_IMG_DIR='/mnt/data/08_各种镜像/OS_windows/'
virsh destroy $OS_DOMAIN > /dev/null 2>&1
virsh undefine $OS_DOMAIN > /dev/null 2>&1
rm -rf $OS_DISK
rm -rf /var/log/libvirt/qemu/${OS_DOMAIN}.log
rm -rf /etc/libvirt/storage
virt-install \
--virt-type=kvm \
--os-type=windows \
--os-variant=win10 \
--name ${OS_DOMAIN} \
--cpu=host-passthrough \
--accelerate \
--autostart \
--ram 4096 \
--noautoconsole \
--vcpus sockets=1,cores=2,threads=2 \
--network mac=12:34:56:78:90:A1,bridge=br0,model=virtio \
--graphics vnc,listen=0.0.0.0,port=5920,password=chunli \
--disk path=${OS_DISK},size=80,format=raw,bus=virtio \
--disk path=${OS_IMG_DIR}/virtio-win/virtio-win-0.1.190_amd64.vfd,device=floppy \
--cdrom ${OS_IMG_DIR}/windows_10_2111/zh-cn_windows_10_business_editions_version_21h2_x64_dvd_93b4cb1a.iso \
root@debian:~/kvm#
windows_10 模板:
1 |
|
windows 模板
兼容 CentOS Debian
1 |
|
win10 模板
经过测试对比, Windows10版本中 1709空闲时占用CPU最低, 1809占用CPU最高, 1903,LTSC 约30%
#VNC 也可以不设定密码1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17virt-install \
--name win10_1709 \
--ram 4096 \
--os-type=windows \
--os-variant=win10 \
--virt-type=kvm \
--accelerate \
--autostart \
--noautoconsole \
--cpu=host \
--vcpus sockets=1,cores=2,threads=2 \
--graphics vnc,listen=0.0.0.0,port=5920 \
--boot cdrom \
--network bridge=br0,model=virtio \
--disk path=/home/OS_Disk_Image/win10_1709.disk,size=80,format=raw,bus=virtio \
--disk path=/mnt/data/08_各种镜像/OS_windows/virtio-win-0.1.126_amd64.vfd,device=floppy \
--disk path=/mnt/data/08_各种镜像/OS_windows/windows_10_1709/cn_windows_10_multi-edition_version_1709_updated_dec_2017_x64_dvd_100406696.iso,device=cdrom \
镜像导入
koolshare
1 |
|
软路由模板1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29[root@dell ~]# cat install_kvm_mikrotik.sh
name=mikrotik
RAM=256
ostype=linux
osvariant=centos7.0
virsh destroy mikrotik
sleep 1
virsh undefine mikrotik
rm -rf /home/OS_Disk_Image/${name}.disk
virt-install \
--name $name \
--os-type=$ostype \
--os-variant=$osvariant \
--accelerate \
--autostart \
--hvm \
--ram $RAM \
--cpu=host \
--vcpus sockets=1,cores=2,threads=1 \
--network bridge=br0,model=virtio \
--network bridge=br1,model=virtio \
--graphics vnc,listen=0.0.0.0,port=5928,password=chunli \
--noautoconsol \
--cdrom=/home/OS_Disk_Image/mikrotik-6.44.6.iso \
--disk path=/home/OS_Disk_Image/${name}.disk,size=1,format=raw,bus=ide
[root@dell ~]#