Friday, February 10, 2012

Dual Boot Windows 7 and Debian GNU/Linux

Previously on Machine-Cycle: your thrill-seeking host has decided to upgrade his laptop and setup a dual boot system, and has managed to install a vanilla Windows 7 Ultimate on a new clean hard disk, from upgrade media.

Onward and forward: time to install Debian and make this box useful.

I researched this step a bit and decided to use Windows' own boot manager to manage the selection of operating systems at boot time, so as to minimize the risk of somehow trashing the Windows 7 installation. I did, eventually, replace Windows boot manager with GRUB2, and it worked out just fine. I switched to GRUB2 because it allowed me to debug some hardware issues that cropped up later, but I'll leave that for a future post.
  1. download the Debian/testing netinst ISO image and burn it to a CD
  2. boot Debian Installer from CD
  3. select graphical install
  4. select manual partitioning: you should now see the list of existing disk partitions - the first, smaller, NTFS partition belongs to the Windows 7 boot manager, and should not be touched; the second, large, NTFS partition is the one we need to shrink, in order to fit in Debian
  5. resize the second NTFS partition listed to, say, 33 percent of the hard-drive's total size (this will take a while)
  6. select the remaining empty partition and install Debian into it (this will take a while)
  7. when prompted to install GRUB: you can let the Debian Installer perform its magic for you, and it should just work; otherwise, in order to keep the Windows boot manager: DO NOT install GRUB on the first partition (named, most likely, /dev/sda1), install grub on the new partition (/dev/sda3)
  8. complete the installation - note that you will not be able to boot into Debian just yet
  9. Windows will run a disk check upon reboot, and it should then start normally
  10. boot the system into a live CD/USB (Grml is a good choice) and copy the contents of the /dev/sda3 boot sector to a file on the second partition (mounted, for example, on /mnt/sda2):
    dd if=/dev/sda3 of=/mnt/sda2/debian.bin bs=512 count=1
  11. reboot into Windows
  12. open Command Prompt as administrator
  13. add a new entry to the boot manager's menu:
    bcdedit /create /d "Debian GNU/Linux" /application BOOTSECTOR
    this command returns the numeric ID of the new menu entry, which is used in the following steps
  14. configure the new menu entry to boot C:\debian.bin, make it the last entry in the menu, and configure the menu to timeout after 30 seconds:
    bcdedit /set {ID} device partition=C:
    bcdedit /set {ID}  path \debian.bin
    bcdedit /displayorder {ID} /addlast
    bcdedit /timeout 30
  15. (read more about bcdedit on this Microsoft TechNet article)
  16. you should now be able to select, upon reboot, to boot into either Windows 7 or Debian GNU/Linux
Going both ways ain't that simple.

No comments:

Post a Comment