磁盘管理常用命令
qemu-img info centos1.1.raw # 查看具体信息
qemu-img create -f qcow2 /opt/vm_hfr.qcow2 2G #创建磁盘
qemu-img resize vm_hfr.qcow2 +2G # 扩容 --> +2G(在原基础上增加2G)
qemu-img resize vm_hfr.qcow2 6G # -->+6G(到6G)
qemu-img convert -f raw -O qcow2 centos1.1.raw centos1.1.qcow2 # 格式转换
virsh edit centos1 # 修改磁盘类型 raw-->qcow2
virsh snapshot-create centos1 # 创建快照
dd if=/dev/zero of=centos1.raw bs=200M count=1 # 测试内存
快照管理
mkfs.xfs /opt/centos1.raw #格式化
mount /opt/centos1.raw /srv #挂载
df -h
挂载虚拟机磁盘文件
fdisk /opt/centos1.1.raw
Command (m for help): p
Disk /opt/centos1.1.raw: 10.7 GB, 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
Disk label type: dos
Disk identifier: 0x000adf13
Device Boot Start End Blocks Id System
/opt/centos1.1.raw1 * 2048 2099199 1048576 83 Linux
echo $((2048*512)) # 计算偏移量
mount -o loop,offset=1048576 /opt/centos1.1.raw /srv
chroot /srv #更改root目录
passwd # 修改密码
快照常用命令
[root@kvm02 opt]# virsh snapshot-list centos1
Name Creation Time State
------------------------------------------------------------
1652621582 # (unix时间戳) 2022-05-15 09:33:02 -0400 running
1653123386 2022-05-21 04:56:26 -0400 shutoff
> https://tool.lu/timestamp/
# unix时间戳网址
virsh snapshot-create-as centos1 --name vm_01 # 创建快照并别名
virsh snapshot-delete centos1 --snapshotname 1652621582 # 删除快照
virsh snapshot-revert centos1 --snapshotname vm_01 # 恢复快照
[root@kvm02 opt]# qemu-img info centos1.1.qcow2 # 快照保存的位置
image: centos1.1.qcow2
file format: qcow2
virtual size: 10G (10737418240 bytes)
disk size: 2.5G
cluster_size: 65536
Snapshot list:
ID TAG VM SIZE DATE VM CLOCK
3 vm_01 258M 2022-05-21 05:31:51 00:00:54.301
Format specific information:
compat: 1.1
lazy refcounts: false
补充
虚拟机操作
ssh root@192.168.122.34
grubby --update-kernel=ALL --args="console=ttyS0,115200n8"
reboot
物理机操作
virsh console centos1
使用qaq修改虚拟机的密码
虚拟机操作
yum install qemu-guest-agent
systemctl start qemu-guest-agent
systemctl enable qemu-guest-agent
物理机操作
ssh root@192.168.122.34
echo 'adadasdadsa' | passwd -stdin root # 随机设置一个密码
virsh set-user-password --user root --password 654321 centos1 # 设置密码
> 前提:(需要保证虚拟机的qemu-guest-agent的服务是启动的)