Gparted Error/HD Fix
I recently deleted several partitions on my HD accidentally, and restored them with Testdisk. Now, Gparted does not load correctly and prints the error "Can't have a partition outside the disk!"
This is the result of sudo fdisk -lu: Code:
Disk /dev/sda: 160.0 GB, 160041885696 bytes Code:
Warning: extended partition does not start at a cylinder boundary. Can anyone help me correct this problem so that I can run Gparted? My computer runs fine otherwise, but this is preventing me from getting certain things done! Thanks! |
You are able to show the disk using fdisk; so maybe you can fix it using fdisk. First of all, remember that linux fdisk does not reformat like windows fdisk does; so deleting and remaking a partition with linux fdisk does not remove data. I've done this years ago and I'm pretty sure the way fdisk works has not changed.
First make a hard copy of that printout you have of the fdisk -l results. You will be using the data from the top (fdisk -lu). I don't think you can do this with the partition mounted; so you will need to use a live cd of some sort. If you have one, good. If not, I'd get one of the rescue disks that smaller than a regular distro. Boot the disk and go to a terminal and get to root. Run fdisk -l again to be sure the numbers are the same as what you already have. Then run fdisk /dev/sda. If you haven't used it before, look at the list of commands. You will need to delete sda5 and sda4 and then remake sda4 using the end as the same number as the total sectors at the top. That gets rid of the error, hopefully. Then make sda5 using the exact cylinder numbers on your printout. Save and close fdisk. Run fdisk -l again to be sure sda5 has those same numbers as before. Then boot your machine to Linux. And yes, I'd be afraid to do this now. The way drives work may have changed a lot in the 10 years or so since I did this. I'd back up my data and have a really good reason to want to fix this. In my case, the partition table got hosed and I just happened to have a printed copy of the table like the one you posted here. I went in and remade the partitions and all was well. With fdisk it is the partition table that you change, not anything else on the disk. PS: Congratulations on being able to use testdisk to restore your partitions! |
Solved
Quoted from my thread at the Ubuntu forums:
Quote:
Start by typing the command: Code:
sfdisk -d /dev/sda > parts.txt Code:
# partition table of /dev/sda Code:
Disk /dev/sda: 160.0 GB, 160041885696 bytes 312581808 - 86011987 = 226569821 Now, replace the size of the problem partition in parts.txt (226580783) with the new number (226569821). Done right, this number should be smaller than that which it replaces. Save as a different file name (I used "part.txt") so that you have the original backed up before making changes. Now run this command: Code:
sfdisk /dev/sda < part.txt Code:
sfdisk --force /dev/sda < part.txt Remember, this only works if the problem is caused by an extended partition overlapping the disk boundary. This is not the solution if the extended partition is cutting into a logical partition, although similar steps can be taken to rectify it, and may not work if the problem is related to a primary partition. I hope my instructions are clear and this helps someone in the future! Big thanks to srs5694 and coffeecat! |
Quote:
Code:
Disk /dev/sda: 160.0 GB, 160041885696 bytes |
I see. Would you say one technique is preferable to the other? Sfdisk was pretty fast and straightforward, but then, I've never rewritten a partition table with fdisk, so I can't compare.
|
Quote:
Oh, come to think of it, the best technique would have been to have had that partition table on paper so that you could have just remade it correctly to start with. :-) But, I admire anyone who can come up with one when they don't have those numbers. |
Well I do realize this thread is six months old, but I do feel it is relevant & timely to "bump" it as Ritzbitts solution helped me much and other seekers should have access to this info.
I had the same problem, apparently caused by the testdisk bug? Anyhow I had to jiggle around with the values somewhat, the simple subtraction didn't get me there, but closely looking at the errors I would get in GParted finally led me to the correct number to "feed" back to the drive. What finally solved it for me was formatting the drive as Fat32. The ext formats would just not give me enough info somehow to solve it. By making an intentionally slightly smaller Fat32 partition I got it to format ok. Then the real clincher was to run check in GParted, the Fat32 partition somehow automatically decided it should fill all the free space as well, but the sector number I had used was one sector too large and it showed that error clearly in the Gparted details. Then I knew, simply changed my "part.txt" file to one less sector and Bob's your Uncle (even if you're American). Incidentally, another helpful thing was that although sfdisk says it is checking to see if anyone's using the drive, I would leave GParted running while doing "feed" updates, it didn't mind. Easier than restarting GParted over and over. However, be sure and do "refresh drives" from the top left "GParted" menu. Thanks Ritzbitts! You kept me going, I had given up. And a very special THANK YOU to Rod Smith for his very unique fixit stuff. OMG, I just spilled a glass of water all over the drive while powered and now it won't spin up! Hopefully it'll dry. It's just a tiny old drive anyhow, but I did kinda need it. At least I did want to document this here for others. :o |
Glad I was able to help. Hope the HD dries!
|
All times are GMT -5. The time now is 04:26 AM. |