howto reinstall GRUB in rescue mode while using lvm / mdadm

This article is how to activate LVM and mdadm software raid in rescue and reinstall GRUB boot loader, since the boot CD will not do this job for you. By following the steps, you may able to do system recovery or disk operation.

RedHat 5.x

Activate the RAID

mkdir /etc/mdadm
mdadm --examine --scan > /etc/mdadm/mdadm.conf
mdadm -A --scan

RedHat 4.x

Activate the RAID

vi /etc/mdadm.conf

DEVICE /dev/sda1 /dev/sdb1 /dev/sda2 /dev/sdb2

scan it

mdadm --examine --scan >> /etc/mdadm.conf

or put it in /etc/mdadm.conf maunally

DEVICE /dev/sda1 /dev/sdb1 /dev/sda2 /dev/sdb2
ARRAY /dev/md0 level=raid1 devices=/dev/sda1,/dev/sdb1
ARRAY /dev/md1 level=raid1 devices=/dev/sdb2,/dev/sdb2

LVM2

Activate LVM

If your root partition located on logical volume.

lvm pvscan
lvm vgscan
lvm lvscan
lvm vgchange -ay

Reinstall GRUB?

Example Case A:

/boot on md0
/ on md1

Prepare the environment

mkdir /mnt/sysimage
mount /dev/md1  /mnt/sysimage
mount -o bind /dev /mnt/sysimage/dev
mount -o bind /proc /mnt/sysimage/proc
chroot /mnt/sysimage /bin/bash
mount /dev/md0 /boot

Install GRUB

grub
grub>root (hd0,0)
grub>setup (hd0)

Example Case B:

/boot on md0
/ on /dev/VolGroup00/LogVol00

Prepare the environment,

mkdir /mnt/sysimage
mount /dev/VolGroup00/LogVol00  /mnt/sysimage
mount -o bind /dev /mnt/sysimage/dev
mount -o bind /proc /mnt/sysimage/proc
chroot /mnt/sysimage /bin/bash
mount /dev/md0 /boot

Install GRUB

grub
grub>root (hd0,0)
grub>setup (hd0)

3 Replies to “howto reinstall GRUB in rescue mode while using lvm / mdadm”

Leave a Reply