To check if GRUB is installed on a specific disk (e.g., /dev/sda), use these terminal commands:
# Check for GRUB in MBR (BIOS systems)
sudo dd if=/dev/sda bs=512 count=1 2>/dev/null | strings | grep "GRUB"
# For UEFI systems
sudo ls /boot/efi/EFI/ | grep -i grub
The primary configuration file contains the root parameter you need to verify:
# Check the current GRUB configuration
sudo cat /boot/grub/grub.cfg | grep -A5 "menuentry"
# View the root device setting
sudo grep "set root" /boot/grub/grub.cfg
For software RAID1 arrays, you should check each member disk independently:
#!/bin/bash
for disk in /dev/sd[a-b]; do
echo "Checking GRUB on $disk"
sudo grub-install --no-floppy --boot-directory=/mnt/tmpboot $disk
sudo grep -r "root=" /mnt/tmpboot/grub/
sudo umount /mnt/tmpboot 2>/dev/null
done
The root parameter should point to your RAID device (e.g., /dev/md0). Here's how to verify:
# Check current root filesystem
sudo grub-probe -t device /boot
# Compare with RAID array members
sudo mdadm --detail /dev/md0 | grep -i "active"
For batch processing multiple RAID arrays, use this script:
#!/bin/bash
RAID_DEVICES=("/dev/md0" "/dev/md1")
for raid in "${RAID_DEVICES[@]}"; do
DISKS=($(sudo mdadm --detail $raid | grep -o "/dev/sd[a-z]"))
for disk in "${DISKS[@]}"; do
echo "Verifying $disk in array $raid"
sudo grub-install --no-floppy --boot-directory=/mnt/tmpboot $disk
if ! sudo grep -q $(sudo blkid $raid -o value | head -1) /mnt/tmpboot/grub/grub.cfg; then
echo "WARNING: Mismatched UUID on $disk"
fi
sudo umount /mnt/tmpboot 2>/dev/null
done
done
1. Always install GRUB to all RAID member disks using:
sudo grub-install /dev/sda
sudo grub-install /dev/sdb
2. The root parameter should reference the RAID device (e.g., /dev/md0) not individual disks
3. After changes, update GRUB configuration with:
sudo update-grub
To check if GRUB is installed on a disk in a Linux system, you can use the following methods:
# Method 1: Check for GRUB files in boot partition
sudo ls -l /boot/grub/
# Method 2: Check the first sector for GRUB signature
sudo dd if=/dev/sdX bs=512 count=1 2>/dev/null | strings | grep GRUB
# Method 3: Use file command on MBR
sudo file -s /dev/sdX
For RAID arrays, you need to verify the root parameter points to the correct device:
# View current GRUB configuration
sudo cat /boot/grub/grub.cfg | grep -i "set root"
# Alternative method using grub-mkconfig
sudo grub-mkconfig | grep -i "root="
When dealing with multiple disks in RAID1, you should verify GRUB on each member:
#!/bin/bash
for disk in /dev/sd{a,b}; do
echo "Checking $disk..."
sudo dd if=$disk bs=512 count=1 2>/dev/null | strings | grep -q GRUB && \
echo "GRUB found on $disk" || echo "GRUB missing on $disk"
echo "Checking root parameter:"
sudo grep -oP "set root='\K[^']+" /boot/grub/grub.cfg | uniq
done
If you find disks without GRUB or with incorrect root parameters:
# Install GRUB to secondary disk (example for /dev/sdb)
sudo grub-install /dev/sdb
sudo update-grub
# Verify the root device UUID matches your RAID array
sudo blkid | grep -i raid
For systems with multiple RAID arrays, extend the verification:
#!/bin/bash
RAID_DEVICES=$(lsblk -o NAME,RAIDLEVEL | grep -P "raid1" | awk '{print $1}')
for device in $RAID_DEVICES; do
DISKS=$(lsblk -o NAME,MAJ:MIN /dev/$device --noheadings | awk '{print $1}')
for disk in $DISKS; do
echo "Processing $disk..."
# Add verification and correction logic here
done
done