Administrator
发布于 2025-02-07 / 6 阅读
0
0

KVM

使用计算节点制作镜像、创建虚机

qemu-img create -f qcow2 win.qcow2 200G ####创建磁盘

virt-install --virt-type=kvm --name 1206 --vcpus=4 --memory=8192 --cdrom=/root/CentOS-7-x86_64-DVD-2009.iso --disk path=/home/songxu/win.qcow2,size=200,format=qcow2 --network=bridge:br-bond0,virtualport_type=openvswitch,model=virtio --vnc --vnclisten=0.0.0.0 --vncport=6000 --clock offset=utc --force --boot=hd ####创建linux虚机

virt-install --virt-type=kvm --name 1206 --vcpus=4 --memory=8192 --cdrom=/root/20348.1787.230607-0640.fe_release_svc_refresh_SERVER_EVAL_x64FRE_zh-cn.iso --disk path=/home/songxu/win.qcow2,size=200,format=qcow2 --network=bridge:br-bond0,virtualport_type=openvswitch,model=virtio --vnc --vnclisten=0.0.0.0 --vncport=6000 --clock offset=utc --force --boot=hd ####创建windows虚机

kvm压缩镜像 qemu-img convert -c -O qcow2 win.qcow2 /root/windows_server_2022_cn_x64.qcow2

给kvm虚机增加宿主机上的物理磁盘

</disk>

<disk type='block' device='disk'>

<driver name='qemu' type='raw' cache='none' io='native'/>

<source dev='/dev/sdb'/>

<target dev='vdd' bus='sata'/> <address type='drive' controller='0' bus='0' target='0' unit='3'/>

</disk>

重置kvm虚机root密码

安装工具 // 安装虚拟机客户端管理工具,这个一般在kvm的机器上都有安装,检查没有的话就安装一个

rpm -qa | grep libguestfs-tools

// 安装

yum install libguestfs-tools

生成新密码

# openssl是一个加密工具,-1 是指普通加密,

# hello为key , 123456 才是密码,

# 下面就是是生成的密码串,这样我们只要将这些进行对应的替换就可以了

openssl passwd -1 -salt 'hello' '123456'

$1$hello$ZwmhCpcG.I1XIfVjdarKc1

替换虚拟机的账号密码

// 查看当前机器所有的虚拟机 virsh list --all

// 关闭对应的虚拟机 dameng-8-65

virsh shutdown dameng-8-65

virsh destroy dameng-8-65 # destory 相对于shutdown更暴力,相当于直接关电源

// 编辑虚拟机的shadow 账号密码文件

virt-edit -d dameng-8-65 /etc/shadow

// 这里以修改root密码为例

root:$1$bTPRDWwf$LpjUZmGTHw.hYFccl0/lK.:16804:0:99999:7:::

更换为

root:$1$hello$ZwmhCpcG.I1XIfVjdarKc1:16541:0:99999:7:::

// 更换后重启虚拟机

virsh start dameng-8-65

// 测试登陆,43是virsh list --all查看虚拟机,dameng-8-65对应的id号码

virsh console 43


评论