Pages

Saturday, July 31, 2010

Installing Windows 7 after Ubuntu 10.04 from a USB





Introduction
With all the new games coming out this year, Startcraft II, Civ V and maybe (I hope...) Diablo III, I decided it was finally time to bite the bullet and setup windows on my ubuntu desktop. Seeing as Vista is absolutely terrible and XP is getting a 'little' dated, I decided I'd go for windows 7. Now for most installs this would be rather simple however, the box I decided to use can't boot from usb (I know... it sucks!) and seeing as I didn't have a blank DVD to waste things got complicated. After a little look around it didn't seem like anyone had a thorough guide that explained all these things in one place, so I've decided to put one together!

Overview
  1. Obtain Windows 7, CD or ISO
  2. Create Bootable USB (you can use a DVD... but it takes forever)
  3. Download and setup Plop Boot Manager (Only if your computer won't boot from a USB)
  4. Resize Ubuntu partition to make room for Window 7 and format free space to NTFS
  5. Install Windows 7 on the new partition
  6. Restore Grub2
Guide
I am installing this on top of Ubuntu 10.04. This is important because unlike previous versions (except 9.10.. kind of), 10.04 uses Grub 2 and the live CD includes GParted. 


If there is a more complicated piece of code, usually one that involves a subsitution, then i will provide an example below it, in the format of Mine: code that I typed when I did it. This is not code that you need to copy, it serves only as an example!


1. Obtaining Windows 7
For this guide it does not matter whether you have a Windows 7 DVD or USB. However, if you do already have a bootable DVD then you might want to skip steps 2 and 3 but thats entirely up to you. Personally I much prefer installing from a USB as they do take less time.

2. Creating the bootable USB

The first thing we have to do is format the USB so that its NTFS (FAT 32 might work) and let the computer know it can use this device to boot from. When we format the USB it will lose all its data, so if you have anything important make sure you back it up.
  • To do this open up terminal and install GParted
    • sudo aptitude install gparted
  • Plug in the USB you plan to use, I suggest 4gb or more
  • Open GParted by going System>Administration>GParted
  • Select your device from the drop down menu on the right
    • This is REALLLY important. Do not format your harddrive. Make sure you select your USB. For me that's /dev/sdb
  • Right click on the partition in the list and select unmount
  • Right click on it again and select delete
  • Right click again and select new
    • Set the 'File System' to ntfs
    • Click add
  • Click Edit>Apply All Operations
  • Once this has finished. Right click on the partition again and select Manage Flags
    • Check 'boot'
    • Press close
  • Exit gparted
Now that we have a bootable USB, the next step is to put Windows 7 on there! 
  • If you have a Windows 7 DVD simply insert the DVD and open it up in nautilus (your file browser). If you have an ISO file then we'll mount it with some terminal magic
    • Open up terminal and type
    • sudo mkdir /media/iso
    • This will create your mount location. Next we mount the ISO and make the computer think its a CD 
    • sudo mount -o loop -t auto [path to ISO] /media/iso
      • Mine: sudo mount -o loop -t auto /home/ubuntu/iso/windows\ 7.iso /media/iso
    • If done correctly you should now be able to open the iso from nautilus (your file browser) 
  • Now copy all the files from either your DVD or the mounted ISO onto your USB
That should be it. One the files have finished copying you should now be able to boot Windows 7 from your usb.

3. Download and setup Plop Boot Manager 
*** This is only necessary if your computer can't boot from a USB. To test this reboot and open bios (sometimes F11, F12, or Delete and check your boot options***
  • Download plpbt-5.0.10.zip (the version shouldn't really matter) from http://www.plop.at/en/bootmanagerdl.html
  • Open the file and extract plpbt.bin to your home directory
  • Open terminal and type
    • sudo mv ~/plpbt.bin /boot
    • sudo gedit /etc/grub.d/40_custom &
    • Add the following to the file (do not delete anything!) then save the file.




menuentry "Plop Bootmanager" {
set root=(hd0,1)
search --no-floppy --fs-uuid --set 0b07e554-9083-4467-a1a8-94cb88ee6c6f
linux16 /boot/plpbt.bin
}
  • In terminal type 
    • sudo update-grub
    • If you get no errors then you should be ready to boot from your USB
      • If you do get errors then it is possible that your boot partition is not your first partition. If thats the case. In terminal type sudo fdisk -l. Find your boot partition (the one with the *) and then use that in the 40_custom file for the set root(hd0,1) command
        • For example: If my boot is /dev/sda2 then I would use set root(hd0,2)
        • If it was /dev/sdb1 then i would use set root(hd1,0)
4. Resize Ubuntu partition 
I won't go into to much detail here as we have already used gparted earlier. Just make sure you are doing this from a live CD or USB instead of the installed OS.
  • Insert Ubuntu or GParted live CD or USB. Reboot your computer and boot into it.
  • Open up the partitioner 
  • Resize your linux install to make room for Windows. I'd say more than 14 GBs
  • Apply, wait for this to finish (took mine 2 hours..)
  • Reboot
5.  Install Windows 7 on the new partition
The first few steps will depend on whether you installed plop boot manager. If you didn't then to get your computer to boot from the USB you are going to have to enter BIOS and set the boot priority. Seeing as this seems to be different for every computer you will prolly have to figure it out on your own and then skip to the install step
  • insert your Windows 7 USB (or DVD)
  • Reboot your computer and hold shift. This will bring up the grub menu.
  • Select Plop Boot manager
  • Select USB
  • The computer sould now boot from your USB and let you install windows.
  • The only thing you really need to watch when your installing is that you select the Custom (Advanced) option instead of the Upgrade option. This will allow you to select the space you just cleared for the install
6.  Restore Grub2
After windows installs it very nicely wipes out grub and leaves your computer unable to boot back into ubuntu... now your only option is Windows!!! :(
To fix this:

  • For Ubuntu 10.04 or Ubuntu with a Grun2 install
    • Boot with a Ubuntu 10.04 Live CD or USB
    • Open terminal
      • Find the partition that grub is installed on with: 
      • sudo fdisk -l
      • Make note of the 'Device Boot" the one your looking for will probably say 'Linux' under System
    • Mount the drive using the 'Device Boot' from before
      • sudo mount [Device Boot] /mnt
        • Mine: sudo mount /dev/sda1 /mnt
    • Install Grub
      • sudo grub-install --root-directory=/mnt [Device Boot, without the number]
        • Mine: sudo grub-install --root-directory=/mnt/ /dev/sda
    • Unmount
      • sudo umount /mnt
    • Reboot
      • sudo reboot now
  • For Ubuntu with a Grub legacy install

And that should be it!