PVE

https://www.proxmox.com/en/downloads

pvetools
https://github.com/ivanhao/pvetools

#SSH登陆LXC容器的Debian11慢
选项-签名-嵌套✓

导入磁盘到虚拟机
qm importdisk 101 arpl.img local-lvm
qm importdisk 101 /root/openwrt-x86-64-generic-squashfs-combined-efi.img local

PVE设置定时关闭、启动虚拟机
shell中输入命令:
crontab -e

00 2 * * * pvesh create /nodes/pve/qemu/102/status/stop
00 6 * * * pvesh create /nodes/pve/qemu/102/status/start

其中pve为节点名称,102为虚拟机编号。

#合并local、local-lvm空间
1、备份虚拟机
2、删除虚拟机
3、删除local-lvm
命令:lvremove pve/data
4、把local-lvm空间分配给Local
命令:lvextend -l +100%FREE -r pve/root
5、删除local-lvm
数据中心-存储-删除local-lvm
6、编辑local,内容里添加 磁盘映像和容器
7、恢复虚拟机

#添加E1000e网卡

1.编辑/usr/share/perl5/PVE/QemuServer.pm
my $nic_model_list = ['rtl8139', 'ne2k_pci', 'e1000', 'pcnet', 'virtio','ne2k_isa', 'i82551', 'i82557b', 'i82559er', 'vmxnet3','e1000-82540em', 'e1000-82544gc', 'e1000-82545em'];
改为:
my $nic_model_list = ['rtl8139', 'ne2k_pci', 'e1000', 'e1000e', 'pcnet', 'virtio','ne2k_isa', 'i82551', 'i82557b', 'i82559er', 'vmxnet3','e1000-82540em', 'e1000-82544gc', 'e1000-82545em'];

2.编辑/usr/share/pve-manager/js/pvemanagerlib.js
if ((match_res = p.match(/^(ne2k_pci|e1000|e1000-82540em|e1000-82544gc|e1000-82545em|vmxnet3|rtl8139|pcnet|virtio|ne2k_isa|i82551|i82557b|i82559er)(=([0-9a-f]{2}(:[0-9a-f]{2}){5}))?$/i)) !== null) {
改为:
if ((match_res = p.match(/^(ne2k_pci|e1000|e1000e|e1000-82540em|e1000-82544gc|e1000-82545em|vmxnet3|rtl8139|pcnet|virtio|ne2k_isa|i82551|i82557b|i82559er)(=([0-9a-f]{2}(:[0-9a-f]{2}){5}))?$/i)) !== null) {

['e1000', 'Intel E1000'],
['virtio', 'VirtIO (' + gettext('paravirtualized') + ')'],
['rtl8139', 'Realtek RTL8139'],
['vmxnet3', 'VMware vmxnet3']
]
改为:
['e1000', 'Intel E1000'],
['e1000e', 'Intel E1000e'],
['virtio', 'VirtIO (' + gettext('paravirtualized') + ')'],
['rtl8139', 'Realtek RTL8139'],
['vmxnet3', 'VMware vmxnet3']
]

#硬件直通
nano /etc/default/grub

GRUB_CMDLINE_LINUX_DEFAULT="quiet"
改为:
GRUB_CMDLINE_LINUX_DEFAULT="quiet intel_iommu=on"

update-grub
dmesg | grep -e DMAR -e IOMMU

nano /etc/modules
添加:
vfio
vfio_iommu_type1
vfio_pci
vfio_virqfd

update-initramfs -u -k all

dmesg | grep 'remapping'
find /sys/kernel/iommu_groups/ -type l

#intel核显直通
vim /etc/default/grub

GRUB_CMDLINE_LINUX_DEFAULT="quiet"
改为:
GRUB_CMDLINE_LINUX_DEFAULT="quiet intel_iommu=on video=efifb:off"

update-grub
dmesg | grep -e DMAR -e IOMMU

vim /etc/modules
添加:
vfio
vfio_iommu_type1
vfio_pci
vfio_virqfd

vim /etc/modprobe.d/pve-blacklist.conf
添加:
blacklist snd_hda_intel
blacklist snd_hda_codec_hdmi
blacklist i915

#查看核显和声卡ID
lspci
00:02.0 VGA compatible controller: Intel Corporation Device 5a85 (rev 0b)
00:0e.0 Audio device: Intel Corporation Atom/Celeron/Pentium Processor N4200/N3350/E3900 Series Audio Cluster (rev 0b)
#查询对应ID
lspci -n -s 00:02
lspci -n -s 00:0e
00:02.0 0300: 8086:5a85 (rev 0b)
00:0e.0 0403: 8086:5a98 (rev 0b)

#添加直通组,多个设备用“,”号隔开
vim /etc/modprobe.d/vfio.conf
添加:
options vfio-pci ids=8086:5a85,8086:5a98

#添加options防止VM死机
vim /etc/modprobe.d/kvm.conf
添加:
options kvm ignore_msrs=1

update-initramfs -u
lsmod | grep vfio

dmesg | grep 'remapping'
find /sys/kernel/iommu_groups/ -type l

#硬盘软直通
ls /dev/disk/by-id
qm set 100 -sata1 /dev/disk/by-id/ata-SanDisk_SDSSDHP128G_144410401660

ls -la /dev/disk/by-id/|grep -v dm|grep -v lvm|grep -v part
qm set <vmid> --scsi[x] /dev/disk/by-id/[xxxxxxx]

#更新PVE提示错误:command 'apt-get update' failed: exit code 100
修改 /etc/apt/sources.list /etc/apt/sources.list
改为:
deb http://ftp.debian.org/debian buster main contrib
deb http://ftp.debian.org/debian buster-updates main contrib
# PVE pve-no-subscription repository provided by proxmox.com,
# NOT recommended for production use
deb http://download.proxmox.com/debian/pve buster pve-no-subscription
# security updates
deb http://security.debian.org buster/updates main contrib

注释 /etc/apt/sources.list.d/pve-enterprise.list 中的源
改为:
# deb https://enterprise.proxmox.com/debian/pve buster pve-enterprise

执行更新:
apt update

#锐角云PVE下开启VT-D - https://github.com/Cyberpunk2177/AcuteAngle/blob/master/enable-vt-d-auto.md
1.将 setup_var.mod 复制到 /boot/grub/x86_64-efi/
2.修改 /etc/grub.d/00_header
echo -e 'echo "insmod setup_var"\necho "setup_var_3 0x49 0x01"' >> /etc/grub.d/00_header
3.修改 /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="quiet intel_iommu=on"
4.生成新的 grub 配置
update-grub
5.重启两次, 检查是否启用成功
root@pve:~# dmesg |grep DMAR
[    0.013559] ACPI: DMAR 0x0000000079AB7820 0000A8 (v01 INTEL  EDK2     00000003 BRXT 0100000D)
[    0.013695] ACPI: Reserving DMAR table memory at [mem 0x79ab7820-0x79ab78c7]
[    0.058291] DMAR: IOMMU enabled
[    0.204229] DMAR: Host address width 39
[    0.204233] DMAR: DRHD base: 0x000000fed64000 flags: 0x0
[    0.204251] DMAR: dmar0: reg_base_addr fed64000 ver 1:0 cap 1c0000c40660462 ecap 7e3ff0505e
[    0.204259] DMAR: DRHD base: 0x000000fed65000 flags: 0x1
[    0.204273] DMAR: dmar1: reg_base_addr fed65000 ver 1:0 cap d2008c40660462 ecap f050da
[    0.204281] DMAR: RMRR base: 0x00000079a32000 end: 0x00000079a51fff
[    0.204286] DMAR: RMRR base: 0x0000007b800000 end: 0x0000007fffffff
[    0.204293] DMAR-IR: IOAPIC id 1 under DRHD base  0xfed65000 IOMMU 1
[    0.204297] DMAR-IR: HPET id 0 under DRHD base 0xfed65000
[    0.204302] DMAR-IR: Queued invalidation will be enabled to support x2apic and Intr-remapping.
[    0.206605] DMAR-IR: Enabled IRQ remapping in x2apic mode
[    2.988101] DMAR: No ATSR found
[    2.988107] DMAR: dmar0: Using Queued invalidation
[    2.988119] DMAR: dmar1: Using Queued invalidation
[    2.994505] DMAR: Intel(R) Virtualization Technology for Directed I/O
这样就是成功了,如果只有一行
[    0.058291] DMAR: IOMMU enabled
说明没有成功,可以再重启一次试试。

#PVE删除自带swap并重新创建swap
#关闭swap
vim /etc/fstab
/dev/pve/swap none swap sw 0 0 #注释掉这句

free #重启后查看swap是否为0
lvremove /dev/pve/swap #删除pve-swap

lvextend -L +7G /dev/mapper/pve-root #剩下空间随意分配,这里是分配给了pve-root

#创建新的swap
dd if=/dev/sdb of=/swap bs=1024M count=15
mkswap /swap #建立swap文件
swapon /swap #启用swap文件

free

#开机自动挂载
vi /etc/fstab
/swap none swap sw 0 0 #修改成这样就可以了