|Install Linux after Windows • Install Windows after Linux • Using Windows Loader • Using GRUB or LILO • coLinux|
For this HOWTO I will assume that your root partition extends to the end of your drive. If you have enough unpartitioned space to install Windows on then please skip down to the Creating the Windows Partition section. In this HOWTO's example we will be installing Windows XP Professional.
If installing Windows 2000, and probably XP, you'll need to have some extra partition space as a primary partition, not an extended partion. If you've already created more than three primary partitions, or simply want your Windows XP in an extended partition.
Tool for partitioning
You can use Gparted, http://gparted.sourceforge.net, an easy graphical tool.
Converting to ext2
Unless you're running reiserfs or ext2, you must convert your partition to the ext2 filesystem.
- Before we convert the filesystem you should run an integrity check of your partition.
- reiserfsck: program is used to check and repair a linux reiserfs filesystem.
- xfs_repair: program is used to repair a linux xfs filesystem.
- fsck.jfs: program is used to check and repair a linux jfs filesystem.
- e2fsck: program is used to check and repair a linux ext2 or ext3 filesystem
This can corrupt filesystems. Always backup your data.
It may be easier to use a tool such as Gparted or qtparted rather than following this process. You do NOT need to convert reiserfs to ext2, it has native shrink support.
First emerge -av convertfs ext2resize e2fsprogs. Next, get yourself a Gentoo LiveCD. Reboot with the cd in the drive. Mount your root partition mount /dev/hdxx /mnt/gentoo.
Now copy the following files from /mnt/gentoo/sbin/ to /tmp/.
- convertfs (rename it because convertfs will make a new directory with the same name in /tmp)
Now unmount the drive, umount /mnt/gentoo.
Now we can proceed with the conversion:
If your partition is...
tune2fs -O ^has_journal /dev/hdxx
cd /tmp/ ./convertfs /dev/hdxx current_fs ext2
After the conversion is done its probably a good idea to run fsck
- e2fsck program is used to check and repair a linux ext2 or ext3 filesystem.
So something like:
e2fsck -f /dev/hdxx
Resizing the filesystem
Next we need to free up some space on the root partition for windows. This can be done with either ext2resize or resize2fs. The latter is recommended since you can specify the size in GB, KB, MB or blocks, while ext2resize only supports blocks.
- The syntax for using is: resize2fs -p <device> <newsize>
- For <newsize> use G for GB, M for MB, K for KB and s for blocks.
Example: resize2fs -p /dev/hda3 20G
- NOTE PLEASE CHECK THE SIZE UNIT FLAGS "s" is not for "blocks" "s" designates sectors
- not specifying a size flag defaults to the filesystem block size, therefore,
- no flag => blocks!!!!! RTFM "man resize2fs"
Note: Do not use ext2resize if you already used resize2fs.
- The syntax is: ext2resize <device> <newsize>
- <newsize> must be in blocks.
Example: ext2resize /dev/hda3 1048576
How to get "1048576"?
1 GB = 1024 x 1024 x 1024
(((1024 x 1024 x 1024) x Disk space in GB)) / Blocksize)
To get the blocksize of your harddisk, simply type:
dumpe2fs -h /dev/hdxx
So if you wanted your root partition to be 20GB and your Blocksize was 4096 you would take:
(((1024 x 1024 x 1024) x 20) / 4096) = 5242880
Now that we have our desired size we will run the ext2resize program.
/tmp/ext2resize /dev/hdxx 5242880 e2fsck -f /dev/hdxx
Shrinking the partition
Shrinking a filesystem does not generally shrink the partition it is on. You may need to use parted, fdisk, etc, to shrink the partition down to the size of the filesystem. This is dangerous. As always, keep backups.
If you used resize2fs you will need to use fdisk to recreate the partition. To keep your data, you must start the partition on the same cylinder.
fdisk /dev/hdx p to see your current partitions d select your partition you are resizing n new partition p for primary, then your partition number +20480M make sure to start this resized partition at the same cylinder or all your data will be lost, M for MB w write the new partition table to disc
Check the partition when you are finished with e2fsck -f /dev/hdxx. If you get an error about differing filesystem and partition sizes, you may need to resize your file system again. See Shrinking reiserfs partition HOW-TO for a good description for how to calculate the end point of a reiserfs partition.
Re-converting the partition
It is time to re-convert our partition to its old filesystem.
If you want your partition to be...
tune2fs -O has_journal /dev/hdxx
cd /tmp/ ./convertfs /dev/hdxx ext2 desired_filesystem
Be sure to run the filesystem integrity check after re-converting.
Creating the Windows Partition (primary)
Great! Now that you have space on your drive for Windows you would think you could slap in your Setup disc and start installing, right? Wrong!
The Windows XP (but not Vista) disc will give you an error when you try to create your NTFS partition on the unformatted space stating: “This disk has reached the maximum number of partitions on the disk”. Windows doesnt seem to like being put on the end of the drive but we are going to make it!
If you create the NTFS partition while you are still booted to your LiveCD Windows will recognize that partition later, when you try to install and let you continue (even though it is passed its "maximum" number of partitions).
To do this we will:
fdisk /dev/hdx Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 4 First cylinder (1-3876): (Hit Enter) Last cylinder or +size or +sizeM or +sizeK (1-3876): (Hit Enter) t Partition number (1-4): 4 Partition type: 07 w
This will create a NTFS partition at the end of your drive that you can now install Windows on.
Creating the windows partition (extended)
It is not a requirement to have the whole Windows in a primary partition, however and as far as I know, the boot loader NTLDR needs to be there. It only requires about 10 MB on my computer (with XP SP2 Pro). So that if you have only two primary partitions but no room left for XP, you can shrink one of the existing and have NTLDR there. Another solution (which I have not tried but should work) is to move your /boot partition away and boot linux with NTLDR.
Note: NTLDR will not boot at all with Windows installed on an extended partition. If you install GRUB after the 1st WinXP installation reboot then it will work
Shrink an existing partition
To boot Linux, in principle, 32 MB is enough for your Linux /boot partition so if you have made it like 64 MB or 50 MB, you can take some place off it. The first thing to do is to save the data from /boot and put it, e.g., in your ~ directory. Also note that you should still have backups available... as always.
su - mount /boot mkdir ~/boot.d cp -Rvi /boot/* ~/boot.d
It is good to verify that nothing has been forgotten.
Then fdisk, make your smaller /boot partition and something like a 15 MB partition for NTLDR. It is a good idea to make both partitions where you want windows FAT32 (LBA), so that the windows install sees them. Mind that the installer is going to tell you you have no OSes where Linux actually sits and is going to be happy to just format it, so that you get yourself a `real' OS as Microsoft understands it. It is however useless to format the new partitions, the installer will do it.
Install Windows, you will probably need to delete both partitions, but since you have made them visible to the installer, there is fewer risks you delete one you use for Linux, and tell the Windows installer to have XP in the big partition, it will then format both for NTLDR and the OS.
Reboot into Linux from the CD to reinstall your /boot partition
mkdir /mnt/gentoo/boot mount /dev/hda#B /mnt/gentoo/boot mkdir /mnt/gentoo/toto mount /dev/hda#R /mnt/gentoo/toto cp -Rvi /mnt/gentoo/toto/boot.d/* /mnt/gentoo/boot
where #B is your /boot partition and #R is your /root partition.
Boot Linux with NTLDR
Copy-save your existing /boot partition as stated above, so that whatever happens you can return your computer to its original state.
Then read here: HOWTO Dual Boot from Windows Bootloader (NTLDR) and why.
I believe there is an alternative, which would consist in cloning the NTLDR partition wherever, and keep booting with grub. However, I have no experience with that and wish somebody else writes this HOWTO.
The interested reader can start by following the link I gave in the links section at the bottom, which is of general interest anyway.
Next insert your Windows XP disc and start the install.
Select that you would like to use the NTFS partition that we created and it will ask you to format it in NTFS again and if you would like it to do it "Quick" or "Normally". I usually just choose quick.
After it finishes installing you will have both Gentoo and Windows XP on your system... HOWEVER Windows has written over your MBR so when your computer turns on it boots straight into Windows.
To fix this you will need to reinstall your bootloader (Grub or Lilo).
Boot back into your Gentoo LiveCD.
This is for Grub users. To reinstall Grub to your MBR, chroot to your linux install as described in the install handbook, and then:
# grub grub> root (hd0,0) grub> setup (hd0) grub> quit
Chrooting is vital, especially if you're using a different livecd, to ensure that it pulls the grub stages from the right place.
The two digits in "root (hd0,0)" correspond to the Gentoo boot partition located on /dev/hda1. The first digit maps as per the examples: 0=>/dev/hdax, 1=/dev/hdbx, 2=/dev/hdcx etc., the second digit maps: 0=>/dev/hdx1, 1=>/dev/hdx2, 2=>/dev/hdx3 etc. Change this accordingly.
Next you are going to need to edit your grub.conf:
# mount /dev/hdxx /mnt/gentoo/boot (Where /dev/hdxx is your boot partition) # nano -w /mnt/gentoo/boot/grub/grub.conf
And add the following:
title Windows XP rootnoverify (hd0,3) makeactive chainloader +1
Remember to change the "rootnoverify (hd0,3)" accordingly. In this example the Windows boot partition is /dev/hda4.
This is for Lilo users. To reinstall Lilo to your MBR:
mount /dev/hdxx /mnt/gentoo chroot /mnt/gentoo env-update emerge --usepkg lilo
Next you are going to need to edit your /etc/lilo.conf
# nano -w /etc/lilo.conf
And add the following:
Finally you have to run lilo to update your MBR:
For those using software RAID on SATA drives:
You need to load the appropriate RAID modules (RAID0 in my case)
# modprobe raid0
Now you need to create the RAID device your root partition is on (/dev/md1 for me)
# mknod /dev/md1 b 9 1
Then initialise the array with mdadm. Change sdaX and sdcX to reflect your setup.
# mdadm -A /dev/md1 /dev/sda1 /dev/sdc1
Next, mount the partition:
# mount /dev/md1 /mnt/gentoo
Don't forget to mount the proc filesystem. This is important.
# mount -t proc proc /mnt/gentoo/proc
Now chroot into your existing system.
# chroot /mnt/gentoo /bin/bash # env-update
I did not need to re-merge lilo as mentioned above. Simply edit your lilo.conf as above, then
and you should be done.
You should now be able to turn on your computer and have your Linux bootloader give you the option of booting into either Gentoo or Windows. Enjoy :)
Qemu avoids dual booting at the expense of speed.
- Installing a copy of Windows 2000/XP on a Spare Partition (after installing Linux).
- How To Clone Windows XP/2000 Installations.
- Forking a XP-installation.
- Resizing root partition: scroll down to bottom for a very useful post with examples by 'widesteps'.
- Understanding MultiBooting and Booting Windows from an Extended Partition
- GAG, the graphical boot manager fits in the MBR.
Created by NickStallman.net, Luxury Homes Australia
Real estate agents should list their apartments, townhouses and units in Australia.