PREAMBLE
Lots of people have detailed how to install
Linux onto a PC that already has Windows on it, such as a new PC bought
from a shop. Usually this is written from a Windows user's perspective.
1) MAKE SPACE FOR
WINDOWS ON YOUR HARD DISK
I'm assuming that your entire hard disk is
taken up with Linux and you don't have any FAT32/NTFS partitions at
all.
First off, you need to free at
least 5Gb or so in which to install Windows. Linux lacks a tool to
repartition on the fly (I'm sure there's a Sourceforge project but, if
there is, I wouldn't trust it with my valuable data until it's REALLY
well established).
You can use a proprietary program
like Partition Magic to do the
job
although you'll have to make sure it understands Linux partition types.
Only more recent versions of Partition Magic will deal with Ext3 and
it's not clear if the likes of ReiserFS or XFS are supported. Check
before splashing out for new software.
The product info page for Partition Magic lists Windows as a system requirement but this is not fully correct. On version 8.0, which I have here, you can boot from the CD and run Partition Magic from there (this boots into Caldera DOS, supplied on the CD, so no Windows bits & pieces are needed at all). Using this version of Partition Magic is just like using the Windows program, complete with mouse operation.
Alternatively you can just delete
one of your Linux partitions. The obvious candidate on many Linux
installs is the /home partition - move everything from there into your
main Linux boot partition and blank it using Linux's fdisk (and remove the
entry from fstab, of course). Or you could copy everything to the root partition, delete /home, and then recreate it but this time much smaller. It's up to you.
FWIW I use cfdisk
rather than fdisk - it uses a curses GUI interface which makes the
whole procedure easier to follow, particularly when dealing with free
space, although some people say that cfdisk isn't as reliable as fdisk.
Note: don't try to make a
FAT32/NTFS partition using Linux's fdisk or cfdisk. Windows won't
recognise it. This task needs to be done under Windows itself. Talking
of which...
2) MAKE A NEW
PARTITION
Boot from your Windows CD. When the Windows
pre-installation routine has finished loading every possible disk
driver in the world ever, DON'T choose to install. Instead choose to
boot to the Rescue console. When you get to the command prompt, type:
diskpart
This should give you a curses-style graphical display
of the disk. Notice how your Linux partitions are unidentifiable by
Windows but how it still gives them drive letters (!).
You should spot the free space
you created earlier. Use the cursor keys to move to it so it's
highlighted. Hit C to create a new partition. You might get asked a few
questions so answer them using common sense. Note how Windows will
instantly rewrite the partition table without asking you to confirm it,
or waiting until a later stage when you can confirm all your changes in
one fell swoop. Make a note of the drive letter which Windows assigns
to the new partition.
Note: weird things can happen at
this stage and this is where things are most likely to go catastrophically wrong. On my PC, I tried to create a new partition from all the
available space (around 13Gb), and Windows instead split it into a 5Gb
partition alongside 8Gb of free space. Without asking or telling me, of course. This might be something to do
with FAT or NTFS
limitations. In the end, to complete the next step of this tutorial, I
chose the 5Gb partition to install into, which worked fine.
3) FORMATTING
After you've created your partition, quit
out. I think you have to press F3 or something. You'll have to reboot
so do so. At this point your boot sector will have been wiped so
GRUB/lilo will be no more, and you'll find you can't boot into
Linux. DON'T WORRY! We'll fix it later (hopefully).
Boot from the Windows disk again
and go to the Rescue console again. This time type
format {drive letter}: /FS:fat32
where "drive letter" is what you wrote down earlier.
This will format the partition to FAT32. Both Win2K and XP can work
under FAT32, even if Microsoft advises you use NTFS. Why choose FAT32? Well,
it's natively supported in the kernel so you can mount it later under
Linux and copy files to and from. NTFS support under Linux is VERY
DODGY - you can usually read okay but writing to NTFS from Linux is not
advised. (Note that FAT32 support is only in the kernel if it's been
compiled into it - most distro kernels should provide support but if
you've made your own kernel then, obviously, check your config file).
When the formatting starts, you
will see a message saying that it's going to format the "drive". It's
not. It's just going to format the partition. Formatting will take a
while depending on your partition size so go and make a cup of tea.
4) INSTALLING
When formatting has finished, type exit and
reboot. Then boot from the Windows CD again. This time select to go for
the full install and identify your brand spanking new Windows partition
when prompted.
There's no need to format it
again, so select to use it as is. Then get on with installing Windows!
5) BACK TO THE
WINDOWS CD...
At this point you can boot into Windows and
use it normally - visit Windowsupdate, reboot, install your virus
scanner, reboot, visit Windowsupdate again, reboot, install a firewall,
reboot, visit Windowsupdate once more, reboot, and so on.
However, we want to get back to
Linux! But we've got to make sure the Windows partition will be
bootable when we restore Linux to its rightful place as king of the
hard disk.
I know what you're thinking - how
can we have just booted to Windows if it's not bootable? Well, Windows
will have written a boot sector to the MBR and possibly not to its own
partition. We're going to put GRUB onto the MBR. So we need to ensure there's a
Windows boot sector onto the Windows partition so we can point GRUB at it later on.
Luckily, this is easily done. But
you're going to have to boot from that Windows CD again... Choose to go
to the Rescue console and, when prompted, type in the partition number
of your new Windows install. Enter the administrator password and, at
the command prompt, type
fixboot {driveletter}:
As you'll see from the on-screen prompt, this will
install a bit of boot code onto the partition.
6) BACK TO LINUX
Almost there now...! Insert your Linux
rescue disk (or CD-ROM) and boot. If you're using Red Hat or Fedora
Core 1, you should automatically find your Linux partition mounted
within /mnt/sysimage. Don't worry if you get a message that no Linux
partition was found - sometimes it can be missed if it's in an extended
partition. In this case just type:
mkdir /mnt/sysimage
mount /dev/hdax /mnt/sysimage
(Where x is the partition number of your Linux root partition - you can find this out by typing fdisk -l /dev/hda)./grub-install /dev/hda
This will restore the GRUB bootloader program and
menu.
7) BACK TO WIN2K/XP
But, but... you can now boot Linux but can
no longer boot Win2K. Don't worry - the solution is simple.
Boot into Linux and switch to
root user. Edit your GRUB config file (in the following way if you're
using Red Hat/Fedora):
vi /boot/grub/grub.conf
I'm not going
to explain the ins and outs of grub.conf but, needless to say, you need
to add an entry for your Windows partition. Here's what does the trick
on my machine (I added this underneath the current entry for Linux):
title Windows 2000
root (hd0,1)
makeactive
chainloader +1