How to dual-boot Windows and Fedora, by hand, for the insane

I recently bought a Thinkpad X60 that came with Windows preinstalled. I never actually use Windows, but it’s convenient to have around for the occasional BIOS update.

My Linux distribution of choice has long been Fedora. Unfortunately, unlike other modern Linux distros, Fedora doesn’t provide a simple graphical means to shrink an NTFS partition in its installer.

Since the X60 doesn’t have an optical drive, and I don’t have any USB storage like a memory stick or CD-ROM drive, I couldn’t easily boot into something like Knoppix. If I’d had such gear available, I could easily have shrunk the Windows partition using qtparted. So here are my notes on how to get dual-booting working, by hand, in a bare-bones environment.

Really, if there’s some way you can use a sane all-in-one GUI tool like qtparted to do all of this messy work, you should. You should think of these as the instructions of last resort for the terminally optimistic.

Since I had no suitable media handy, I installed Fedora onto the X60 over the network using PXE. (Getting a PXE server configured sounds scary, but I had one up and serving in less than five minutes on my older laptop. Granted, I’ve done this many times.)

When the Fedora installer (Anaconda) is running, it runs you through a series of questions in text mode, and then starts up an X-based GUI. Don’t run through any of the GUI setup steps yet. Behind the scenes, Anaconda also sets up some virtual terminals, one of which contains a root shell prompt. That root prompt is the key to shrinking your Windows partition.

To get to the virtual terminal with the root prompt, you’ll first need to press the key combination of Control+Alt+F1 to switch to the first virtual terminal. After that, you can press Alt+F2 to get to the second, Alt+F3 the third (I think this is the one where the root prompt lives), and so on. Alt+F6 will bring you back to the GUI.

Once you have a root prompt, you’ll need to find another system, such as the one you’re installing from, and download an ntfsprogs source tarball. Unpack it, and build static binaries. (You must have static binaries, because the install environment doesn’t provide shared libraries.)

tar zxf ntfsprogs-1.13.1.tar.gz
cd ntfsprogs-1.13.1
./configure --enable-really-static

(Don’t forget to make sure that you’re building binaries that can actually run on the machine you’re installing on! If you’re installing an x86_64 version of Fedora, for example, it doesn’t matter whether you build a 32-bit or 64-bit version of ntfsprogs. But the converse is not the case.)

Once the build has finished, find the ntfsresize program in the ntfsprogs subdirectory. This is what you’ll need to get onto the machine you’re installing on.

Go back to the root shell on the system you’re installing onto. Recent versions of Anaconda make ssh and scp commands available from the shell, so you can simply scp the ntfsresize program from the system where you built it into /tmp on the machine you’re installing on.

Before I continue, I must point out what should already be obvious: if you are foolhardy enough to follow any directions after this point, you could completely destroy all data on your disk. Proceed at your own risk! If you have any important data on the system, back it up.

You’ll need to use the fdisk command to find out the name of your Windows partition. If you have a newish machine, it probably contains a SATA drive, so you’ll probably need to invoke it thus:

fdisk /dev/sda

Just type p to print the partition table, and note the name of the big partition (there’s probably only one) that’s marked as HPFS/NTFS. Once you’ve done that, type q to quit out of fdisk.

Let’s assume that /dev/sda1 is your NTFS partition. The next thing to do is use ntfsresize to see what size it is:

/tmp/ntfsresize -i /dev/sda1

This will run for a few seconds, and spit out lots of information. The pertinent line to look for in the output begins with “You might resize at …”. Record that number: it’s the minimum you’re likely to get away with.

Now try a dry run of resizing. Let’s say you’ve chosen ten gigabytes as your target Windows partition size.

/tmp/ntfsresize -n -s 10G

Again, ntfsresize will run for a few seconds, and print lots of information. If it prints an error message, don’t try to follow any directions beyond this point. You’re on your own.

However, if the dry run completes successfully, you ought to be safe to resize the partition. This is the first point at which you can destroy things, so it’s not for the faint of heart. Simply run the same command as before, only without the -n option.

/tmp/ntfsresize -s 10G

This will take a few minutes to run. If it exits with an error message, this might be a good time to take up religion and prayer, or at least to look for your Windows install CD. That is, if your system shipped with one.

Assuming ntfsresize did its job, the next step is even more scary: you’ll have to fiddle with the disk’s partition table so that the NTFS partition’s size matches the size of the actual filesystem. Messing with the partition table is even more scary than resizing filesystems, so dust off that rabbit’s foot your well-meaning aunt gave you.

It’s time to run fdisk again, this time with prejudice.

fdisk /dev/sda

Once again, type p to print the partition table. This time, make a note of the start offset of the NTFS partition.

Next, you’ll need to delete that partition table entry, with d. It will ask you for the number of the partition to delete; if your NTFS partition is on /dev/sda1, you’ll be deleting partition 1.

With that partition table entry gone, you’ll be creating a new, smaller entry to replace it. To get started on this process, use n.

  1. fdisk will ask you whether to create a primary or extended partition. Choose p for primary.
  2. It will prompt you for the start offset of the partition. You must use the same start offset as the old partition had; this is likely to be the default.
  3. When fdisk asks you for an end offset, give it a relative offset that’s the exact same size as you gave earlier to ntfsresize. For example, if you resized to ten gigabytes, type +10G as the end offset.

The new shrunken partition you created will not have an NTFS system ID. Use t from the main fdisk prompt to change its ID. The number to change it to is 7.

Once you’re done, use p to take a look at the new partition table. This won’t actually be written to disk yet. Once you’re sure it looks correct (has the same start offset as before, the correct smaller size, and the right system ID), use w to write out the new partition table and quit fdisk.

In case I haven’t been successful in stating the risks of using fdisk by hand, here are a few charming possibilities for you to consider.

  • fdisk will make no attempt to ensure that your partition table is correct or consistent. Neither, most likely, will your operating system. It’s thus quite possible to accidentally cause your partitions to overlap. This can result in data corruption problems that might not surface until months later.
  • If you hork your partition table badly enough, it can be a pain to subsequently install anything on the system at all. I’ve been forced once or twice to use dd to splatter zeroes all over a partition table in order to get it back to a state where I could do anything with the disk.
  • Don’t say I didn’t warn you!

At this point, you can return to the Anaconda GUI installer by typing Alt+F6. Step through a few install screens. When Anaconda reaches the point of asking you about partitioning, you might be okay to let it partition automatically for you; I haven’t tried this, so I don’t know. I simply go with the custom disk layout option instead, and find to my satisfaction that I now have a big chunk of empty space to fill with swap and ext3 partitions. As you continue through the installation process, Anaconda should automatically set up the boot loader to let you boot into Windows or Linux.

One final thing to bear in mind: the next time you boot into Windows after your install is complete, Windows will probably run chkdsk during boot, to verify that its filesystem is still sane.

Posted in linux
2 comments on “How to dual-boot Windows and Fedora, by hand, for the insane
  1. Peter Berry says:

    Just a small point: you should be able to press Ctrl-Alt-F3 to go directly to the 3rd virtual terminal from Anaconda. I don’t use Fedora though so YMMV.

  2. Paul R. Potts says:

    Thanks for this detailed tutorial! I have a dual-boot Fedora/Win2K desktop configuration that I configured mostly by hand and ran into similar problems trying to rearrange partitions. The tool I wound up using was Paragon Partition Manager; the Symantec tools were useless because they didn’t understand Linux partitions. But this info may come in handy if I try to put Fedora on a new machine.

Leave a Reply

Your email address will not be published. Required fields are marked *