Gentoo Wiki


This article is part of the Dual Boot series.
Install Linux after Windows Install Windows after Linux Using Windows Loader Using GRUB or LILO coLinux

Please format this article according to the guidelines and Wikification suggestions, then remove this notice {{Wikify}} from the article



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,, an easy graphical tool.

Converting to ext2

Unless you're running reiserfs or ext2, you must convert your partition to the ext2 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.

Getting started

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/.

Now unmount the drive, umount /mnt/gentoo.


Now we can proceed with the conversion:

If your partition is...

  • Ext3
    • To convert ext3 to ext2 just run:
tune2fs -O ^has_journal /dev/hdxx
  • Xfs, minix, jfs, reiserfs
    • reiserfs, at least, has a native resize tool (resize_reiserfs). You do NOT need to convert a reiserfs partition. The same may be true of other filesystems. Converting filesystems is dangerous and should be avoided if at all possible; consider using resize_reiserfs instead.
    • To convert another filesystem to ext2:
cd /tmp/
./convertfs /dev/hdxx current_fs ext2

After the conversion is done its probably a good idea to run fsck

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.


Example: resize2fs -p /dev/hda3 20G


Note: Do not use ext2resize if you already used resize2fs.

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...

  • Ext2
    • Just leave it! Your partition is already ext2.
  • Ext3
    • To convert ext2 to ext3 just run:
tune2fs -O has_journal /dev/hdxx
  • Xfs, minix, jfs, reiserfs
    • For the rest of the filesystems just run:
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)
Partition number (1-4): 4
First cylinder (1-3876): (Hit Enter)
Last cylinder or +size or +sizeM or +sizeK (1-3876):  (Hit Enter)
Partition number (1-4): 4
Partition type: 07

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.

Reinstall grub.

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.

Installing Windows

Next insert your Windows XP disc and start the install.

If it hangs read HOWTO install Windows after Gentoo if setup hangs after displaying "Setup is inspecting your computer’s hardware configuration".

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).

Re-install bootloader

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)
chainloader +1

Remember to change the "rootnoverify (hd0,3)" accordingly. In this example the Windows boot partition is /dev/hda4.

Note: *On my system I have been playing around with the partition. After Windows install and grub reinstall my partition table was reordered differenttly than my previous setup before windows install. I have to edit my menu.lst(or grub.conf) and fstab for the system to work properly since the previous setup pointed to the wrong partition


This is for Lilo users. To reinstall Lilo to your MBR:

mount /dev/hdxx /mnt/gentoo
chroot /mnt/gentoo
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:

# /sbin/lilo

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

# /sbin/lilo

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 :)

See also

HOWTO Dual boot

HOWTO Dual Boot from Windows Bootloader (NTLDR) and why

HOWTO nvidia raid dual boot

Qemu avoids dual booting at the expense of speed.


Retrieved from ""

Last modified: Fri, 05 Sep 2008 21:01:00 +0000 Hits: 75,697