LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   Install grub for a filesystem on sdb from a rescue system on sda (http://www.linuxquestions.org/questions/linux-general-1/install-grub-for-a-filesystem-on-sdb-from-a-rescue-system-on-sda-750105/)

simonb 08-25-2009 09:48 AM

Install grub for a filesystem on sdb from a rescue system on sda
 
I boot a CentOS 5 image running on /dev/sda and I have a dormant CentOS 5 image on /dev/sdb that I need to install grub on.

I do the following sequence of commands to mount the other installation (I copied these mounts from the rescue CD).

Code:

mkdir -p /mnt/target
mount /dev/VolGroup00/LogVol00 /mnt/target
mount /dev/sdb1 /mnt/target/boot
mount /tmp/sysfs /mnt/target/sys -t sysfs
mount /tmp/proc /mnt/target/proc -t proc
mount /dev /mnt/target/dev -o bind
mount /dev/pts /mnt/target/dev/pts -t devpts
mount /selinux /mnt/target/selinux -t selinuxfs

I then chroot and install grub...

Code:

chroot /mnt/target
grub
>root (hd1,0)
 Filesystem type is ext2fs, partition type 0x83
>setup (hd1)
setup (hd1)
 Checking if "/boot/grub/stage1" exists... yes
 Checking if "/boot/grub/stage2" exists... yes
 Checking if "/boot/grub/e2fs_stage1_5" exists... yes
 Running "embed /boot/grub/e2fs_stage1_5 (hd1)"...  17 sectors are embedded.
succeeded
 Running "install /boot/grub/stage1 (hd1) (hd1)1+17 p (hd1,0)/boot/grub/stage2 /boot/grub/grub.conf"... succeeded
Done.
>quit
exit

I then unmount all the target directories...

Code:

umount /mnt/target/selinux
umount /mnt/target/dev/pts
umount /mnt/target/proc
umount /mnt/target/sys
umount /mnt/target/dev
umount /mnt/target/boot
umount /mnt/target

I then reboot with the target system now as sda. It just drops to a grub shell. I have no idea why. I can re-install grub from this shell, it reports success and then it still does the same thing next time I boot. If I install grub from a rescue CD then it works fine. However I don't what to do this from a rescue CD since I have to script the process (for a VM backup and disaster recovery system) and the CD requires manual intervention.

The grub.conf file is correct for a system booting off sda, after all, the install CD is able to get grub working.

David1357 08-25-2009 12:07 PM

Quote:

Originally Posted by simonb (Post 3656765)
I then reboot with the target system now as sda. It just drops to a grub shell. I have no idea why.

Have you tried
Code:

# grub-install --root-directory=/mnt/target /dev/sdb
Also, is the "bootable" flag set on "/dev/sdb"? You can check this by running "fdisk -l /dev/sdb".

simonb 08-26-2009 06:35 AM

Fixed!

I tried what you suggested but still got the same result. However I have now found a way to install grub on the other drive so that it boots. I don't even have to mount the other drive.

Code:

grub << EOF
device (hd0) /dev/sdb
install (hd0,0)/grub/stage1 d (hd0) (hd0,0)/grub/stage2 p (hd0,0)/grub/grub.conf
EOF

The next hurdle I had was that it couldn't find VolGroup00. This turned out to be because the previous Xen kernel needed "alias scsi_hostadapter xenblk" in /etc/modprobe.conf which cause the rpm install of the non-Xen kernel to mess up the initrd file with the error message, "No module xenblk found for kernel ..... aborting". The solution was to comment out the line in /etc/modprobe.conf, chroot to the target filesystem and re-run initrd.

Now it boots :-)

David1357 08-27-2009 01:03 PM

Quote:

Originally Posted by simonb (Post 3657997)
Fixed!

Don't forget to use the "Thread Tools" drop down to mark this thread as "solved".

simonb 08-28-2009 12:39 AM

Quote:

Originally Posted by David1357 (Post 3659730)
Don't forget to use the "Thread Tools" drop down to mark this thread as "solved".

Thanks for the reminder. Done!


All times are GMT -5. The time now is 07:24 PM.