Windows 7 Dual-Boot CentOS 6.4 on an External USB Drive

Before you do this, make recovery disk(s) for Windows 7. Unless you already have them. You may want to backup anything you have on the Windows 7 drive, but if you’re only using it to run browsers, you haven’t invested that much anyway. Make sure you have some sort of recovery disks or you will either have to buy them or pay someone to fix your disk. Label the disk. Eventually.

The first thing you’ll need for this is a CentOS 6.4 LiveCD. Go to one of the CentOS mirrors (http://www.centos.org/modules/tinycontent/index.php?id=15) and use the following URL pattern: http://mirror.example.com/centos/6/isos/i386/CentOS-6.4-i386-LiveCD.iso. If you have a 64-bit machine, use x86_64. You can also use a USB to boot, I recommend http://unetbootin.sourceforge.net/

Install CentOS on the external drive. I recommend doing a minimal install to get the boot loader set up, then you can either reinstall or add packages to get the system set up the way you want it to.

Once CentOS is on the drive, try to boot from it. You’ll probably have to press a key (on this Asus laptop it is Esc) to choose which drive to boot from. If it won’t boot, you’ll need to adjust the grub settings.

Apparently you can’t change the Windows 7 boot loader. I’m not going to claim this is an authoritative statement, however, installing grub on the Windows 7 drive caused it to fail to boot with a ‘Hard disk error’ (or something similar). This required the Windows 7 recovery disks to recover.

Therefore, you must put the bootloader on the external drive and configure the BIOS to try to boot from the external drive first, with an option to go to Windows.

The problem I had was that by booting off a USB stick the device numbers were a bit off.

Once I had grub loaded on the external drive, I use the find command to determine how the disk was referenced. Then I manually edited the device.map file and grub.conf files after booting into the LiveCD.

For an Asus laptop with Windows 7 on the internal hard disk, and an external USB disk drive, the device.map file looked like this:

It wasn’t really generated by anaconda since I edited it, but that’s okay.

Code

# this device map was generated by anaconda
(hd0)     /dev/sdb

I edited grub.conf using hd0 to refer to the external drive and hd1 to refer to the internal drive.

Code

# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /boot/, eg.
#          root (hd0,0)
#          kernel /vmlinuz-version ro root=/dev/mapper/vg_asuslaptopcentos-lv_ro
ot
#          initrd /initrd-[generic-]version.img
#boot=/dev/sda1
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.32-358.6.2.el6.i686)
  root (hd0,0)
  kernel /vmlinuz-2.6.32-358.6.2.el6.i686 ro root=/dev/mapper/vg_asuslapto
pcentos-lv_root rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD rd_LVM_LV=vg_asuslaptopcent
os/lv_swap SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_LVM_LV=vg_asuslaptopcen
tos/lv_root  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
  initrd /initramfs-2.6.32-358.6.2.el6.i686.img
title CentOS (2.6.32-358.el6.i686)
  root (hd0,0)
  kernel /vmlinuz-2.6.32-358.el6.i686 ro root=/dev/mapper/vg_asuslaptopcen
tos-lv_root rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD rd_LVM_LV=vg_asuslaptopcentos/l
v_swap SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_LVM_LV=vg_asuslaptopcentos/
lv_root  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
  initrd /initramfs-2.6.32-358.el6.i686.img
title Windows 7
  rootnoverify (hd1,1)
  chainloader +1

What I learned:

Drive references may vary based on how the machine was booted.

You can’t just plug an external drive into a different machine and work with it, you may mess up the other machine.

Don’t change the Windows 7 boot loader, although you can use EasyBCD to recover. Maybe.

Taking the time to read the grub documentation is well worth the investment.