Windows-CD will not boot after installing Ubuntu.

Asked by Matthias Niess

To reproduce:
- Use a blank (i.e. new) harddisk and start the Ubuntu live-CD.
- Use gparted to create some partitions (when asked for partition table type I use MSDOS - the default)

At this point (no matter if you install Ubuntu or not) no Windows-CD will be able to boot as long as the harddrive you just partitioned is connected to the SATA-controller.

The only way I found to solve this is to destroy the partition table with
dd if=/dev/zero of=/dev/sda

Now I have a dual-boot computer which crashed in Windows and thus started fsck on Ubuntus boot (correcting minor problems.. all partitions and data are still okay). On that computer Windows won't boot anymore and neither will Windows-CDs.

The only thing I can think of is that Windows XP device-drivers can't access a harddisk as soon as gparted of fsck have done a certain thing to the harddisk. From what I could find on Google, Vista can read such disks without any problems.

So does anyone have a clue what change exactly (to the partition table?) is responsible for Windows-CDs not booting?

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu Edit question
Assignee:
No assignee Edit question
Solved by:
Laeg
Solved:
Last query:
Last reply:
Revision history for this message
Guillermo Belli (glock24) said :
#1

I had a similar problem with my portable computer (Compal HEL80) on a new WD 160GB disk, a BIOS update solved the problem.

Don't know what exactly caused it, but XP would only install on a blank disk. If I created the partitions first with the Ubuntu CD first, the XP CD would not load.

You can try installing XP first, create the Windows partition with the XP installer and leave free space to install Ubuntu afterwards. After XP is installed, try installing Ubuntu on the free space.

Revision history for this message
Matthias Niess (mniess) said :
#2

Hi Guillermo,

this does not solve my problem. In my original post I already wrote how to fix this (destroy part table with dd). Of course when I set up a new computer it is best to install Windows first. But now I have a computer with lots of data on it (in Ubuntu partition) and I'm looking for a way that avoids forcing me to reinstall everything (including Ubuntu).

Revision history for this message
Matthias Niess (mniess) said :
#3

To clarify: the reproduce steps in the original post were just to reproduce the problem. My problem itself is further down in the text.

So if you want to reproduce this and have an old unused SATA drive lying around:
- pop it in and run dd if=/dev/zero of=/dev/sdX (replacing X with the drives actual number)
- the drive looks "new" to gparted now so start up gparted and create some partitions
Now as long as this drive is connected you won't be able to boot from any Windows XP CD. It will just hang at the point were the screen is still black and it looks at the hardware configuration (right after pressing SPACE to boot from the CD).

Revision history for this message
W. Prins (wprins) said :
#4

Which version of the XP CD are you booting with? Original, SP1, or SP2 boot image? I'll see if I can reproduce this.

Revision history for this message
Guillermo Belli (glock24) said :
#5

As I understand, you can still boot to Ubuntu.

So, from what you describe it is the same problem I had, a Windows CD won't boot if you create the partitions using gparted; but if you destroy the partition table, say the disk is blank, only then will the Windows CD boot, right?

The only way I could fix this for good was with a BIOS update for the computer. Also, using another disk (not the same brand) this did not happen, so I suspect it is some bug in the BIOS code, or gparted messes up the MBR with some disk/BIOS combination.

Revision history for this message
Wyatt Smith (wyatt-smith) said :
#6

I have also noticed the problem that you are talking about. I have not been able to reproduce it with WinXP Pro SP2. I believe that part of the problem with gparted is that does not actually perform a full format of the partition. Anyhow if you can mount the drive from ubuntu, I would use ubuntu to extract and backup any important data that you have.

I am wondering if it is better to just delete the partition in gparted rather than format it. You windows may work better if the space is listed a just a raw unused partition. I am just speculating since I can´t reproduce this on my machine.

Also be careful with that the dd command that you posted. I believe that this will zero out the entire drive unless you use these flags

dd if=/dev/zero of=/dev/sdX bs=512 count=1

This will only zero out the MBR.

Revision history for this message
Matthias Niess (mniess) said :
#7

Hi thanks for all the information. The Windows-CDs I used, where all I could find. I tried an original SP2, a slipstreamed SP3 and a Home SP1 OEM CD.

On that machine I can still boot Ubuntu, right! I haven't tried a BIOS-Update, yet. But I remember when the problem first appeared (about a year ago) no BIOS update was available (leading me to blanking the disk and reinstalling everything). I wouldn't want to reinstall now because I don't have the time to set it all up again and spend 99% time in Ubuntu anyway. I just use Windows for the occasional game.

@Wyatt: I'mm well aware that the command I supplied will zero out the whole disk. I'm just too lazy to type it all and just kill the command after a couple of seconds ;)

Well, anyway. I'll report back with BIOS-Update news.

Revision history for this message
W. Prins (wprins) said :
#8

Well, with some jiggery pokery it would be possible to use dd to a) backup then b) only wipe the partition table, then boot with the windows cd, then create any partition table with Windows, that it will understand, then restore the entries in the partition table by hand onto the Windows created partition table, thereby sidestepping the problem. If you'd like to try this, then I'll try to be of more assistance. You should in that case probably download the Ubuntu rescue remix as it has useful extra disk tools on. (Here: http://ubuntu-rescue-remix.org/)

Revision history for this message
Matthias Niess (mniess) said :
#9

Hi everyone. Sorry for taking such a long time. So I updated the BIOS now.. didn't solve the problem. As far as I can see I have two options now. A) Reformating the harddisk and starting all over again and B) going with Walter Prins suggestion.

I've got a backup of all data so I'd like to try what Walter wrote. Do you have any pointers for me? Here is what I would do so far (and know how to do):
- backup and wipe partition table (first 512 bytes, right?)
- create one primary partition exactly like the one I had for Windows before.. of course without formatting that new partition
- boot back to the live-cd (i.e. rescue remix) and read the new MBR to a file.
(- compare both of the MBRs)

Now the last point is the hard one ;) Are there any tools to easily do this. What editor would I use? Any HEX editor to recommend?

Revision history for this message
Matthias Niess (mniess) said :
#10

Here's some additional information I found out just yesterday.. maybe it can help resolve the problem:
sudo sfdisk -V gives the following output
partition [6]: start: (c,h,s) expected (1023,254,63) found (1023,0,1)
partition [7]: start: (c,h,s) expected (1023,254,63) found (1023,0,1)
/dev/sda: OK

This looks kind of wrong to me. Maybe there's something wrong with the extended partition table?

Revision history for this message
W. Prins (wprins) said :
#11

Hmm, re the sfdisk output: Something fishy going on... Might indeed be possible to directly fix it, if indeed that is the problem stopping XP booting.

Anyway, if you have a full backup, you can proceed as follows:

Backup current partition table:
1.) Open a terminal window. Enter:
sudo dd if=/dev/sda of=partitiontable.img bs=512 count=1
chown username:username partitiontable.img
2.) Copy this file someplace you can access it again from a liveCD if need be (a USB key maybe.)
3.) Now enter:
sudo dd if=/dev/zero of=/dev/sda bs=512 count=1
(be very careful with this command - getting it wrong can wipe out your data. Particularly the count=1 and the bs=512.)

OK, now we have several options to try and fix the issue you're having. My first suggestion is to use "testdisk", which is a tool on the Ubuntu Rescue remix that searches for lost partitions and will rebuild your partition table from scratch. So, boot from the Ubuntu Rescue remix, and at the prompt enter:
testdisk

Follow the onscreen menu's and it should find and offer to recover your XP (and other) partitions on the disk.
After recovery, also check that the XP partition is marked as "Active"/"Bootable". After doing that boot with the XP CD into the recovery console and run "fixboot" and "fixmbr". Then see if your XP partition will boot again.

Revision history for this message
Matthias Niess (mniess) said :
#12

Hi Walter. I tried your suggestion but unfortunately the MBR created by testdisk won't let the Windows-CD boot either. Putting the old MBR back in place of course lets me boot Ubuntu again. Any more ideas?

Revision history for this message
W. Prins (wprins) said :
#13

Sorry for only replying now, have been away and been rather busy so haven't had time to deal with Launchpad issues the last few days.

Anyway, I do have some further suggestions, if you still have the issue and would still like to try to solve it.

1.) Firstly, let's save the exact start/ending of your current partition. From a prompt do:

sudo sfdisk -d /dev/sda >partitions.txt

This dumps the partition table structure to a file that is human readable but also suitable for later input to sfdisk. Copy that file (partitions.txt) someplace safe (e.g. a USB key or such). I trust you know how to deal with that, if not let me know.

2.) Next, wipe your current partition table out, like you did before:
sudo dd if=/dev/zero of=/dev/sda bs=512 count=1
(be very careful with this command - getting it wrong can wipe out your data. Particularly the count=1 and the bs=512.)

3.) Next, we have to create an acceptable (to XP) partition table. The easiest is probably to use Windows XP's fdisk, or it's installer. But be careful not to format any newly created partitions. ONLY the partition table should be created. Alternatively, I can post a snapshot/image of a working XP partition table tonight, which we can use instead. If you'd rather do that, then you'll have to wait until I'm home tonight so I can do the neccesary snapshotting/posting.

4.) Restore your partition table entries from the file saved above:
sudo sfdisk </path/to/folder/with/partitions.txt
(You need to replace the path above as appropriate to locate the file "partitions.txt")

5.) Check over the resultant partition table with e.g. "cfdisk";
sudo cfdisk

Make sure only the window partition is marked bootable/active and that everything else seems in order. Then try to reboot and see what happens.

Revision history for this message
Best Laeg (kay-werndli) said :
#14

Hi everyone

I had the exact same problem with two laptops. On one of them, there is a partition with Ubuntu Intrepid x64 and another one with Vista x64 on it. The other one is running under Ubuntu Hardy x86. Now, I wanted to install WinXP on the one-OS box but couldn't boot from any XP-CD I tried on either laptop. After doing a little googling, it turned out that the XP-CD has some trouble with extended partitions and in fact, I used extended partitions on both laptops.

Now, I tried Walters method and used several tools to create an acceptable partition table but nothing seemed to work out. So I started playing with the partition tables a bit and found a method that did the trick.

Boot your PC with a Linux-LiveCD (I used the GParted-LiveCD but Ubuntu will also work). Now launch a terminal and run "fdisk -l". The output may look something like this:
   Device Boot Start End Blocks Id System
/dev/sda1 * 1 3916 31455238+ 7 HPFS/NTFS
/dev/sda2 3917 26109 178265272+ 7 HPFS/NTFS
/dev/sda3 26110 27976 14996677+ 83 Linux
/dev/sda4 27977 38913 87851452+ 5 Extended
/dev/sda5 27977 38390 83650423+ 83 Linux
/dev/sda6 38391 38414 192748+ 83 Linux
/dev/sda7 38415 38913 4008186 82 Linux swap / Solaris

The important part is the partition wich has "5" as it's ID (i.e. is an "Extended" partition) which is /dev/sda4 in this case. Now type "sfdisk --change-id /dev/sda 4 fa" with "4" replaced by the number of your extended partition. This will set the type of /dev/sda4 to "fa" which is an unknown file system type. Don't worry if all the logical partitions in your extended one won't show up after this.

Now you can reboot and the Windows CD should start just fine. After installing Windows (on /dev/sda1 in my case) I simply ran the LiveCD again and typed "sfdisk --change-id /dev/sda 4 5" to set the type of /dev/sda4 to "Extended" again. Then all your logical partitions will be visible again.

Hope that helped.

So long,
Laeg

Revision history for this message
Matthias Niess (mniess) said :
#15

Thanks Laeg, that solved my question.

Revision history for this message
Matthias Niess (mniess) said :
#16

Hi, I didn't have too much time lately, to look into this any further. Your workaround, is going to help me save hours, though. So thanks alot!

Revision history for this message
Laeg (kay-werndli) said :
#17

Hi again

Now, there seems to be another problem. After installing Windows and restoring the partition table, it turns out that Windows XP itself won't boot if there is an extended partition on the hdd. I have no clue what is going on because I'm pretty sure that Windows supports extended partitions (in fact on two other laptops I own, this works smooth and never made any problems at all). However, normally it won't be a big deal to work your way around it but there is an exception (which was the case on my laptop). The first (easy) case is when your boot-partition (if you have one) i.e. the partition which is mounted as "/boot" under Ubuntu is a primary partition. I guess that this is the case for most systems since normally, there is no reason to have a separate boot-partition and so everything's on the root-partition, which should be a primary one for most systems. The second case is rather complicated (for me!) and in fact I couldn't really resolve it directly, but had to reduce it to the first case (which might not be possible for everyone). However, here's what one can do. I will use the same partition table as in the last post, where sda1, sda2 and sda3 are primary partitions, sda4 is an extended one and all the others are logical partitions, contained in sda4.

Case 1: Let's assume that sda3 is the partition containing all the files in your /boot directory (so it's either a separate boot-partition or it's the root-partition and all your stuff is on there). Now boot to Ubuntu, open a terminal and write "gksudo gedit /boot/grub/menu.lst" and scroll down to the end of this file. There you'll probably find some lines looking like this:

title Windows XP Professional (loader)
root (hd0,0)
savedefault
makeactive
chainloader +1

Simply add a line "hide (hd0,3)" (where "3" needs to be replaced by the number of your extended partition MINUS ONE [e.g. in this case sda4 becomes (hd0,3)]) after "root (hd0,0)". This makes your extended partition invisible to Windows right before booting it. Now, if you start Ubuntu the next time, you'd probably want to have the extended partition again. So you need to insert "unhide (hd0,3)" for each Ubuntu boot-entry. So something like

title Ubuntu 8.10, kernel 2.6.27-8-generic
uuid 985f0fdc-9bca-406c-aa75-aced7d4e2465
kernel /vmlinuz-2.6.27-8-generic root=UUID=ace99917-f6f2-4cc8-80f2-80f6137caad5 ro quiet splash
initrd /initrd.img-2.6.27-8-generic
quiet

should afterwards read as

title Ubuntu 8.10, kernel 2.6.27-8-generic
uuid 985f0fdc-9bca-406c-aa75-aced7d4e2465
unhide (hd0,3)
kernel /vmlinuz-2.6.27-8-generic root=UUID=ace99917-f6f2-4cc8-80f2-80f6137caad5 ro quiet splash
initrd /initrd.img-2.6.27-8-generic
quiet

and you should do this for every entry. Now that's it and everything should work just fine.

Case 2: For the following method to work, you'll need a primary ext2- or ext3-partition (probably any file system will work as long as GRUB can handle it), if you don't have one then I really don't know how to resolve the problem. So let's assume that sda5 (i.e. a logical partition) is the partition containing all the files in your /boot directory and that sda3 is your root partition (i.e. mounted at "/" under Ubuntu). I guess any primary ext3-partition would do, so sda3 doesn't NEED to be your root-partition but that's the only case I tested. Now the method from above won't work because if you hide sda4 the first time you boot Windows then all the logical partitions in sda4 and so especially sda5 will be hidden, too. Now, you can imagine what will happen the next time you try to boot your system. You won't even be able to start GRUB again because GRUB will try to find all the files it needs on sda5, which doesn't exist anymore (at least as far as you can tell from the partition table). You will have to boot from a Live-CD and unhide sda4 (which means, setting its type to "5" as described above) so that GRUB will work again. Now the easiest solution afaik is to simply copy all the content of your /boot-directory (which is on the logical partition sda5) to our primary partition sda3. You can do this the following way:
1. Boot from a Live-CD (e.g. GParted or Ubuntu).
2. Open a terminal and write "mkdir /media/boot" (you will need a "sudo" in front of every command if you use Ubuntu).
3. Type "mount /dev/sda3 /mnt" to mount your root-partition and "mount /dev/sda5 /media/boot" to mount your boot-partition.
4. Type "cp --preserve=all -HR /media/boot/* /mnt/boot" to copy everything from your boot-partition to the "/boot"-directory on your root-partition (i.e. to the place where it is mounted normally).
5. Now we have to tell Ubuntu not to mount anything again as "/boot" because all the files are on your root-partition now. So write "sudo vim /mnt/etc/fstab" (any other editor will do of course) and comment out the line which reads something like "UUID=985f0fdc-9bca-406c-aa75-aced7d4e2465 /boot ext3 relatime 0 2" (of course your UUID will be different from this one) and close fstab again.
6. Write "sudo vim /mnt/boot/grub/menu.lst" and change every "(hd0,4)" to "(hd0,2)", meaning that GRUB should look for its files on sda3 now instead of sda5.
7. I also did have to change every "/vmlinuz..." and "/initrd..." to "/boot/vmlinuz..." and "/boot/initrd...." respectively. I don't know why because according to any source I found so far this should not be necessary.
8. Close menu.lst again and write "grub-install --root-directory=/mnt /dev/sda" (actually I did "grub-install --root-directory=/mnt/boot /dev/sda" by mistake but I think both commands should work just fine).
9. Now, it's time to test it, so restart your system and try booting to Ubuntu again. If I didn't forget anything and remembered the stuff I didn't forget correctly, you should be able to start it.
10. If you like, you can delete sda5 now and use the space for something different. You have reduced the problem to the first case and can now continue with the solution given there.

Hope I could help and that everything was more or less understandable.

So long,
Laeg

Revision history for this message
Matthias Niess (mniess) said :
#18

Reading a bit around some search results I might have found a more permanent solution. I think we agree that the extended partitions are set up in a way XP can't handle. Since I've always set them up the same way for years and XP never had problems I assume it is a problem with gparted. So one solution would be to run the Partition Magic Live-CD. As soon as it boots it will tell you your partition table has errors and will offer to fix it. After that the extended partitions should be "windows-compatible" again.

I haven't tried this, yet, and it is some kind of a last-resort because it is a commercial solution to the problem which I was hoping to avoid.