Skip to content

Instantly share code, notes, and snippets.

@9minuet
Created September 2, 2025 09:05
Show Gist options
  • Select an option

  • Save 9minuet/6aecad87462d34317c906718e03cc1aa to your computer and use it in GitHub Desktop.

Select an option

Save 9minuet/6aecad87462d34317c906718e03cc1aa to your computer and use it in GitHub Desktop.
Proxmox VE 9 NUC grub 복구 스크립트
#!/bin/bash
# Proxmox VE 9 NUC grub 복구 스크립트
echo "===== Proxmox grub 자동 복구 시작 ====="
# 1️⃣ 루트 파티션 / ZFS 자동 감지
ROOT_PART=""
ZFS_POOL=""
if command -v zpool >/dev/null 2>&1; then
for pool in $(zpool list -H -o name); do
mountpoint=$(zfs get -H -o value mountpoint $pool 2>/dev/null)
if [ "$mountpoint" = "/" ]; then
ZFS_POOL=$pool
ROOT_PART=$pool
echo "ZFS root pool detected: $ZFS_POOL"
break
fi
done
fi
if [ -z "$ROOT_PART" ]; then
ROOT_PART=$(lsblk -o NAME,MOUNTPOINT | grep " /$" | awk '{print $1}' | head -n1)
if [ -z "$ROOT_PART" ]; then
echo "Root partition not detected. Exiting."
exit 1
fi
echo "Root partition detected: $ROOT_PART"
fi
# 2️⃣ 마운트
if [ -d /sys/firmware/efi ]; then
MODE="UEFI"
echo "UEFI mode detected."
mount /dev/$ROOT_PART /mnt || { echo "Failed to mount root"; exit 1; }
EFI_PART=$(lsblk -o NAME,FSTYPE,MOUNTPOINT | grep vfat | awk '{print $1}' | head -n1)
if [ -z "$EFI_PART" ]; then
echo "EFI partition not found. Exiting."
exit 1
fi
mkdir -p /mnt/boot/efi
mount /dev/$EFI_PART /mnt/boot/efi
else
MODE="BIOS"
echo "BIOS mode detected."
mount /dev/$ROOT_PART /mnt || { echo "Failed to mount root"; exit 1; }
fi
# 3️⃣ chroot 설정
mount --bind /dev /mnt/dev
mount --bind /proc /mnt/proc
mount --bind /sys /mnt/sys
# 4️⃣ grub 재설치
chroot /mnt /bin/bash << EOF2
if [ "$MODE" = "UEFI" ]; then
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=proxmox --recheck
else
grub-install /dev/$ROOT_PART
fi
update-grub
EOF2
# 5️⃣ 정리 및 재부팅
umount /mnt/dev
umount /mnt/proc
umount /mnt/sys
if [ "$MODE" = "UEFI" ]; then
umount /mnt/boot/efi
fi
umount /mnt
echo "Grub 복구 완료. 시스템 재부팅 중..."
reboot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment