화. 8월 5th, 2025

Introduction to GRUB
GRUB (Grand Unified Bootloader) is the default boot manager for most Linux distributions. It loads your operating system kernel and initiates the startup process. When GRUB encounters issues, your system may become unbootable. This guide covers essential configuration, troubleshooting, and recovery techniques.


I. Basic GRUB Configuration

1. Key Configuration Files

  • Primary Config: /boot/grub/grub.cfg (⚠️ Do NOT edit directly!)
  • Custom Settings: /etc/default/grub (controls timeout, default OS, etc.)
  • Script Directory: /etc/grub.d/ (generates grub.cfg)

2. Making Permanent Changes

  1. Edit preferences:
    sudo nano /etc/default/grub

    Example modifications:

    GRUB_DEFAULT=0                 # Boot first OS entry
    GRUB_TIMEOUT=5                 # Show menu for 5 seconds
    GRUB_CMDLINE_LINUX="quiet splash"
  2. Update GRUB:
    sudo update-grub

    (Regenerates grub.cfg safely)


II. Essential Recovery Commands

Boot Failure? Access GRUB Rescue:

  1. Reboot → Hold SHIFT (or spam ESC) during startup
  2. You’ll see:
    grub> _

Critical Commands:

ls                  # List partitions (e.g., (hd0,msdos1), (hd0,msdos2))
ls (hd0,msdos1)/    # Explore files in partition 1
set root=(hd0,msdos2)  # Set root partition
linux /boot/vmlinuz-xyz root=/dev/sda2  # Specify kernel
initrd /boot/initrd.img-xyz             # Load initramfs
boot                # Boot manually

III. Reinstalling GRUB

Scenario: Corrupted GRUB after Windows install or disk changes.

From Live USB (Chroot Method):

  1. Boot Linux Live USB → Open Terminal
  2. Identify partitions:
    sudo fdisk -l

    (Note Linux root /dev/sda2 and boot /dev/sda1)

  3. Mount partitions:
    sudo mount /dev/sda2 /mnt
    sudo mount /dev/sda1 /mnt/boot
    sudo mount --bind /dev /mnt/dev
    sudo mount --bind /proc /mnt/proc
    sudo mount --bind /sys /mnt/sys
  4. Chroot into system:
    sudo chroot /mnt
  5. Reinstall GRUB:
    grub-install /dev/sda      # Install to MBR
    update-grub                # Rebuild config
    exit
    sudo reboot

For UEFI Systems:
Replace grub-install with:

grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=GRUB

IV. Common Fixes & Tips

  • Boot Repair Tool:
    Use Ubuntu’s boot-repair:

    sudo add-apt-repository ppa:yannubuntu/boot-repair
    sudo apt update && sudo apt install boot-repair
    sudo boot-repair

    (Automates GRUB recovery)

  • Password Protection:
    Add to /etc/grub.d/00_header:

    
    cat < 💡 **Need Help?** Share your error in forums with outputs from `lsblk` and `sudo fdisk -l` for faster assistance.

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다