Monday, May 31, 2010

Windows 7 - (K)Ubuntu coexistance nightmare

I had been running Windows and Kubuntu on a dual boot configuration for a long time now. My current Presario CQ60 laptop came with Windows Vista pre-installed. When Windows 7 was launched, I got a copy for the $50 promotional price. I use Grub2 as the default boot manager.

I use Kubuntu as my primary OS and only log into Windows 7 mostly for applying updates, which is why I didn't bother to investigate when windows 7 did not start without restarting the computer 3 - 4 times. Then one day, I decided to install Visual Studio 2010 Express editions. The first part of the installation requires restarting the computer to apply come settings and then continues to complete the rest of the installation. Except, for me, the computer went into a restart frenzy. I tried safe mode with no luck. The 3 - 4 restarts turned into 7 - 8 before letting me log into windows. When starting in Safe Mode, I noticed that the last driver that was loaded before the computer restarted was classpnp.sys. Bing-ing and Google-ing "CLASSPNP.SYS Windows 7" made chills run down my spine.

With no solution available on the Internet, I decided to reinstall Windows 7. I got Windows back, but my home partition (/home) I use with Linux went missing. GParted listed it as "Unallocated." My months and years worth of work went poof! I also noticed some issues with my partition table. I had restructured my HDD earlier to increase the size of the /home partition and ever since, certain partitions in the partition table had overlapping boundary sectors. TestDrive utility bundled with PartedMagic came to the rescue. I got my /home partition, and hence, Linux installation back, but the Windows 7 restarting issue came back as well. And this was a fresh OS install with no additional software installed yet. Moreover, GParted listed the entire 250GB HDD as unallocated. My partition table was messed up.

Next few were some of the most painstaking days of my life. I had an external HDD with not nearly as much space as I needed for my /home partition, not even after tar.gz-ing all the files. I knew that sacrifices would have to be made. After leaving behind all the application configuration files and downloads, I managed to copy my most valuable content to the external HDD. I wiped the 250GB HDD clean and installed Windows 7 64-bit on 100GB partition. Then I reinstalled Linux, and restored my files to the new 100GB /home partition. Linux installation make Grub2 as the default boot loader. The nightmares returned.

Windows 7 was back, and so was the problem with multiple restarts. I decided to install Windows 7 32-bit to see if that resolved the issue. Once installed, I restarted my computer multiple times to see if the issue was still there. To my surprise, Windows behaved this time. Excited about this, I restored Grub2 using the LiveCD of Kubuntu. Soon enough the grin on my face turned into a frown. It appeared that as long as Windows got to hold the MBR with its boot loader, it was happy. However, when Grub2 took over, Windows started throwing a fit.

I decided to let Windows boot loader hold on to the MBR. I followed Method two from:

http://www.sevenforums.com/tutorials/668-system-recovery-options.html

Once on the Command Promt, I browsed to the Windows System32 folder. I issued the following command to restore MBR:

bootsect /nt60 c: /mbr

I now had to figure out how to chain load Grub2 from windows boot loader. I came across this article:

http://ubuntuforums.org/showthread.php?t=208951

Three differences I found with the configuration addressed in the article and mine were:

  1. No separate /boot partitions
  2. Grub2 instead of Grub Legacy.
  3. No boot.ini in Windows 7 which I did not realize until much later

I decided to improvise. I understood that I needed the boot sector with Grub2 installed on it. After installing Grub2 to the external HDD /dev/sdc, I issued the following command:

sudo dd if=/dev/sdc of=/home/{my-user-id}/Desktop/kubuntu.lnx bs=512 count=1

I then copied the kubuntu.lnx to the root directory on the Windows 7 partition and restarted the computer into Windows to rig the boot.ini. Here I ran into the issue with no boot.ini in Windows 7. I research and came across this article:

http://apcmag.com/how_to_dualboot_vista_with_linux_linux_is_already_installed.htm?page=5

EasyBCD tool seemed promising. I promptly installed it and followed the instructions when I ran into another brick wall. EasyBCD was not Grub2 compatible. It only worked with Legacy Grub. However, I noticed that a new entry was added to Windows boot loader options and it referred to NeoGrub.mbr file residing in C:\NST folder. It was time to improvise again. I renamed the original NeoGrub.mbr file to NeoGrub-bak.mbr effectively breaking the reference and renamed my kubuntu.lnx to NeoGrub.mbr. With my fingers crossed, I rebooted the laptop. It worked! I was able to load Kubuntu using the Windows boot loader. I haven't had the restart issues ever since. I've also updated the boot option description from "NeoSmart Linux" to "Kubuntu" and changed the file path from C:\NST\NeoGrub.mbr to C:\kubuntu.lnx.

Few things to note. The restart issue is not limited to dual/multi boot configuration in Windows Vista/7. People have also reported this issue to be related to certain hardware, mainly with NIC and VGA. While the problem seems to be resolved for now, I am not sure if I've seen the end of the multiple restarts.

No comments:

Post a Comment