Disclaimer: This procedure can render your computer unbootable and corrupt your data if you do it wrong. Perform a backup prior to doing it and verify you can read the backup. Don’t attempt it on a critical laptop. I am in no way responsible if you attempt this and end up with an expensive brick or it results in data loss.

The scenario:

1 Dell Latitude D610 with a 60GB HDD
1 IT Guy about to go on holiday but not wanting just to take a Windows XP box

The dream:

Shrink the XP install down to 30GB and use the new volume to install Fedora 9. Keep the standard windows boot loader (i.e. Nothing to see here move along)

The how:

  1. Boot XP and run disk check (chkdsk c:) on the volume you want to shrink – this is a good idea
  2. Boot XP and run defrag (defrag c:) till it’s as contiguous volume as it’s going to be
  3. Grab a Knoppix CD and boot from it
  4. In Knoppix get a root console and do the following
  5. use fdisk -l to get the hard disk volumes – in my case it’s /dev/sda
  6. fdisk -l
    
    Disk /dev/sda: 60.0 GB, 60011642880 bytes
    255 heads, 63 sectors/track, 7296 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Disk identifier: 0x41ab2316
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1               1           8       64228+  de  Dell Utility
    /dev/sda2   *           9        7296     XXXXXXX  7  HPFS/NTFS
    
  7. Use ntfsresize --info /dev/sda2 to get the minimum size of what you can shrink it to. We will be leaving the Dell Utility partition alone the C: drive is /dev/sda2
  8. ntfsresize --info /dev/sda2
  9. In this case I didn’t go to the minimum size I just divided the hard disk in half 60011642880/2 = 30005821440
  10. Use ntfsresize -s 30005821440 -n /dev/sda2 to test (-n or not really) if it seems OK
  11. ntfsresize -s 30005821440 -n /dev/sda2
  12. Then run ntfsresize -s <size IN BYTES> /dev/sda2 to do it for real
  13. ntfsresize -s 30005821440 /dev/sda2
  14. When it’s finished make a note of the new partition size in MiB that it has created you need this for fdisk
  15. run fdisk /dev/sda, make note if the partition you are shrinking has the bootable flag, partition type (7) and start sector. Delete the old partition (/dev/sda2)
  16. Create a new partition with the new partition size as specified by the output of the previous ntfsresize operation. When entering the partition size use +<size IN MiB>M e.g. (+28616M note: This size is a guess I am writing this from memory make sure you use the size recommended by ntfsresize as the size of the new partition), mark it bootable if it was before and set it to be NTFS (type 7). When it’s right, commit it to disk
  17. Reboot back into Windows twice. It will run chkdsk the first time and find new hardware, the second time is just to make sure it’s all in a consistent state
  18. Now install Fedora 9 onto the empty part of the hard disk. When prompted for the location of the GRUB bootloader code choose the /dev/sda3 partition which is the /boot partition of the linux installation. Don’t chose to install the GRUB bootloader to the MBR as this will wipe out your Windows bootloader
  19. Once you reboot you will find that you still have your Windows bootloader but no option to select Fedora 9 from the Windows boot menu.
  20. Here is a fdisk /dev/sda listing after installing Fedora 9
  21. fdisk /dev/sda
    
    Disk /dev/sda: 60.0 GB, 60011642880 bytes
    255 heads, 63 sectors/track, 7296 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Disk identifier: 0x41ab2316
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1               1           8       64228+  de  Dell Utility
    /dev/sda2   *           9        3829    30692182+   7  HPFS/NTFS
    /dev/sda3            3830        3854      200812+  83  Linux
    /dev/sda4            3855        7296    27647865    5  Extended
    /dev/sda5            3855        7296    27647833+  8e  Linux LVM
  22. Using the Knoppix CD once again boot into Knoppix and gain a root console
  23. You now need to take a copy of the GRUB bootloader from /dev/sda3
  24. Plug a USB key in and copy the bootloader to it with dd if=/dev/sda3 of=/media/MYKEY/bootsect.bin count=1 bs=512 – I think these days you could mount and write straight to the NTFS partition but when I tried to get Knoppix to write directly to the NTFS partition it complained that the volume was dirty. This, I think, was because I had power cycled when Windows XP was half booted, so I just used the USB key to get a copy of the GRUB bootloader.
  25. dd if=/dev/sda3 of=/media/MYKEY/bootsect.bin count=1 bs=512
  26. Booting back into Windows copy the bootsect.bin file from the USB key to c:\
  27. Then making sure Windows Explorer has the show hidden files option enabled and hide system files disabled find c:\boot.ini, remove the readonly attribute, and add a Fedora 9 entry to it pointing to the Linux bootsector thusly:
  28. [boot loader]
    timeout=30
    default=multi(0)disk(0)rdisk(0)partition(2)\WINDOWS
    [operating systems]
    multi(0)disk(0)rdisk(0)partition(2)\WINDOWS="Microsoft Windows XP Professional" /noexecute=optin /fastdetect
    C:\bootsect.bin="Fedora 9"
  29. After another reboot you should now have both OS options on your standard Windows boot menu

The result:
I can now go on holidays with a dual boot Laptop containing a standard work OS and a Fedora 9 environment. If I need to give the laptop over to anyone, I can remove the boot.ini entry and hand it to them.

PS. Fedora 9 found the Intel wireless and I could connect straight up to my WAP with no issues. GNU/Linux Rocks!