First of all, I'm not sure that this is exactly the right place to post this question - it has to do with partitions and booting, particularly Linux partitions, but also some Windows. Second, I've been using Linux for about three years, and I'm able to do most things (use the command line, etc.) but I'm by no means an expert.
So, first, some background on the current situation. The computer in question is an ASUS desktop (about 2 years old now) with a 1 TB hard drive. It came with Windows 7. One of the first things I did was to shrink the Windows 7 partition to about 300 GB and use the rest as a Linux partition. Over the course of time, I installed Ubuntu 12.04, Linux Mint 13 (the primary OS I use), Fedora 17, and OpenSUSE 12.1. I used GRUB as my bootloader (the one that came with Fedora, which I installed last), and all was well. At this point, my Linux partition was normal, I think, one primary partition containing a logical partition for each OS, as well as one or two random, small partitions that I think were used for booting, and the Linux Swap.
Then, a couple days ago I decided to install Windows 8 - more for fun than anything. I freed up 150 GB of unallocated space on the hard drive and installed it there. Everything went well. The Windows bootloader took over, which only recognized Windows 7 and 8, but that was fine for the time being - I would just reinstall GRUB at some point. Eventually I decided to switch back to Linux for a while so I booted from a gparted live CD. gparted correctly found the Windows 7 and 8 partitions (as well as a "RECOVERY" partition of 10 GB that has been there since I got the computer; I'm pretty sure that's normal). However, the Linux partition contained only unallocated space, except for the swap, which appeared to be untouched.
My first idea was that Windows 8 must have messed up the partition formatting (I know next to nothing about this) somehow - I doubt that it would erase the contents of a partition, while leaving the partition itself (and the swap) intact. First, I used either gparted's "Create Partition Table" or "Attempt Data Rescue" (I honestly can't remember which). It ran, supposedly successfully, and prompted me to restart, which I did. However, when the computer resumed (booting from the gparted live CD still) the entire hard drive appeared as unallocated. I managed to recover all the important files from the hard drive with "testdisk" (which does recognize the partitions - more on that later) onto a flash drive. Now, all that's left is to restore the partitions, preferably everything, but if I can just get back Windows 7 and 8 I'll be happy - reinstalling Linux isn't a problem.
So, here's the current state of the computer (as seen from a gparted live CD):
gparted reports that the entire hard drive is unallocated:
Warning: Can't have a partition outside the disk!
Running "sudo fdisk -l" gives:
Running testdisk with normally (running as sudo, using quick scan) gives something like this:
Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders, total 1953525168 sectors
Unites = sectors of 1 * 512 = 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xa72flcae
Device Boot Boot Start End Blocks Id System
/dev/sda1 * 63 20980889 10490413+ 7 HPFS/NTFS/exFAT
/dev/sda2 20980890 650127346 314573228+ 7 HPFS/NTFS/exFAT
/dev/sda3 650129408 964702199 157286396 83 Linux
/dev/sda4 964703250 1953536129 494416440 f W95 Ext'd (LBA)
/dev/sda5 964704256 1174419455 104857600 83 Linux
/dev/sda6 1174421504 1216376831 20977664 83 Linux
/dev/sda7 1216378880 1321236471 52428796 83 Linux
/dev/sda8 1321238528 1322262527 512000 83 Linux
/dev/sda9 1322264576 1626976255 152355840 83 Linux
/dev/sda10 1626978304 1638950895 5986296 82 Linux Swap / Solaris
/dev/sda11 1638952960 1953521663 157284352 7 HPFS/NTFS/exFAT
I'll see if I can explain these a bit:
Disk /dev/sda - 1000 GB / 931 GiB - CHS 121602 255 63
Partition Start End Size in sectors
* HPFS - NTFS 0 1 1 1305 254 63 20980827 [RECOVERY]
P HPFS - NTFS 1306 0 1 40468 141 44 629146457 [WINDOWS]
P Linux 40468 174 27 60049 238 21 314572792
L Linux 60050 15 62 73104 58 42 209715200
L Linux 73104 91 12 75715 243 48 41955328
L Linux 75716 21 18 82243 42 31 104857592
L Linux 82243 75 9 82307 9 6 1024000
L Linux 82307 41 39 101274 149 59 304711680
L Linux Swap 101274 182 29 102019 248 37 11972592
L HPFS - NTFS 102020 26 23 121601 25 24 314568704
Structure: Ok. Use Up/Down Arrow keys to select partition.
Use Left/Right Arrow keys to CHANGE partition characteristics:
*=Primary bootable P=Primary L=Logical E=Extended D=Deleted
- /dev/sda1 is the RECOVERY partition I mentioned earlier. It came on the computer, I'm not really sure what it's supposed to do, and I've never really used it
- /dev/sda2 is the Windows 7 partition
- /dev/sda3 is the primary partion that holds the Linux partitions\
- /dev/sda4 no idea what this is. I don't remember ever having a /dev/sda4 before. What's more, based on "End" from fdisk, it seems to be going past the end of the hard drive, which is probably what's causing the gparted problems
- /dev/sda5 is Ubuntu I believe
- /dev/sda6 a small, random partition I didn't make. I think it came about when I installed openSUSE
- /dev/sda7 is Linux Mint, I think
- /dev/sda8 is another small, random partition I didn't make, I think it's associated with Fedora
- /dev/sda9 is Fedora
- /dev/sda10 is the Linux Swap, which was still intact initially after installing Windows 8
- /dev/sda11 is Windows 8
I see two problems here, myself. First, /dev/sda4 seems to be an issue. It goes past the end of the hard drive, and looks like it has Windows 95 formatting of some sort (this computer has never had '95). Second, the Windows 8 partition looks like it's a logical partition, although I think it should be primary (I believe I read somewhere that Windows requires primary partitions), so this may or may not be an issue.
In conclusion, anything you can think of would be appreciated. Thanks so much for just reading this! I know it's a bit long (and if you haven't read it, that's fine too - any suggestions are great). I'm always happy to post more info or try new things (although after typing out those testdisk and fdisk screens I'm half asleep :P).
EDIT: Something I forgot to mention. If I try to boot without the gparted live CD, Windows 7 boots (I had marked the Windows 7 partition as the boot most recently, but I can't change that now that gparted's not working). It starts an ASUS service to recover the partition (only the 300 GB that are in the Windows 7 partition as far as I can tell). I haven't tried this yet, fearing that it'll cause another problem, and that there might be a better solution. In any case, I can't imagine that this would fix much beyond Windows 7, if anything.
EDIT: EDIT: I've messed around with the boot partition with fdisk, and now when I boot from the hard drive I either get "operating system not found" or "insert an appropriate boot device and press any key". Also, I'm now pretty sure I was booting from RECOVERY before, which is why it tried to restore stuff.
/dev/sda4 964703250 1953536129 494416440 f W95 Ext'd (LBA)
That's the extended partition that holds sda5-11. See how the block number extends before and past all the partitions contained therein? It's normal.
The Parted live CD doesn't pick up ext4 IIRC. It's not really up to date, and best left alone.
Anyway, Grub probably has to be reinstalled on the MBR, and you need to toggle the boot flag to which ever partition you're booting from.
I did figure out that sda4 (silly of me to think it was Windows 95 something-or-other) is the extended partition, but why is it encompassing Windows 8 (sda11)? I set that up as a separate primary partition, so Linux would only be sda3-10. Is this normal? (I never really got a chance to check how the partition was actually configured before these problems started.) It also does look like it's going past the end of the disk, can I just trim it back in some way?
Originally Posted by mizzle
I did try getting to boot from one of the Linux partitions by setting the boot flag, but they all failed. I just tried to boot from Windows 7 and the Windows bootloader popped up. So it seems that Windows 7 and 8 are working. I'm confident I can install Grub on the MBR (something I've never done), but then what exactly does the boot flag do (and which partition should have it)?
Also, is there a way to make gparted less confused? I use it to manage my partitions, so it would be convenient if it would be able to read the partitions.
Thanks a ton for the quick response and help.
If you have more than 4 partitions, partition 4 (in our case sda4) is always the extended partition.
When you install an operating system onto a IBM PC, the OS will over write the MBR. There is some preliminary code placed there (what it is and does specifically, not 100% sure) which prepares the system for booting. That code will look for the bootable/primary flag in the partition table, and proceed to try to continue booting from that partition.
Since you installed Windows 8, Windows 8 over wrote your MBR with something that is only Windows-compatible, which is why you're able to boot into windows if you set the boot flag to one of your windows partitions.
After you reinstall Grub, it's up to you which partition should have the bootable flag. Grub will happily boot all the other OS's it finds, so it's typical to set the bootable flag to your primary linux distro's /boot (or / if you don't have a /boot).
When you reinstall Grub, it should pick up all the OS's on the disk.
windows does not need to be installed on a primary partition but its boot files do. What is most likely the case is that your windows8 on sda11 installed its boot code to the mbr and its boot files in the windows 7 partition (sda1?). Linux systems do not need a bootable flag set so I would leave that on sda1, your windows primary partition.
I reinstalled Grub and everything is mostly working now. I can boot Ubuntu and Mint as well as Windows 7 and 8. However, openSUSE and Fedora a missing from the boot list. Fedora was messed up from the start, and I never really used SUSE much so I don't mind. The only problem left is that gparted won't recognize the partitions, complaining that they're outside of the hard drive.
Originally Posted by mizzle
If I can get gparted working, I can remove Fedora and openSUSE and either forget about them or put them back on. My plan is to use fdisk to resize extended partition (which is outside the drive) by deleting it and recreating it - like askubuntu.com/questions/48717/how-to-manually-fix-a-partition-table (sorry, can't post URLs directly without 15 posts) describes. Is this generally safe?
Thank you again for all the help. I've gone from nothing booting to having the important operating systems working.
I'm not sure, I've never tried that. I've seen the boundary problem, but I just always ignore it. Command line utils don't seem to ever care.
There's a small chance that if you mess up the boundaries you could corrupt data on another partition. If your files aren't that important to you, I say give it a try ;) Also, you can back up your MBR in case you need to revert: UNIX / Linux: Copy Master Boot Record (MBR)
dd if=/dev/sda of=/tmp/mbrsda.bak bs=512 count=1
Then, copy mbrsda.bak to removable storage or what have you. of=/path/to/file.ext can be whatever you like.
If you don't mind me asking what guide (if any) did you use to reinstall GRUB?
I used av8n.com/computer/htm/grub-reinstall.htm (again, can't use URLs, sorry). It seemed to work great - I only had to use the first seven steps. I used Mint as the default, is there any possibility that, because I installed openSUSE and Fedora after Mint that they wouldn't show up in GRUB?
I made a backup of the MBR on a flash drive, with the instructions you gave, so I'll try resizing the partition with the gparted live CD at some point tonight and see how it goes.
Yeah, if you installed them after Mint, then those newer OS's wouldn't have been added to Mint's grub files.
From that page: Highly recommended: Rebuild the grub configuration file: update-grub
That may rescan your drive and find the other OS's.
Okay, so all the problems have been completely resolved. So that other people with the same problem can fix their partitions as well, here is a summary of what I've done.
First of all, there was never anything really wrong at all, just two things that freaked me out:
1. The Windows 8 bootloader overwrote GRUB.
To fix this, just re-install GRUB. Easy enough to do, av8n.com/computer/htm/grub-reinstall.htm is a nice guide. In my case, I used device as /dev/sda and used the default partitions of /dev/sda5 (Linux Mint for me). Make sure you update GRUB (go through step 11).
2. One of the partitions was outside of the hard drive, which messed up gparted (although fdisk, sfdisk, and testdisk all worked fine).
I used sfdisk from a gparted live CD to fix this. The command
solved the issue.
echo "213905475,411231871,f" | sudo sfdisk -f -uS /dev/sda -N4 -O sda_sectors_modified.save
Some explanation: "213...,f" are the parameters for sfdisk. 213905475 is the starting sector of the /dev/sda4 partition (the one that was past the end of the hard drive), and 411231871 is a better size for the partition (when added to the start, it is within the end of the hard drive). -f forces the command, -uS make sfdisk use sectors, -N4 makes sfdisk use only the 4th partition (/dev/sda4), and -O with the .save file saves the partition table, just in case something goes wrong.
Thank you sooo much to mizzle - really helpful advice, and I hope this is able to help other people with the same problem (for more info, read through the whole thread).