🐳 Infra/System

부트 파티션 트러블슈팅

terranbin 2025. 3. 19. 17:55
728x90
SMALL

 

case1) grub rescue 수동 부팅

# 존재 파티션 확인
grub rescue> ls
(hd0) (hd0,msdos2) (hd0,msdos1)

#---------------------------------

# 파티션 내용 확인 (Error Case)
grub rescue> ls (hd0,msdos2)/ # 파티션 내용 확인
error: unknown filesystem     

#---------------------------------

# 파티션 내용 확인 (Correct Case)
grub rescue> ls (hd0,msdos1) # 파티션 내용 확인
 /lost+found     /sys      /bin  /boot .... /usr
# 이렇게 partition 나오는 걸 확인 가능
# 해당 파티션에 /boot/grub 존재 확인

#---------------------------------

grub rescue> set  # 환경 변수 확인
grub rescue> set prefix=(hd0,msdos1)/boot/grub   # 환경 변수 변경
grub rescue> set root=(hd0,msdos1)
grub rescue> insmod normal # 모듈 로딩 명령어. 
                           # insmod (절대경로)/normal.mod
grub rescue> normal        # GRUB 의 일반 모드로 전환
----------------------------
# 아래 3 가지 중 하나

# BIOS 부트 시스템 (MBR 기반)
sudo grub2-install /dev/sda
sudo grub2-mkconfig -o /boot/grub2/grub.cfg

# UEFI 부트 시스템 (GPT + EFI 파티션 있는 경우)
sudo grub2-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=GRUB
sudo grub2-mkconfig -o /boot/efi/EFI/GRUB/grub.cfg   # 시스템에 따라 다름

# Ubuntu
sudo grub-install /dev/sda         # BIOS
sudo grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=ubuntu  # UEFI
sudo update-grub

case2) Live CD(USB)로 부팅해서 chroot 환경에서 실행

# Live OS로 부팅 후:
mount /dev/sda3 /mnt/sysimage/ 
# /dev/sda3은 root 파티션이다. 다른 파티션에 설치되어 있을 수 있으니 확인 후 mount

mount /dev/sda1 /mnt/sysimage/boot/ 
# /dev/sda1 은 boot 파티션이다. 보통은 sda1로 하나 다를수 있으니 확인 후 mount

mount -o bind /dev /mnt/sysimage/dev/
mount -o bind /sys /mnt/sysimage/sys/
mount -o bind /proc /mnt/sysimage/proc/
mount -o bind /var /mnt/sysimage/var
mount -o bind /tmp /mnt/sysimage/tmp
sudo chroot /mnt

# 이제 grub 복구
grub-install /dev/sda
# sudo grub-install --root-directory=/mnt /dev/sda
grub2-mkconfig -o /boot/grub2/grub.cfg
exit
sudo reboot

 

 

[참고 영상]

https://www.youtube.com/watch?v=3JQxlu828w4&t=77s

LIST