I ran into this issue while on Fedora16 (32bit). This isn’t the first time this has happened to me. In fact, this happens every time you install Windows while trying to dual boot on your linux machine (even if it’s on another partition). If it’s another harddive altogether, go read something else as this isn’t your solution.
This solution may work for RedHat as well as CentOS, but please research more for your specific distro and partitions as this post is meant to give you a higher approach first then dives into the details. This approach seemed to work really well because of my specific situation.
My setup:
- 1 physical disk, 5+/- logical partitions (LVM2) (all linux partitions except for boot are encrypted..those that are encrypted are actually LVM2, so there’s only two actual partitions…but wait partitions are logical anyway…nevermind.)
- /dev/sda1 <– M$ft partition (recovery)
- /dev/sda2 <– M$ft partition (non-recovery)
- /dev/sda3 <– /boot partition
- /dev/sda5 <– encrypted partition containing main linux FS (swap, /home, /root)
Steps for recovering your linux boot loader:
- Boot into Linux with a Live CD/DVD (or USB).
- Make sure you are root. (Might as well since we’re on a Live boot)
- Log into the encrypted drive
- Enable logical volume support
- Mount the drive(s)
- Install Grub2
- Configure Grub2
- Reboot
1. Boot into Linux with a Live CD/DVD (or USB)
This should be straight forward. I recommend using the same distribution LiveCD as is on your PC, but not required.
Booting with a live USB thumbdrive can be a pain as I’m told, but if I did it you can do it too. I’m not sure why people say it’s a pain. Space can’t be an issue — you can get 8,16,32,64 GB USB thrumdrives easily and it’s way more than enough space to boot into Linux. Whatever.
2. Make sure you are root
su or su root should suffice.
3. Log into the encrypted drive (optional)
If your drive is encrypted you’ll need to bypass that. Open a terminal and issue this:
Figure out the partition mappings:
fdisk -l
Issue the decryption command, this can be different for different encryption types. I had LuksOpen on mine.
cryptsetup luksOpen /dev/XXX# encrypted-fedora
Where XXX is sda, hda or something else and # is 1,2,3,4,etc. If you have no idea which drive is encrypted, go ahead and go down the list output by fdisk and you may or may not be prompted. If you are, great. Enter your drive encryption password. If not, you’re in luck and you don’t need a password to mount the drive! (Meaning, skip this step). If you cannot remember your drive encryption password, I have bad news for you. Either create a spiffy cracking program/script and pray your password is not that strong or reformat the drive, meaning all data is lost, sorry you’re SOL, or up the proverbial creek without a paddle.
4. Enable LVM support (optional)
This may or may not be needed. You can check real quick by issuing:
lvscan
If no drives are listed whether active or inactive (even after unlocking the encryption on the drive) then no need! You can most likely just mount your drive(s)! Otherwise, do this:
modprobe dm-mod vgchange -ay
Then issue an lvscan again to make sure the logical volume support is ACTIVE.
5. Mount the drive(s)
Okay this can be tricky depending on your setup. If you have /root, /boot and other folders on separate partitions then have no fear. You just need the main two, /root and /boot.
mkdir -p /mnt/my-drive mount /dev/LogVolume-lv_root /mnt/my-drive <-- my /root was LVM2 AND encrypted. FUN. mount /dev/sda3 /mnt/my-drive/boot <-- /dev/sda3 was where my /boot partition was
6. Reinstall Grub2
grub2-install --root-directory=/mnt/my-drive /dev/sda
That’s right, there are NO numbers here when issuing the install command. You are telling grub to install itself on the MBR (master boot record) of the drive.
7. Configure Grub2
Chances are if you had Linux already running you don’t need to update grub. Also, installing grub2 might suffice for most people’s situations and can usually detect M$ft partitions quite well. Lastly, there are books written on grub2 so I won’t go into detail here. Sorry!
8. Reboot and has cookies!
reboot && $can_has_cookies
KIDDING… just do:
reboot
Conclusion
Hopefully you get the higher level view of a workflow when working with drives in Linux. Drives are mapped to folders, not drive letters (letters for a drive? Nonsense!).
Some nuances: there may be difference drive encryption types out there. Beware which you have on your drive, if any. Also beware if you have LVM2. If you’re installing grub2/Linux for the first time this post won’t fit your needs very well.
Lastly, why do you still have Windows installed? (evil grin)