上传 iso 到宿主机
ls -l /data1/iso/
total 4422912
-rw-r--r-- 1 root root 1774077952 Jan 22 08:51 ctyunos-2.0.1-210625-x86_64-dvd.iso
-rw-r--r-- 1 root root 2754981888 May 7 2024 ubuntu-24.04-live-server-amd64.iso
创建虚拟磁盘(可选)
创建 qcow2 文件
qemu-img create -f qcow2 /data/ctyunos/ctyun-01_system.qcow2 20G
Formatting '/data/ctyunos/ctyun-01_system.qcow2', fmt=qcow2 size=21474836480 cluster_size=65536 lazy_refcounts=off refcount_bits=16
查看 qcow2 文件大小
ls -lh /data/ctyunos/ctyun-01_system.qcow2
-rw-r--r-- 1 root root 193K Jan 24 15:46 /data/ctyunos/ctyun-01_system.qcow2
查看支持的系统版本
osinfo-query os | grep centos
centos6.0 | CentOS 6.0 | 6.0 | http://centos.org/centos/6.0 centos6.1 | CentOS 6.1 | 6.1 | http://centos.org/centos/6.1 centos6.2 | CentOS 6.2 | 6.2 | http://centos.org/centos/6.2 centos6.3 | CentOS 6.3 | 6.3 | http://centos.org/centos/6.3 centos6.4 | CentOS 6.4 | 6.4 | http://centos.org/centos/6.4 centos6.5 | CentOS 6.5 | 6.5 | http://centos.org/centos/6.5 centos6.6 | CentOS 6.6 | 6.6 | http://centos.org/centos/6.6 centos6.7 | CentOS 6.7 | 6.7 | http://centos.org/centos/6.7 centos6.8 | CentOS 6.8 | 6.8 | http://centos.org/centos/6.8 centos6.9 | CentOS 6.9 | 6.9 | http://centos.org/centos/6.9 centos7.0 | CentOS 7.0 | 7.0 | http://centos.org/centos/7.0
根据 iso 创建虚拟机
事前创建磁盘文件
virt-install \--name ctyun-2.0.1-01 \--ram 2048 \--vcpus 2 \--virt-type kvm \--os-variant=generic \--description ctyun-2.0.1-01 \--network bridge=CN1,model=virtio \--network bridge=CN2,model=virtio \--graphics vnc,listen=0.0.0.0 \--disk path=/data/ctyunos/ctyun-01_system.qcow2,format=qcow2,bus=virtio \--disk path=/data/ctyunos/ctyun-01_data.qcow2,format=qcow2,size=20,bus=virtio \--cdrom=/data/iso/ctyunos-2.0.1-220311-x86_64-dvd.iso \--noautoconsole \--channel unix,path=/var/lib/libvirt/qemu/ctyun-2.0.1-01.agent,mode=bind,target_type=virtio,name=org.qemu.guest_agent.0 \--console pty,target_type=serial \--autostart
Starting install...
Allocating 'ctyun-01_data.qcow2' | 20 GB 00:00:00
Domain installation still in progress. You can reconnect to
the console to complete the installation process.
无需事先创建磁盘文件
virt-install \--name ctyun-2.0.1-01 \--ram 2048 \--vcpus 2 \--virt-type kvm \--os-variant=generic \--description ctyun-2.0.1-01 \--network bridge=CN1,model=virtio \--network bridge=CN2,model=virtio \--graphics vnc,listen=0.0.0.0 \--disk path=/data/ctyunos/ctyun-01_system.qcow2,size=10,format=qcow2,bus=virtio \--disk path=/data/ctyunos/ctyun-01_data.qcow2,size=20,format=qcow2,bus=virtio \--cdrom=/data/iso/ctyunos-2.0.1-220311-x86_64-dvd.iso \--noautoconsole \--channel unix,path=/var/lib/libvirt/qemu/ctyun-2.0.1-01.agent,mode=bind,target_type=virtio,name=org.qemu.guest_agent.0 \--console pty,target_type=serial \--autostart
Starting install...
Allocating 'ctyun-01_system.qcow2' | 10 GB 00:00:00
Allocating 'ctyun-01_data.qcow2' | 20 GB 00:00:00
Domain installation still in progress. You can reconnect to
the console to complete the installation process.
查看虚机 ID
virsh list --all
Id Name State
-----------------------------1 ctyun-2.0.1-01 running
查看虚机 VNC 信息
virsh vncdisplay 1
:0
通过 VNC 连接
安装过程 。。。。
虚拟机开启
virsh start ctyun-2.0.1-01
Domain ctyun-2.0.1-01 started
查看虚拟机网卡信息
ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00inet 127.0.0.1/8 scope host lovalid_lft forever preferred_lft foreverinet6 ::1/128 scope host valid_lft forever preferred_lft forever
2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000link/ether 52:54:00:de:1f:fe brd ff:ff:ff:ff:ff:ffinet 192.168.80.138/24 brd 192.168.80.255 scope global dynamic noprefixroute ens3valid_lft 1757sec preferred_lft 1757secinet6 fe80::de9:e2c7:769d:93ed/64 scope link noprefixroute valid_lft forever preferred_lft forever
3: ens4: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000link/ether 52:54:00:26:0d:d5 brd ff:ff:ff:ff:ff:ffinet 192.168.174.124/24 brd 192.168.174.255 scope global dynamic noprefixroute ens4valid_lft 1758sec preferred_lft 1758secinet6 fe80::f02a:ae03:bb7d:2e96/64 scope link noprefixroute valid_lft forever preferred_lft forever
查看虚拟机磁盘信息
fdisk -l
Disk /dev/vda: 10 GiB, 10737418240 bytes, 20971520 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x31741cc3Device Boot Start End Sectors Size Id Type
/dev/vda1 * 2048 2099199 2097152 1G 83 Linux
/dev/vda2 2099200 20971519 18872320 9G 8e Linux LVMDisk /dev/vdb: 20 GiB, 21474836480 bytes, 41943040 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/mapper/ctyunos-root: 7.102 GiB, 8585740288 bytes, 16769024 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/mapper/ctyunos-swap: 1 GiB, 1073741824 bytes, 2097152 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
查看宿主机网卡信息
ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00inet 127.0.0.1/8 scope host lovalid_lft forever preferred_lft foreverinet6 ::1/128 scope host valid_lft forever preferred_lft forever
2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq master CN2 state UP group default qlen 1000link/ether 00:0c:29:2f:c1:1a brd ff:ff:ff:ff:ff:ff
3: ens192: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq master CN1 state UP group default qlen 1000link/ether 00:0c:29:2f:c1:24 brd ff:ff:ff:ff:ff:ff
4: CN2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000link/ether 00:0c:29:2f:c1:1a brd ff:ff:ff:ff:ff:ffinet 192.168.174.123/24 brd 192.168.174.255 scope global noprefixroute CN2valid_lft forever preferred_lft foreverinet6 fe80::51c3:93b:274:6372/64 scope link noprefixroute valid_lft forever preferred_lft forever
5: CN1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000link/ether 00:0c:29:2f:c1:24 brd ff:ff:ff:ff:ff:ffinet 192.168.80.137/24 brd 192.168.80.255 scope global noprefixroute CN1valid_lft forever preferred_lft foreverinet6 fe80::2392:17b5:d36:9ae/64 scope link noprefixroute valid_lft forever preferred_lft forever
6: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000link/ether 52:54:00:fe:8d:0f brd ff:ff:ff:ff:ff:ffinet 192.168.124.1/24 brd 192.168.124.255 scope global virbr0valid_lft forever preferred_lft forever
9: vnet0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master CN1 state UNKNOWN group default qlen 1000link/ether fe:54:00:de:1f:fe brd ff:ff:ff:ff:ff:ffinet6 fe80::fc54:ff:fede:1ffe/64 scope link valid_lft forever preferred_lft forever
10: vnet1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master CN2 state UNKNOWN group default qlen 1000link/ether fe:54:00:26:0d:d5 brd ff:ff:ff:ff:ff:ffinet6 fe80::fc54:ff:fe26:dd5/64 scope link valid_lft forever preferred_lft forever
查看网桥信息
brctl show
bridge name bridge id STP enabled interfaces
CN1 8000.000c292fc124 yes ens192vnet0
CN2 8000.000c292fc11a yes ens160vnet1
virbr0 8000.525400fe8d0f yes