From ef6ed60c46cf04a192867d7a0742b42a296ec606 Mon Sep 17 00:00:00 2001 From: Ing Date: Wed, 17 Sep 2025 17:37:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20pve.sh=20=E8=84=9A?= =?UTF-8?q?=E6=9C=AC=EF=BC=8C=E4=BF=AE=E5=A4=8D=E5=AD=98=E5=82=A8=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/pve.sh | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/scripts/pve.sh b/scripts/pve.sh index ce0e8a72..fc52e6d3 100644 --- a/scripts/pve.sh +++ b/scripts/pve.sh @@ -106,7 +106,7 @@ else if ! command -v unzip >/dev/null 2>&1; then apt-get update >/dev/null 2>&1 && apt-get install -y unzip >/dev/null 2>&1 fi - IMG_FILE=$(unzip -l "/tmp/rr-${TAG}.img.zip" | awk '{print $4}' | grep '\.img$' | head -n 1) + IMG_FILE=$(unzip -l "/tmp/rr-${TAG}.img.zip" | awk '{print $4}' | grep '\.img$' | head -1) if [ -z "${IMG_FILE}" ]; then echo "No img file found in rr-${TAG}.img.zip" exit 1 @@ -137,9 +137,17 @@ if [ $? -ne 0 ]; then exit 1 fi +# 获取 存储 +STORAGE=$(pvesm status -content images | awk 'NR>1 {print $1}' | grep local | tail -1) +if [ -z "${STORAGE}" ]; then + echo "No storage for images" + qm destroy ${VMID} --purge + exit 1 +fi + # 启用 UEFI 引导 if [ "${EFI:-1}" -eq 1 ]; then - if ! qm set ${VMID} --bios ovmf --efidisk0 local-lvm:4,efitype=4m,pre-enrolled-keys=0; then + if ! qm set ${VMID} --bios ovmf --efidisk0 ${STORAGE}:4,efitype=4m,pre-enrolled-keys=0; then echo "Set UEFI failed" qm destroy ${VMID} --purge exit 1 @@ -147,12 +155,6 @@ if [ "${EFI:-1}" -eq 1 ]; then fi # 导入 RR 镜像 -STORAGE=$(pvesm status -content images | awk 'NR>1 {print $1}') -if [ -z "${STORAGE}" ]; then - echo "No storage for images" - qm destroy ${VMID} --purge - exit 1 -fi BLDISK=$(qm importdisk ${VMID} "${IMG_PATH}" "${STORAGE}" | grep 'successfully imported disk' | sed -n "s/.*'\(.*\)'.*/\1/p") STATUS=$? if [ "${STATUS:-0}" -ne 0 ] || [ -z "${BLDISK}" ]; then @@ -203,9 +205,9 @@ if [ $? -ne 0 ]; then fi # 添加 32G 数据盘 -qm set ${VMID} --sata1 local-lvm:32 +qm set ${VMID} --sata1 ${STORAGE}:32 -BRIDGE=$(awk -F: '/^iface vmbr/ {print $1}' /etc/network/interfaces | awk '{print $2}' | head -n 1) +BRIDGE=$(awk -F: '/^iface vmbr/ {print $1}' /etc/network/interfaces | awk '{print $2}' | head -1) if [ -z "${BRIDGE}" ]; then echo "Get bridge failed" qm destroy ${VMID} --purge