Lost dual boot option and need to reinstall grub

The steps in this post are applicable to be done in distributions like Redhat, Centos and Fedora.

Recently I met with an issue like my personal desktop has lost its Dual Boot option at the startup. The machine has been working by having both Windows XP and Centos present in it. The dual boot option has been lost ever since I reinstalled Windows XP. I was not able to choose Centos at the startup from then, and the machine was automatically booting to Windows XP once I power on the CPU. It was pretty sure that I would probably need to reinstall grub in Centos to bring back the Dual Boot option.

Here you go with the steps I tried to reinstall grub in Centos.

Put in the installation CD you used to install Centos in your machine.
(Before that log into BIOS and set CD/DVD Drive in first place of Boot Priority list)

– Press F10(Save your BIOS change and exit inorder to reboot) and on the reboot cycle, machine would load your Centos disk. That means your Centos disk should be present prior to the booting of machine, otherwise it would try to load the from Harddrive.
– Select “Rescue installed system”.
– Select “Local CDDVD” for the Rescue Method.
– On the “Rescue Screen”, select “Continue”.
– On the next menu screen, select “shell Start shell”.
– I got the shell as “bash-4.1#” successfully.
– Then I tried to run “chroot /mnt/sysimage” and hit the following error.

=====================
chroot: failed to run command `/bin/bash’: No such file or directory
=====================

The above error indicates that either you have put in a different architecture CD that doesn’t match the one installed in your machine. Mine is Centos 6.4 i686 and I was using the same disk used to installed it, so that wasn’t issue here.

Finally I found “chroot /mnt/sysimage” was not working and not shifting me into chroot environment, because “/” and “/boot” partitions were not mounting as well. I had to proceed with manual steps in the following way.

My fdisk -l result is

bash-4.1# fdisk -l
omitting empty partition (5)

Disk /dev/sda: 80.0GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x332cf22a

Device Boot Start End Blocks Id System
/dev/sda1 * 1 2550 20482843+ 7 HPFS/NTFS
/dev/sda2 2551 9728 57657285 f W95 Ext’d (LBA)
/dev/sda3 5738 9728 32057676 7 HPFS/NTFS
/dev/sda5 2551 2576 204800 83 Linux
/dev/sda6 2576 5476 23294976 83 Linux
/dev/sda7 5476 5737 2096128 82 Linux swap / Solaris

/dev/sda6 is my “/” partition and “/dev/sda5” is the “/boot” partition.

I mounted “/” and “/boot” partitions manually and chrooted it.

bash-4.1# mkdir /mnt/ROOT
bash-4.1# mount -t ext4 /dev/sda6 /mnt/ROOT
bash-4.1# mount -t ext4 /dev/sda5 /mnt/ROOT/boot

bash-4.1# chroot /mnt/ROOT
you will be switched to chroot environment >> sh-4.1#

sh-4.1#

I tried to run fdisk -l , but got the below error:

sh-4.1# fdisk -l
cannot open /proc/partitions
sh-4.1#

I exit from the chroot and mounted /proc and /dev using bind method.

sh-4.1# exit
bash-4.1# mount -o bind /proc /mnt/ROOT/proc
bash-4.1# mount -o bind /dev /mnt/ROOT/dev

chroot again

bash-4.1# chroot /mnt/ROOT
sh-4.1# fdisk -l
omitting empty partition (5)

Disk /dev/sda: 80.0GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x332cf22a

Device Boot Start End Blocks Id System
/dev/sda1 * 1 2550 20482843+ 7 HPFS/NTFS
/dev/sda2 2551 9728 57657285 f W95 Ext’d (LBA)
/dev/sda3 5738 9728 32057676 7 HPFS/NTFS
/dev/sda5 2551 2576 204800 83 Linux
/dev/sda6 2576 5476 23294976 83 Linux
/dev/sda7 5476 5737 2096128 82 Linux swap / Solaris
sh-4.1#
sh-4.1#

Now install grub

sh-4.1# grub-install /dev/sda
The file /boot/grub/stage1 not read correctly.

Made me crazy again 🙂
and did it manually from grub prompt.

sh-4.1# grub
Probing devices to guess BIOS drives. This may take a long time.

GNU GRUB version 0.97 (640K lower / 3072K upper memory)

[ Minimal BASH-like line editing is supported. For the first word, TAB
lists possible command completions. Anywhere else TAB lists the possible
completions of a device/filename.]

grub> find /boot/grub/stage1
(hd0,5)

grub> root (hd0,5)
Filesystem type is ext2fs, partition type 0x83

grub> setup (hd0)
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 (hd0)”… 15 sectors are embedded.
succeeded
Running “install /boot/grub/stage1 (hd0) (hd0)1+15 p
(hd0,5)/boot/grub/stage2
/boot/grub/grub.conf”… succeeded
Done.

grub> quit

Make corrections to (hd0,5) in the file /etc/grub.conf or /boot/grub/grub.conf and this is MANDATORY.

sh-4.1# exit
bash-4.1# reboot

Issue has been fixed 🙂

1

2

 

 

 

 

 

 

 

This can also be done using a Live CD with same OS and architecture.

– Boot to CD/DVD Drive
– Select “Rescue Installed System”

You will be shifting to Live CD environment

[root@livecd ~]#

just mount the /boot partition and install grub like as follows:

[root@livecd ~]# mkdir /oldboot
[root@livecd ~]# mount /dev/sda5 /oldboot (/dev/sda5 is my /boot partition here)
[root@livecd ~]#
[root@livecd ~]# grub-install –root-directory=/oldboot /dev/sda
Installation finished. No error reported.
This is the contents of the device map /oldboot/boot/grub/device.map.
Check if this is correct or not. If any of the lines is incorrect,
fix it and re-run the script `grub-install’.

# this device map was generated by anaconda

(fd0) /dev/fd0
(hd0) /dev/sda

3

 

 

 

 

You are done 🙂

Broken grub and getting only grub prompt at the startup

At this case you will get only a grub prompt while at the startup. Please follow the below steps to install grub.

grub> find /boot/grub/stage1
(hd0,5)

(This means the boot loader lies on the first harddisk hd0 and its 5th logical partition)

grub> root (hd0,5)

grub> kernel /boot/vmlinuz-2.6.18-238.19.1.el5.i386 ro root=/dev/sda6

(I gave /dev/sda6 because that is my “/” partition)

or you can as follows.

(check before that if label is already set or not to your root partition. For that boot in with the help of Live CD or be in rescue mode)
####bash-4.1# e2label /dev/sda6
#### /

(so confirmed label is there)

grub> kernel /boot/vmlinuz-2.6.18-238.19.1.el6.i386 ro root=LABEL=/

grub> initrd /boot/initrd-2.6.18-238.19.1.el6.i386.img

grub> boot

That’s it 🙂

Import mails from a non cPanel server

It’s easy for us to import emails over between two cPanel servers, no matter we are migrating 50 or 100 accounts or so, its an easy job to do via WHM or even via backend of cPanel servers. But what if your task to migrate over all emails from a non cPanel server. aahh now you are in trouble!!! 😛

But trust me, you can do that easily with “imapsync”. Following is the command that I did to import mails of email account from a non cpanel.

suppose you want to migrate userx account on server sourceserver.com to userx account on destinationserver.com

====
imapsync –host1 sourceserver.com –user1 userx@domain.net –password1 enterpasshere –host2 destinationserver.com –user2 userx@domain.net –password2 enterpasshere –regexflag “s/\Forwarded//g” –noauthmd5 –syncinternaldates
====

you will see lot of things going on as below in the screen which is a sync process betweeen the two mail servers, wait for a while to complete and then you are done.

============
msg INBOX/208 {34910} copied to INBOX/445
msg INBOX/209 {81261} copied to INBOX/446
msg INBOX/210 {77615} copied to INBOX/447
msg INBOX/211 {10423} copied to INBOX/448
msg INBOX/212 {7092} copied to INBOX/449
msg INBOX/213 {13977} copied to INBOX/450
msg INBOX/214 {57403} copied to INBOX/451
msg INBOX/215 {75258} copied to INBOX/452
msg INBOX/216 {54282} copied to INBOX/453
msg INBOX/217 {77174} copied to INBOX/454
msg INBOX/218 {3298} copied to INBOX/455
msg INBOX/219 {48916} copied to INBOX/456
msg INBOX/220 {19315} copied to INBOX/457
[INBOX.Drafts] -> [INBOX.Drafts]
[INBOX.Junk] -> [INBOX.Junk]
[INBOX.Sent] -> [INBOX.Sent]
[INBOX.Trash] -> [INBOX.Trash]
++++ End looping on each folder
++++ Statistics
Transfer started on : Fri Nov 1 15:47:37 2013
Transfer ended on : Fri Nov 1 15:48:19 2013
Transfer time : 42 sec
Messages transferred : 232
Messages skipped : 0
Messages found duplicate on host1 : 0
Messages found duplicate on host2 : 0
Messages void (noheader) on host1 : 0
Messages void (noheader) on host2 : 0
Messages deleted on host1 : 0
Messages deleted on host2 : 0
Total bytes transferred : 16188117
Total bytes duplicate host1 : 0
Total bytes duplicate host2 : 0
Total bytes skipped : 0
Total bytes error : 0
Message rate : 5.5 messages/s
Average bandwidth rate : 376.4 KiB/s
Reconnections to host1 : 0
Reconnections to host2 : 0
Memory consumption : 115.4 MB
Biggest message : 3019767 bytes
Memory/biggest message ratio : 40.1
Detected 0 errors
============

Before everything you need to ensure imapsync is installed in server. If not just install it using yum.

=====
yum install imapsync
=====

You may require the following perl modules to install in the server.

=====
Mail::IMAPClient 3.34
IO::Socket 1.31
IO::Socket::INET 1.31
IO::Socket::SSL 1.955
Digest::MD5 2.53
Digest::HMAC_MD5 1.01
Term::ReadKey 2.30
Authen::NTLM 1.09
=====

For their installation, just go to cpan prompt and install them one by one.
For eg:

=====
[~]# cpan
cpan> install Mail::IMAPClient
=====

Please note if you are trying to import mails from pop accounts, them imapsync may not work. Such cases you can refer to poptoimap tool. Please read these:

http://www.linux-france.org/prj/pop2imap/pop2imap
http://imapsync.lamiral.info/FAQ