[arch-general] fdisk vs cfdisk... And is my drive borked or what?
I'm new to Arch. I recently dumped a very bloated Sabayon installation which left me enough room on my laptop for two other distros... I went with PCLinuxOS AND Arch because both sounded like reinstalling from scratch wasn't a twice a year thing... Actually I tried installing PCLinuxOS on a usb drive before I dumped Sabayon. But something went wrong in the first attempt when the installer formatted the new PCLinuxOS root partition on /dev/sda (as it called my usb drive) and promptly wrote the partition table to /dev/hdb (as it called my laptop's internal drive... ARGH! Fortunately after a send attempt succeeded in installing to usb drive succeeded some tool called "testdisk: was able to restore my laptop's partition table. And every thing worked again... (That was the last time I'll ever let an installer format anything. Strictly pre-partition and pre-mkfs from now on...) Any way I only mention it because When I got around to installing Arch on one of the two partitions I recovered from Sabayon, I skipped the installation step of letting cfdisk touch my partitions and simply selected the partition I previously prepared for it with mkfs.ext3. But later as working my way through the beginners guide in the wiki, the clear explanation of why distro's like to use UUID instead of /dev/Xdx# sold me on using persistent (BUT HUMAN READABLE!!!) entries like: "/dev/disk/by-label/Arch_lap-7" & "/dev/disk/by-label/SWP_lap-12" Especially since there was a wealth of how-to info right there in the wiki... But in the process I happened to do an: fdisk /dev/sda Which complained about a dos compatibility flag and that I should change the display/entry units to sectors. This showed me a small bit of unused space above my last logical partition (/dev/sda12)... Anyway I decided to look at it with cfdisk (which I haven't used in years but remembered as being easier to work with than fdisk...) But all I got from cfdisk was. => FATAL ERROR: Bad primary partition 3: Partition ends after end-of-disk => Press any key to exit cfdisk Which considering the recent "testdisk" repair, frightened be a bit. But it also frustrated me. Especially since fdisk didn't show anything like that... Unless maybe: When "cfdisk /dev/sda" says "partition 3:" is it counting from 0? That is, does it mean "/dev/sda4" ??? Because that's my extended partition... And a close look at the ending cylinder/sector of /dev/sda4 is a slightly higher number than it reports the total cylinders/sectors to be... I've pasted both the sector and cylinder views of my part table below, Is this anything I should be worried about??? Is there a way to fix this without destroying everything in the extended partition??? (That's a LOT of backing up to dvd, and I don't have room anyplace else...) -- | ~^~ ~^~ | <?> <?> Joe (theWordy) Philbrook | ^ J(tWdy)P | \___/ <<jtwdyp@ttlc.net>> Disk /dev/sda: 120.0 GB, 120034123776 bytes 255 heads, 63 sectors/track, 14593 cylinders, total 234441648 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x4573c650 Device Boot Start End Blocks Id System /dev/sda1 * 63 55456379 27728158+ 7 HPFS/NTFS /dev/sda2 55456380 68372639 6458130 c W95 FAT32 (LBA) /dev/sda3 68372640 70332569 979965 83 Linux /dev/sda4 70332570 234452609 82060020 f W95 Ext'd (LBA) /dev/sda5 70332633 103538924 16603146 83 Linux /dev/sda6 103538988 136745279 16603146 83 Linux /dev/sda7 136745343 169951634 16603146 83 Linux /dev/sda8 169951698 175815359 2931831 83 Linux /dev/sda9 175815423 183622949 3903763+ 83 Linux /dev/sda10 183623013 195334334 5855661 83 Linux /dev/sda11 195334398 232444484 18555043+ 83 Linux /dev/sda12 232444548 234436544 995998+ 82 Linux swap / Solaris Disk /dev/sda: 120.0 GB, 120034123776 bytes 255 heads, 63 sectors/track, 14593 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x4573c650 Device Boot Start End Blocks Id System /dev/sda1 * 1 3452 27728158+ 7 HPFS/NTFS /dev/sda2 3453 4256 6458130 c W95 FAT32 (LBA) /dev/sda3 4257 4378 979965 83 Linux /dev/sda4 4379 14594 82060020 f W95 Ext'd (LBA) /dev/sda5 4379 6445 16603146 83 Linux /dev/sda6 6446 8512 16603146 83 Linux /dev/sda7 8513 10579 16603146 83 Linux /dev/sda8 10580 10944 2931831 83 Linux /dev/sda9 10945 11430 3903763+ 83 Linux /dev/sda10 11431 12159 5855661 83 Linux /dev/sda11 12160 14469 18555043+ 83 Linux /dev/sda12 14470 14593 995998+ 82 Linux swap / Solaris
Joe(theWordy)Philbrook wrote:
Any way I only mention it because When I got around to installing Arch on one of the two partitions I recovered from Sabayon, I skipped the installation step of letting cfdisk touch my partitions and simply selected the partition I previously prepared for it with mkfs.ext3. But later as working my way through the beginners guide in the wiki, the clear explanation of why distro's like to use UUID instead of /dev/Xdx# sold me on using persistent (BUT HUMAN READABLE!!!) entries like: "/dev/disk/by-label/Arch_lap-7"& "/dev/disk/by-label/SWP_lap-12" Especially since there was a wealth of how-to info right there in the wiki... But in the process I happened to do an: fdisk /dev/sda
Which complained about a dos compatibility flag and that I should change the display/entry units to sectors. This showed me a small bit of unused space above my last logical partition (/dev/sda12)...
It shows those two warnings with the default call. AFAIK it is unrelated to your actual partition contents.
Anyway I decided to look at it with cfdisk (which I haven't used in years but remembered as being easier to work with than fdisk...) But all I got from cfdisk was.
=> FATAL ERROR: Bad primary partition 3: Partition ends after end-of-disk => Press any key to exit cfdisk
Which considering the recent "testdisk" repair, frightened be a bit. But it also frustrated me. Especially since fdisk didn't show anything like that...
Unless maybe: When "cfdisk /dev/sda" says "partition 3:" is it counting from 0? That is, does it mean "/dev/sda4" ???
Because that's my extended partition... And a close look at the ending cylinder/sector of /dev/sda4 is a slightly higher number than it reports the total cylinders/sectors to be...
Could be.
I've pasted both the sector and cylinder views of my part table below, Is this anything I should be worried about??? Is there a way to fix this without destroying everything in the extended partition??? (That's a LOT of backing up to dvd, and I don't have room anyplace else...)
Caveat emptor: you should have a backup before touching partitions :) That said, you only want to "truncate" the partitions, and since your last partition is the swap, that should be pretty safe. The process of unmounting swap partition, delete partition with fdisk, create with fdisk, reformat swap /shouldn't/ affect your data. I find an oddity on your paritition table, though. You say that /dev/sda4 is an extended partition (and you do have logical partitions) but it is listed by fdisk as having type 0xf (W95 Ext'd (LBA)) instead of 0x5 (Extended). I suspect that after testdisk restoring, some old entries got loaded? If that's really a wrong entry, you can do the fdisk delete/recreate tip to force its length to be inside the disk limits. However, fdisk won't allow you to set a partition type of 5, which is a pity when you *really* know what you are doing. __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
On 03/17/2010 10:45 PM, Linas wrote:
Which complained about a dos compatibility flag and that I should change the display/entry units to sectors. This showed me a small bit of unused space above my last logical partition (/dev/sda12)...
Don't worry about that for now, that could only come back to bite you if you had a new disk with 4KB sectors (or an SSD that I think prefers writes to be aligned with pages ... or something like that).
=> FATAL ERROR: Bad primary partition 3: Partition ends after end-of-disk => Press any key to exit cfdisk
cfdisk can complain if _anything_ isn't as it wants it to be. cfdisk is easier to use than fdisk but complains a lot if the partition table deviates a little from the most compatible "format" possible.
Because that's my extended partition... And a close look at the ending cylinder/sector of /dev/sda4 is a slightly higher number than it reports the total cylinders/sectors to be...
I take it that the first listing is in sectors, if you look closely you will see that your last partition (swap) end before the end of the disk so you're safe, the extended partition is just a placeholder for other partitions, so if the partitions do not try to use space that doesn't exist it should be ok. However I would still try to rectify the ending of the extended partition. Backup all your data and try to shrink that extended partition until it fits in your disk.
I find an oddity on your paritition table, though. You say that /dev/sda4 is an extended partition (and you do have logical partitions) but it is listed by fdisk as having type 0xf (W95 Ext'd (LBA)) instead of 0x5 (Extended). I suspect that after testdisk restoring, some old entries got loaded? If that's really a wrong entry, you can do the fdisk delete/recreate tip to force its length to be inside the disk limits. However, fdisk won't allow you to set a partition type of 5, which is a pity when you *really* know what you are doing.
Type 0xf is also ok, it all depends on which program created the partition table initially, I'm not sure but I think gparted used to set extended partitions to 0xf and so do many other programs. fdisk should be able to change the type to 5 but if it can't then give sfdisk a try but make sure all your data is safe.
It would appear that on Mar 17, Linas did say:
Joe(theWordy)Philbrook wrote:
fdisk /dev/sda
Which complained about a dos compatibility flag and that I should change the display/entry units to sectors. This showed me a small bit of unused space above my last logical partition (/dev/sda12)...
It shows those two warnings with the default call. AFAIK it is unrelated to your actual partition contents.
I'll buy that... The odd thing is the fdisk from my other distros doesn't bother... So the warnings got my attention.
Anyway I decided to look at it with cfdisk (which I haven't used in years but remembered as being easier to work with than fdisk...) But all I got from cfdisk was.
=> FATAL ERROR: Bad primary partition 3: Partition ends after end-of-disk => Press any key to exit cfdisk
When "cfdisk /dev/sda" says "partition 3:" is it counting from 0? That is, does it mean "/dev/sda4" ???
Could be.
I've pasted both the sector and cylinder views of my part table below, Is this anything I should be worried about??? Is there a way to fix this without destroying everything in the extended partition??? (That's a LOT of backing up to dvd, and I don't have room anyplace else...)
Caveat emptor: you should have a backup before touching partitions :) That said, you only want to "truncate" the partitions, and since your last partition is the swap, that should be pretty safe. The process of unmounting swap partition, delete partition with fdisk, create with fdisk, reformat swap /shouldn't/ affect your data.
I hadn't intended to touch the partitions. I only gave the malfunctioning installer permission to reformat an existing ext2 partition as ext3. That's an mkfs job that shouldn't have led to ANY table rewrite, never mind writing to the table of a different drive... Also, backing up everything isn't always practical. I really don't have the spare storage space. So backing up 4 Linux installations would eat a *LOT* of time and several DVD's... I do have enough room on my usb drive to back up the personal data partitions. But if I bork up the drive while fixing this I'm going to have to do a *LOT* of reinstalling from scratch. Which leads to a *LOT* of painful configuring... But I note that while the ending sector of the extended partition apparently exceeds the drive's ending sector... The ending sector of the last logical partition within it does not... So I don't think I need to redo the swap. but rather (and for me more problematic) just the extended partition that contains it. {I'll have more on that in my reply to Mauro below.} It would appear that on Mar 17, Mauro Santos did say:
On 03/17/2010 10:45 PM, Linas wrote:
Joe(theWordy)Philbrook wrote: {quote tag re-inserted by Joe...}
=> FATAL ERROR: Bad primary partition 3: Partition ends after end-of-disk => Press any key to exit cfdisk
cfdisk can complain if _anything_ isn't as it wants it to be. cfdisk is easier to use than fdisk but complains a lot if the partition table deviates a little from the most compatible "format" possible.
So I noticed... But I think it does have a point.
Because that's my extended partition... And a close look at the ending cylinder/sector of /dev/sda4 is a slightly higher number than it reports the total cylinders/sectors to be...
I take it that the first listing is in sectors, if you look closely you will see that your last partition (swap) end before the end of the disk so you're safe, the extended partition is just a placeholder for other partitions, so if the partitions do not try to use space that doesn't exist it should be ok. However I would still try to rectify the ending of the extended partition. Backup all your data and try to shrink that extended partition until it fits in your disk.
I can backup all my personal data... But I don't have the room to back up all my Linux installations. Rebuilding them all from scratch, all at once would be a nightmare. But it's a risk I'll have to take. I'm not so sure how to shrink the extended partition itself. cfdisk won't touch it. And if I remember right, to do it with fdisk I basically have to delete and then recreate the said extended partition using the correct sectors... But that would, I think mean I'd have to delete the logical partitions first, and then recreate them with their correct sector information within the correctly recreated extended partition. (And pray I got it "right" before I "write" the rebuilt table.) I've never used gparted (unless maybe it was used as a backend for the "set up your partitions manually" section of some Linux installer??? But does it have the ability to resize a NON-empty extended partition? If not, is there something I can get from pacman that does? And is it any more risky than the tedious fdisk process I described above?
I find an oddity on your paritition table, though. You say that /dev/sda4 is an extended partition (and you do have logical partitions) but it is listed by fdisk as having type 0xf (W95 Ext'd (LBA)) instead of 0x5 (Extended). I suspect that after testdisk restoring, some old entries got loaded? If that's really a wrong entry, you can do the fdisk delete/recreate tip to force its length to be inside the disk limits. However, fdisk won't allow you to set a partition type of 5, which is a pity when you *really* know what you are doing.
Actually while I don't think the ending sector of the extended partition used to be past the end of the drive before testdisk rebuilt my drive's table for me. I'm quite sure the (W95 Ext'd (LBA)) part has been there forever. The first thing I did when I got this laptop that was destined for at least dual booting was to use the vista cd to repartition the drive into one much smaller ntfs, two fat, and one extended partition(s) before I reinstalled vista. Then I used Linux tools to add the logical drives. And eventually turn the smaller fat into an ext2 /boot partition.
Type 0xf is also ok, it all depends on which program created the partition table initially, I'm not sure but I think gparted used to set extended partitions to 0xf and so do many other programs. fdisk should be able to change the type to 5 but if it can't then give sfdisk a try but make sure all your data is safe.
0xf, 5, Who cares which it's called? As long as it contains the logical partitions... But the ending sector thing will bug me if I don't fix it. So for my piece of mind I'm gonna have to do something...
On 03/18/2010 09:10 AM, Joe(theWordy)Philbrook wrote:
0xf, 5, Who cares which it's called? As long as it contains the logical partitions... But the ending sector thing will bug me if I don't fix it. So for my piece of mind I'm gonna have to do something...
Gparted (which is just a frontend for parted) may be able to resize your extended partition without touching any of the logical partitions inside (you may need to delete your last partition first though, it all depends on what alignment gparted will try to use), however I try not to use gparted because once it wrecked havoc during a resize operation, because of that and because I have a big enough spare disk, I always do a full backup before any major partition changes. Your primary partitions are safe but the logical ones can just vanish if things go wrong. I guess that if you take note of the start and end sectors for all partitions you can recreate the layout if anything goes wrong (I have never tried it though so I can't say how well that will work).
On 18-03-10 12:52, Mauro Santos wrote: [...]
Gparted (which is just a frontend for parted) may be able to resize your extended partition without touching any of the logical partitions inside (you may need to delete your last partition first though, it all depends on what alignment gparted will try to use),
[...] To be safe, first make an *exact* note (on paper) of the current partition table. If anything goes wrong, you can boot a rescue CD and recreate the partition table from this note. You could also make a copy of the first sector with dd and store that on some media (USB hdd comes to mind), but i would still make the paper note. After that, just change the end sector of the extended partition to match the end sector of your swap partition and you should be fine. (try starting cfdisk at this point to see if the error still exists). If you're feeling brave, you could also recreate the entire partition table from scratch. It's just a table listing which partitions are where. Nothing more. If you don't fully trust the process, you could try mounting the data partitions after the change. If that succeeds without errors, it should be ok. HTH, HAND mvg, Guus
On 18/03/10 12:52, Mauro Santos wrote:
On 03/18/2010 09:10 AM, Joe(theWordy)Philbrook wrote:
0xf, 5, Who cares which it's called? As long as it contains the logical partitions... But the ending sector thing will bug me if I don't fix it. So for my piece of mind I'm gonna have to do something...
Gparted (which is just a frontend for parted) may be able to resize your extended partition without touching any of the logical partitions inside (you may need to delete your last partition first though, it all depends on what alignment gparted will try to use), however I try not to use gparted because once it wrecked havoc during a resize operation, because of that and because I have a big enough spare disk, I always do a full backup before any major partition changes.
Your primary partitions are safe but the logical ones can just vanish if things go wrong. I guess that if you take note of the start and end sectors for all partitions you can recreate the layout if anything goes wrong (I have never tried it though so I can't say how well that will work).
It works. But you should copy the values *in sectors*. It's amazing how different tools interpret the same values on different actual positions. __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
On 18-03-10 22:34, Linas wrote: [...]
It works. But you should copy the values *in sectors*. It's amazing how different tools interpret the same values on different actual positions.
Indeed, that is one thing i forgot to note. Make your notes in sectors. mvg, Guus
It would appear that on Mar 18, Mauro Santos did say:
Gparted (which is just a frontend for parted) may be able to resize your extended partition without touching any of the logical partitions inside (you may need to delete your last partition first though, it all depends on what alignment gparted will try to use), however I try not to use gparted because once it wrecked havoc during a resize operation, because of that and because I have a big enough spare disk, I always do a full backup before any major partition changes.
Tried it... Gparted didn't like my existing partition table any better than cfdisk did... It refused to use the table data. But unlike cfdisk it was willing to proceed in case I wanted to recreate the whole thing from scratch...
Your primary partitions are safe but the logical ones can just vanish if things go wrong. I guess that if you take note of the start and end sectors for all partitions you can recreate the layout if anything goes wrong (I have never tried it though so I can't say how well that will work).
I can now certify that rebuilding them with fdisk works... ;) {see below} It would appear that on Mar 18, Guus Snijders did say:
To be safe, first make an *exact* note (on paper) of the current partition table. If anything goes wrong, you can boot a rescue CD and recreate the partition table from this note. You could also make a copy of the first sector with dd and store that on some media (USB hdd comes to mind), but i would still make the paper note.
After that, just change the end sector of the extended partition to match the end sector of your swap partition and you should be fine. (try starting cfdisk at this point to see if the error still exists). Basically that's what I did with fdisk. I had a text file with the table data in it on the usb drive. which I opened in one window while I ran fdisk in another. It let me delete the old extended partition without explicitly deleting the logical partitions, But of course when I recreated it, I
I did print the partition table data... I'm not good with dd. I've got explicit notes on using it to backup/restore the mbr, and have a copy of that on the usb drive (is that what you mean?) but using it back-up the rest of the partition table is beyond me. pasted the ending value from the swap partition. Then proceeded to recreate the logical partitions the same way. (I had used the fdisk "u" to set units to sectors: 1)type "n" copy the default beginning sector to clipboard 2)switch to the window with the text file open with vim 3)paste number next to old starting value to confirm values match 4)copy the ending sector from the old data to the clipboard 5)switch windows to the fdisk session 6)paste in the ending sector. 7)repeat 1-6 until all logical partitions had been recreated 8)use "t" to reset the type of the swap partition back to "82" "w" write table... And it worked.
If you're feeling brave, you could also recreate the entire partition table from scratch. It's just a table listing which partitions are where. Nothing more.
I could have done that. But why mess with the 1st 3 partitions???
If you don't fully trust the process, you could try mounting the data partitions after the change. If that succeeds without errors, it should be ok.
I trust it better now... It would appear that on Mar 18, Linas did say:
It works. But you should copy the values *in sectors*. It's amazing how different tools interpret the same values on different actual positions.
Well I could have recreated the whole table from scratch with gparted. But I felt more secure using fdisk, since it was fdisk that provided the sector data... The good news is afterwards, I rebooted (successfully) And then tested cfdisk, which no longer complains. I figure if cfdisk is willing to work on it, my partition table must now be nearly perfect... -- | --- ___ | <0> <-> Joe (theWordy) Philbrook | ^ J(tWdy)P | ~\___/~ <<jtwdyp@ttlc.net>>
On 19-03-10 19:34, Joe(theWordy)Philbrook wrote: [ fixing a partition table ]
I can now certify that rebuilding them with fdisk works... ;) {see below}
Good work. On a funny note; i read today that fdisk also has an option to "fix" an existing partition table (under expert options)...
It would appear that on Mar 18, Guus Snijders did say:
To be safe, first make an *exact* note (on paper) of the current partition table. If anything goes wrong, you can boot a rescue CD and recreate the partition table from this note. You could also make a copy of the first sector with dd and store that on some media (USB hdd comes to mind), but i would still make the paper note.
I did print the partition table data... I'm not good with dd. I've got explicit notes on using it to backup/restore the mbr, and have a copy of that on the usb drive (is that what you mean?) but using it back-up the rest of the partition table is beyond me.
Looks like the partition table is stored on the first sector of the disk, so restoring a copy of that sector also restores the table. But yes; storing a copy of the MBR on an external disk is what i meant.
After that, just change the end sector of the extended partition to match the end sector of your swap partition and you should be fine. (try starting cfdisk at this point to see if the error still exists). Basically that's what I did with fdisk. I had a text file with the table data in it on the usb drive. which I opened in one window while I ran fdisk in another. [...]
And it worked.
Great, that's good news.
If you're feeling brave, you could also recreate the entire partition table from scratch. It's just a table listing which partitions are where. Nothing more.
I could have done that. But why mess with the 1st 3 partitions???
You're right, it wasn't neccesary in this case, but it sometimes happens that the order of partitions get messed up. On such occasion it might be worthwhile to just recreate the whole table. mvg, Guus
On a funny note; i read today that fdisk also has an option to "fix" an existing partition table (under expert options)...
I did try that once and I won a free system reinstall, maybe I was just unlucky or the partition table was too messed up.
Looks like the partition table is stored on the first sector of the disk, so restoring a copy of that sector also restores the table. But yes; storing a copy of the MBR on an external disk is what i meant.
That will only restore the primary partitions (the extended partition itself is a primary partition), the location of the logical partitions inside an extended partition are saved in a different way, check [1] for a description. With luck, by restoring the extended partition one can also restore all the logical partitions inside.
You're right, it wasn't neccesary in this case, but it sometimes happens that the order of partitions get messed up. On such occasion it might be worthwhile to just recreate the whole table.
As far as I know linux doesn't care if the partition order in the table is the same as the order on disk but lots of partition managers complain (and I like it to be nice and ordered). fdisk can create an out of order layout (at least it did for me once), cfdisk can do that too I think and gparted is a master at messing with that when doing any operation with partitions (and thats why, among other reasons, I try to touch gparted only with a long stick). Now that we are talking about this I guess it is a good time to share thoughts/experiences about this, you never know when knowing this things will prove to be life savers or avoid you from making big mistakes. [1] http://en.wikipedia.org/wiki/Extended_boot_record
participants (4)
-
Guus Snijders
-
Joe(theWordy)Philbrook
-
Linas
-
Mauro Santos