一、pve 创建的虚拟机的配置文件位置
在宿主机的 /etc/pve/qemu-server,这里有创建虚拟机的相关硬件信息。
root@pve:~# cd /etc/pve/qemu-server
root@pve:/etc/pve/qemu-server# ls
100.conf
root@pve:/etc/pve/qemu-server# cat 100.conf
boot: order=scsi0;ide2;net0
cores: 4
ide2: local:iso/CentOS-7-x86_64-DVD-1810.iso,media=cdrom
memory: 3000
meta: creation-qemu=6.1.0,ctime=1646882614
name: centos
net0: virtio=9A:63:A6:89:78:1F,bridge=vmbr0
numa: 0
ostype: l26
scsi0: local-lvm:vm-100-disk-0,size=160G
scsihw: virtio-scsi-pci
smbios1: uuid=cf3f6ca9-c67e-4178-a5fe-afebf109bda0
sockets: 1
vmgenid: addf421d-f238-4017-ac9f-555095988afc
二、虚拟机直通硬盘
为什么需要直通,因为如果先挂载到 pve 宿主机上,然后创建对应的存储不太方便使用。
1、格式化
…
2、查看硬盘的序列号
root@pve:~# ls /dev/disk/by-id
ata-Colorful_SL500_256GB_2021052502522 dm-name-pve-vm--100--disk--0
ata-Colorful_SL500_256GB_2021052502522-part1 dm-uuid-LVM-NYT0y1xTuNdSzEDAzMne2RhZy3E7c5npmfc26jiMSd4q9HSbnMx40WX4kUot4D8v
ata-Colorful_SL500_256GB_2021052502522-part2 dm-uuid-LVM-NYT0y1xTuNdSzEDAzMne2RhZy3E7c5npn95kHgLgEAiyfR7xGemY4tYlLlT2EpX6
ata-Colorful_SL500_256GB_2021052502522-part3 dm-uuid-LVM-NYT0y1xTuNdSzEDAzMne2RhZy3E7c5npY212Dh66Tj3kSITEgBfYxGUV1Qnw3V1i
ata-ST500LT012-1DG142_WBY9Q8MV lvm-pv-uuid-tzLBex-gdHZ-zy8X-D21i-auOC-XEAo-6kRWs8
ata-ST500LT012-1DG142_WBY9Q8MV-part1 wwn-0x5000c500a92bbf03
dm-name-pve-root wwn-0x5000c500a92bbf03-part1
dm-name-pve-swap
通过硬盘插拔,得到硬盘序列号是 ata-ST500LT012-1DG142_WBY9Q8MV,创建了一个分区 ata-ST500LT012-1DG142_WBY9Q8MV-part1 。
3、给虚拟机分配硬盘
# 以 100 为例
root@pve:~# qm set 100 -sata3 /dev/disk/by-id/ata-ST500LT012-1DG142_WBY9Q8MV
update VM 100: -sata3 /dev/disk/by-id/ata-ST500LT012-1DG142_WBY9Q8MV# 重启
root@pve:~# qm reboot 100 # 查看是否配置成功
root@pve:~# cat /etc/pve/qemu-server/100.conf | grep /dev/disk/by-id/ata-ST500LT012-1DG142_WBY9Q8MV
sata3: /dev/disk/by-id/ata-ST500LT012-1DG142_WBY9Q8MV,size=500107861504
可以看见已经挂载完成
4、挂载
进入虚拟机 100
[root@localhost ~]# ls -al /dev/disk/by-id/
总用量 0
drwxr-xr-x. 2 root root 300 4月 27 15:22 .
drwxr-xr-x. 7 root root 140 4月 27 15:22 ..
lrwxrwxrwx. 1 root root 9 4月 27 15:22 ata-QEMU_DVD-ROM_QM00003 -> ../../sr0
lrwxrwxrwx. 1 root root 9 4月 27 15:22 ata-QEMU_HARDDISK_QM00011 -> ../../sda
lrwxrwxrwx. 1 root root 10 4月 27 15:22 ata-QEMU_HARDDISK_QM00011-part1 -> ../../sda1
lrwxrwxrwx. 1 root root 10 4月 27 15:22 dm-name-centos-home -> ../../dm-2
lrwxrwxrwx. 1 root root 10 4月 27 15:22 dm-name-centos-root -> ../../dm-0
lrwxrwxrwx. 1 root root 10 4月 27 15:22 dm-name-centos-swap -> ../../dm-1
lrwxrwxrwx. 1 root root 10 4月 27 15:22 dm-uuid-LVM-Hrp1uyQApzTHE1HNTvoaCwzryr2lhsXD1SiqqkOodJtb8heLnwObvSBwpXFBS0z1 -> ../../dm-2
lrwxrwxrwx. 1 root root 10 4月 27 15:22 dm-uuid-LVM-Hrp1uyQApzTHE1HNTvoaCwzryr2lhsXDjDkr8ARrOJCZLrvt3f5TNFQoFYOSbI7B -> ../../dm-0
lrwxrwxrwx. 1 root root 10 4月 27 15:22 dm-uuid-LVM-Hrp1uyQApzTHE1HNTvoaCwzryr2lhsXDwtcde6xhTT2Y4cPco50buZWjpN9AAfIr -> ../../dm-1
lrwxrwxrwx. 1 root root 10 4月 27 15:22 lvm-pv-uuid-UM20NL-oY1F-KAkK-54oM-Xhbx-w0RY-iPxPgQ -> ../../sdb2
lrwxrwxrwx. 1 root root 9 4月 27 15:22 scsi-0QEMU_QEMU_HARDDISK_drive-scsi0 -> ../../sdb
lrwxrwxrwx. 1 root root 10 4月 27 15:22 scsi-0QEMU_QEMU_HARDDISK_drive-scsi0-part1 -> ../../sdb1
lrwxrwxrwx. 1 root root 10 4月 27 15:22 scsi-0QEMU_QEMU_HARDDISK_drive-scsi0-part2 -> ../../sdb2
[root@localhost ~]#
可以看见需要挂载的设备为ata-QEMU_HARDDISK_QM00011-part1 (之前我只创建了一个分区)即/dev/disk/by-id/ata-QEMU_HARDDISK_QM00011-part1
# 挂载
[root@localhost ~]# mount /dev/disk/by-id/ata-QEMU_HARDDISK_QM00011-part1 /mnt/sdb1/
[root@localhost ~]# ls /mnt/sdb1/
lost+found# 开机自动挂载
[root@localhost ~]# echo "/dev/disk/by-id/ata-QEMU_HARDDISK_QM00011-part1 /mnt/sdb1/ ext4 defaults 0 0" >> /etc/fstab
到这里就完成了。
挂载完后不能创建快照