0%

找到磁盘

1
lsblk -f

磁盘分区

这里只解释用单独硬盘打分区(UEFI+GPT

我们选择 2 个分区,

  1. fat16 为 esp
  2. ext4 为 系统
1
2
3
4
5
6
7
8
9
10
11
lsblk  # 查看硬盘
fdisk /dev/sda # sda是需要甄别的,我的安装硬盘就是 sda
# 这里会提示操作 输入
n #回车
#回车
+300M # 回车 这里是分区的大小
#输入
n #回车
#回车
#回车
w #保存

分区还是很简单的,下面是格式化

1
2
mkfs.ext4 /dev/sda1  # 多次回车就可以啦
lsblk -f # 查询全部池畔的格式

重启自动挂载

1
2
3
4
mkdir /mnt/data
echo "/dev/sda1 /mnt/data ext4 defaults 0 0" >> /etc/fstab
mount -a
df -h

pve备份

本文地址: https://github.com/maxzhao-it/blog/post/53db8c2/

硬盘直通下,配置多少内存,虚拟机就会占用多少内存

找到磁盘

1
2
3
ls -l /dev/disk/by-id/
# 给电脑增加磁盘
qm set 100 -sata3 /dev/disk/by-id/ata-*****

成功后会输出

1
update VM 100:-sata3  /dev/disk/by-id/ata-*****

查询

1
grep ata /etc/pve/qemu-server/100.conf

有会输出

1
sata3: /dev/disk/by-id/ata-*****

重启虚拟机

删除

1
qm set 101 -delete sata3

本文地址: https://github.com/maxzhao-it/blog/post/e43b11ec/

mv /etc/apt/sources.list.d/pve-enterprise.list /etc/apt/sources.list.d/pve-enterprise.list-bak

Proxmox软件源更换

echo “deb https://mirrors.ustc.edu.cn/proxmox/debian/pve bookworm pve-no-subscription” > /etc/apt/sources.list.d/pve-no-subscription.list
apt update && apt dist-upgrade #更新软件,可不执行

Debian系统源更换

sed -i.bak “s#http://ftp.debian.org#https://repo.huaweicloud.com#g" /etc/apt/sources.list #华为Debian源
sed -i “s#http://security.debian.org#https://repo.huaweicloud.com/debian-security#g" /etc/apt/sources.list #华为Debian源
apt update && apt-get install -y apt-transport-https ca-certificates –fix-missing

LXC仓库源更换

sed -i.bak “s#http://download.proxmox.com/images#https://mirrors.ustc.edu.cn/proxmox/images#g" /usr/share/perl5/PVE/APLInfo.pm
wget -O /var/lib/pve-manager/apl-info/mirrors.ustc.edu.cn https://mirrors.ustc.edu.cn/proxmox/images/aplinfo-pve-7.dat
systemctl restart pvedaemon

CEPH源更换

echo “deb https://mirrors.ustc.edu.cn/proxmox/debian/ceph-quincy bookworm no-subscription” > /etc/apt/sources.list.d/ceph.list #中科大源
sed -i.bak “s#http://download.proxmox.com/debian#https://mirrors.ustc.edu.cn/proxmox/debian#g" /usr/share/perl5/PVE/CLI/pveceph.pm #中科大源

删除订阅弹窗
sed -Ezi.bak “s/(Ext.Msg.show({\s+title: gettext(‘No valid sub)/void({ //\1/g” /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js && systemctl restart pveproxy.service
执行完成后,浏览器Ctrl+F5强制刷新缓存

安装常用依赖

apt install -y vim net-tools
apt install -y gcc

磁盘扩容:

lvscan 发现 /dev/pve/data 是有空间的
lvextend -l +100%FREE -r pve/root

本文地址: https://github.com/maxzhao-it/blog/post/1226ea39/

vim /etc/sysctl.conf

在末尾添加

net.ipv6.conf.all.accept_ra=2
net.ipv6.conf.default.accept_ra=2
net.ipv6.conf.vmbr0.accept_ra=2
net.ipv6.conf.all.autoconf=1
net.ipv6.conf.default.autoconf=1
net.ipv6.conf.vmbr0.autoconf=1

然后执行sysctl -p或者重启主机

输入

apt-get install net-tools -y
ifconfig

本文地址: https://github.com/maxzhao-it/blog/post/dcf1ae8e/

显卡声卡

IOMMU支持

vim /etc/default/grub

1
2
# GRUB_CMDLINE_LINUX_DEFAULT="quiet intel_iommu=on"
GRUB_CMDLINE_LINUX_DEFAULT="quiet intel_iommu=on iommu=pt video=vesafb:off video=efifb:off video=simplefb:off"

添加内核模块

vim /etc/modules

1
2
3
4
vfio
vfio_iommu_type1
vfio_pci
vfio_virqfd

禁用显卡

1
2
vim /etc/modprobe.d/pve-blacklist.conf

驱动内名单

1
2
3
4
5
6
7
8
9
10
# 独显
blacklist nouveau
blacklist nvidia
blacklist nvidiafb

# 核显
blacklist snd_hda_intel
blacklist snd_hda_codec_hdmi
blacklist i915

对应的虚拟机添加 硬件-添加-PCI设备-Raw Device

选择对应的选卡,设置主GPU,显示设置为

查询显卡和声卡

1
2
lspci -nn |grep VGA 
lspci -nn |grep Aud

最后的 8086:7ad0 是ID 10de:1c03,10de:10f1,8086:7ad0

加入直通

1
vim /etc/modprobe.d/vfio.conf
1
options vfio-pci ids=8086:7ad0,10de:10f1,10de:1c03

防止 VM 死机

vim /etc/modprobe.d/kvm.conf

1
options kvm ignore_msrs=1

更新内核

1
2
3
4
update-grub
update-initramfs -k all -u
# 重启
reboot

重启后查看

1
lsmod |grep vifo

配置核显输出

web界面配置

对应的虚拟机添加 硬件-添加-PCI设备-Raw Device

配置独显

添加pcie 选择 独显

Raw Device

主GPU 不要选
所有功能
PCI-Express

安装显卡驱动

方案二

/etc/modprobe.d/pve-blacklist.conf

里面只需要一个参数

1
options vfio_iommu_type1 allow_unsafe_interrupts=1

本文地址: https://github.com/maxzhao-it/blog/post/fecbe378/

无法关闭虚拟机

qm stop 101 # 编号

TASK ERROR: can’t lock file ‘/var/lock/qemu-server/lock-101.conf’ - received interrupt

rm /var/lock/qemu-server/lock-101.conf

开机进入 shell

执行 reset

系统光盘放在引导的第一位

swtpm_setup: Not overwriting existing state file.

kvm: -device ide-cd,bus=ide.0,unit=1,drive=drive-ide1,id=ide1,bootindex=102: Can’t create IDE unit 1, bus supports only 1 units
stopping swtpm instance (pid 6199) due to QEMU startup error
TASK ERROR: start failed: QEMU exited with code 1

使用机器类型q35时,只能使用ide0和ide2

ide0 = ventoy-1.0.96-livecd.iso
ide2 = zh-cn_windows_11_business_editions_version_22h2_updated_feb_2023_x64_dvd_632649a2.iso

安装无法识别硬盘(scsi 无法识别)

https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/

下载驱动 virtio-win-0.1.229.iso

挂载iso后,安装时加载驱动 vioscsi\w11\amd64

本文地址: https://github.com/maxzhao-it/blog/post/86a90e71/

分区

这里只解释用单独硬盘打分区(UEFI+GPT

我们选择 2 个分区,

  1. fat16 为 esp
  2. ext4 为 系统
1
2
3
4
5
6
7
8
9
10
11
lsblk  # 查看硬盘
fdisk /dev/sda # sda是需要甄别的,我的安装硬盘就是 sda
# 这里会提示操作 输入
n #回车
#回车
+300M # 回车 这里是分区的大小
#输入
n #回车
#回车
#回车
w #保存

分区还是很简单的,下面是格式化

1
2
3
mkfs.fat -F16 /dev/sda1 # sda 是上面我们使用的硬盘
mkfs.ext4 /dev/sda1 # 多次回车就可以啦
lsblk -f # 查询全部池畔的格式

挂载

1
2
3
4
mount /dev/sda1 /mnt  # sda 是上面我们使用的硬盘
mkdir -p /mnt/boot/EFI
mount /dev/sda1 /mnt/boot/EFI
lsblk #可以详细的看到我们的挂载位置

重启自动挂载

1
2
3
4
mkdir /mnt/data
echo "/dev/sda1 /mnt/data ext4 defaults 0 0" >> /etc/fstab
mount -a
df -h

本文地址: https://github.com/maxzhao-it/blog/post/21578818/

操作文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import os
import shutil
from datetime import datetime

dir = '/data'
file = '/data/1.txt'
# 创建单个目录
os.mkdir(dir)
# 创建多层目录
os.makedirs(dir + '/123')
# 复制文件
shutil.copyfile('old', 'new')
# 复制文件夹
shutil.copytree('olddir', 'newdir')
# 重命名文件或目录
os.rename('odl', 'new')
# 移动文件或目录
shutil.move('old', 'new')
# 删除空目录
os.rmdir(dir)
# 删除空目录
os.removedirs(dir)
# 获取路径下的所有文件
os.listdir(dir)
# 删除文件
os.remove(file)
# 判断是否存在
if os.path.exists(dir):
pass
# 判断是否文件
if os.path.isfile(file):
pass
# 判断是否目录
if os.path.isdir(dir):
pass
# 判断是否绝对路径
if os.path.isabs(dir):
pass
# 获取文件属性
os.stat(file)
# 文件大小
os.stat(file).st_size
os.path.getsize(file)
# 获取文件名
os.path.basename(filePath)
# 获取路径
os.path.dirname(filePath)
# 获取绝对路径
os.path.abspath(file)
# 获取文件的创建时间
fromtimestamp = datetime.fromtimestamp(int(os.path.getctime(filePath))).date()
print(str(fromtimestamp))

# 获取文件后缀
basename = os.path.basename(path) # 获取文件名
extension = os.path.splitext(basename)[1] # 获取文件后缀
# 排序
sorted(os.listdir(path))

本文地址: https://github.com/maxzhao-it/blog/post/cd61337e/

安装

1
2
3
pip install moviepy -i https://mirrors.aliyun.com/pypi/simple/
pip install pandas -i https://mirrors.aliyun.com/pypi/simple/
pip3 install pydub -i https://mirrors.aliyun.com/pypi/simple/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import threading
import time

from moviepy.editor import *

# 定义最大允许的线程数量
max_threads = 5
# 创建 Semaphore 对象
semaphore = threading.Semaphore(max_threads)


def asyncConcat(startPath, endPath, middlePath, middleAudioPath, outputPath, semaphore):
with semaphore:
concat(startPath, endPath, middlePath, middleAudioPath, outputPath)


def concat(startPath, endPath, middlePath, middleAudioPath, outputPath):
try:
start = VideoFileClip(startPath)
end = VideoFileClip(endPath)
middleVideo = VideoFileClip(middlePath)
middleAudio = AudioFileClip(middleAudioPath)
# 正文持续时间
print('持续时间=', middleVideo.duration)
# 音频长度剪切
middleAudio = middleAudio.set_duration(middleVideo.duration)
# 替换音频
middleVideo = middleVideo.set_audio(middleAudio)
# 分辨率
resolution = middleVideo.size
width, height = resolution
print('分辨率=', resolution)
print('分辨率:宽=', width, '高:', height)
# 等比例放大或缩小
start = start.resize(resolution)
end = end.resize(resolution)
# 上下
# resultClip = clips_array([[start], [middle], [end]])
# 左右
# resultClip = clips_array([[start, middle, end]])
# 前后
resultClip = concatenate_videoclips([start, middleVideo, end])
startTime = time.time()
basename = os.path.basename(middlePath)
basename = basename.replace('.', '-已剪辑.')
resultClip.write_videofile(outputPath + basename, threads=50)
print('剪辑使用时间:', time.time() - startTime)

except Exception as e:
print('计算视频失败:', e)


if __name__ == '__main__':
startPath = "D:\\00-自媒体计划\\AI-start.mp4"
endPath = "D:\\00-自媒体计划\\AI-end.mp4"
middleDir = "f:\\Videos\\4K Tokkit\\\dbxbqm22\\"
middlePath = "f:\\Videos\\4K Tokkit\\dbxbqm22\\7257911883674668289.mp4"
middleAudioPath = "D:\\00-自媒体计划\\AI-背景音乐.MP3"
outputPath = "f:\\Videos\\4K Tokkit\\test1\\"
if not outputPath.endswith('\\'):
outputPath = outputPath + '\\'
count = 1
fileCount = 0
startTime = time.time()
files = os.listdir(middleDir)
# 创建线程
threads = []
for file in files:
count = count + 1
basename = os.path.basename(file)
if '.mp4' not in basename:
continue
if '已剪辑' in basename:
continue
if os.path.exists(outputPath + basename.replace('.', '-已剪辑.')):
print('视频已剪辑=', middleDir + basename)
continue
print('待剪辑视频=', middleDir + basename)
fileCount = fileCount + 1
# concat(startPath, endPath, middleDir + basename, middleAudioPath, outputPath)
thread = threading.Thread(target=asyncConcat, args=(
startPath, endPath, middleDir + basename, middleAudioPath, outputPath, semaphore))
threads.append(thread)
thread.start()
# 等待所有线程执行结束
for thread in threads:
thread.join()
print('共处理视频个数:', fileCount, ' 耗时:', time.time() - startTime)

本文地址: https://github.com/maxzhao-it/blog/post/3756efb0/