You are not logged in.

#1 2023-05-18 14:03:42

countrybooter
Member
Registered: 2023-04-25
Posts: 9

Are you an Expert with gdisk and know more than me?

DISCLAIMER: If you answer the topic question with "no," your response will most likely cause confusion.

The idea: detach myself from GUI tools and use the terminal, therefore I'm grateful that Arch exists and is maintained, thank you.

 2023-05-18 09:00:00 sudo gdisk /dev/sdX
GPT fdisk (gdisk) version 1.0.9.1

Caution: invalid backup GPT header, but valid main header; regenerating
backup header from main header.

Warning! One or more CRCs don't match. You should repair the disk!
Main header: OK
Backup header: ERROR
Main partition table: OK
Backup partition table: OK

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: damaged

****************************************************************************
Caution: Found protective or hybrid MBR and corrupt GPT. Using GPT, but disk
verification and recovery are STRONGLY recommended.
****************************************************************************


Command (? for help): /
b    back up GPT data to a file
c    change a partition's name
d    delete a partition
i    show detailed information on a partition
l    list known partition types
n    add a new partition
o    create a new empty GUID partition table (GPT)
p    print the partition table
q    quit without saving changes
r    recovery and transformation options (experts only)
s    sort partitions
t    change a partition's type code
v    verify disk
w    write table to disk and exit
x    extra functionality (experts only)
?    print this menu

Command (? for help): o
This option deletes all partitions and creates a new protective MBR.
Proceed? (Y/N): Y

Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): Y
OK; writing new GUID partition table (GPT) to /dev/sdX.
The operation has completed successfully.
Command (? for help): v

No problems found. 7679999989 free sectors (28.6 TiB) available in 1
segments, the largest of which is 7679999989 (28.6 TiB) in size.
 2023-05-18 09:00:02 sudo partprobe /dev/sdX
Error: The backup GPT table is corrupt, but the primary appears OK, so that will be used.
 2023-05-18 09:00:04 sudo sgdisk -e /dev/sdX
Caution: invalid backup GPT header, but valid main header; regenerating
backup header from main header.

Warning! One or more CRCs don't match. You should repair the disk!
Main header: OK
Backup header: ERROR
Main partition table: OK
Backup partition table: OK

****************************************************************************
Caution: Found protective or hybrid MBR and corrupt GPT. Using GPT, but disk
verification and recovery are STRONGLY recommended.
****************************************************************************

Seem's fixed, right... well, I would just like to understand what could be the reasons of why it's not fixed and what else could I try, because=

2023-05-18 09:00:05 sudo partprobe /dev/sdX
Error: The backup GPT table is corrupt, but the primary appears OK, so that will be used.
2023-05-18 09:00:06 sudo gdisk /dev/sdX 
GPT fdisk (gdisk) version 1.0.9.1

Caution: invalid backup GPT header, but valid main header; regenerating
backup header from main header.

Warning! One or more CRCs don't match. You should repair the disk!
Main header: OK
Backup header: ERROR
Main partition table: OK
Backup partition table: OK

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: damaged

****************************************************************************
Caution: Found protective or hybrid MBR and corrupt GPT. Using GPT, but disk
verification and recovery are STRONGLY recommended.
****************************************************************************

AFAIU, those are the low-level tools that are available, I've replaced /dev/nameofstoragedevice with /dev/sdX on purpose.

How do I use gdisk to repair the backup GPT table?


Thank you for your time, have a pleasant day.

PS: If someone can help me figure this out, I'll modify the title of the post to: 'Fix corrupted GPT table with sgdisk && gdisk' <3

Last edited by countrybooter (2023-05-19 08:44:46)

Offline

#2 2023-05-18 14:18:45

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,449
Website

Re: Are you an Expert with gdisk and know more than me?

No, I'm not an expert.  In fact, I'm not sure I've ever used gdisk.  But I am at least okay at googling:
https://www.rodsbooks.com/gdisk/repairing.html

I don't see any recovery attempts in your output despite being prompted to use them.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#3 2023-05-19 08:47:20

countrybooter
Member
Registered: 2023-04-25
Posts: 9

Re: Are you an Expert with gdisk and know more than me?

Thank you for your response, my Lord.

Could I kindly request you to take a second look at the following two code snippets from my previous post.
AFAIU o/w should create a complete new GPT/backup the new GPT to the end of the disk and write a protective MBR for older systems.
Therefore if after gdisk itself writing the changes to the disk, gdisk itself still recognizes the newly created GPT/backup GPT as damaged, would it be worth posting about it?

Command (? for help): o
This option deletes all partitions and creates a new protective MBR.
Proceed? (Y/N): Y

Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): Y
OK; writing new GUID partition table (GPT) to /dev/sdX.
The operation has completed successfully.

https://askubuntu.com/posts/1370440/revisions

 2023-05-18 09:00:04 sudo sgdisk -e /dev/sdX

As documented in the manual the -e option:

    -e, --move-second-header: Move backup GPT data structures to the end of the disk. Use this option if you've added disks to a RAID array, thus creating a virtual disk with space that follows the backup GPT data structures. This command moves the backup GPT data structures to the end of the disk, where they belong.

However, I fail to understand why neither of these two commands work in my case.

Therefore, even if it does not make sense to try to use the recovery options if not even starting from scratch helps (kind of why I named the title "Are you and Expert with gdisk", nevertheless...

 2023-05-19 09:00:00 sudo gdisk /dev/sdX 
GPT fdisk (gdisk) version 1.0.9.1

Caution: invalid backup GPT header, but valid main header; regenerating
backup header from main header.

Warning! One or more CRCs don't match. You should repair the disk!
Main header: OK
Backup header: ERROR
Main partition table: OK
Backup partition table: OK

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: damaged

****************************************************************************
Caution: Found protective or hybrid MBR and corrupt GPT. Using GPT, but disk
verification and recovery are STRONGLY recommended.
****************************************************************************

Command (? for help): x

Expert command (? for help): z
About to wipe out GPT on /dev/sdX. Proceed? (Y/N): y
GPT data structures destroyed! You may now partition the disk using fdisk or
other utilities.
Blank out MBR? (Y/N): y
 2023-05-19 09:00:01 sudo gdisk /dev/sdX
GPT fdisk (gdisk) version 1.0.9.1

Partition table scan:
  MBR: not present
  BSD: not present
  APM: not present
  GPT: not present

Creating new GPT entries in memory.

Command (? for help): o
This option deletes all partitions and creates a new protective MBR.
Proceed? (Y/N): y

Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sdX.
The operation has completed successfully.
 2023-05-19 09:00:02 sudo gdisk /dev/sdX
GPT fdisk (gdisk) version 1.0.9.1

Caution: invalid backup GPT header, but valid main header; regenerating
backup header from main header.

Warning! One or more CRCs don't match. You should repair the disk!
Main header: OK
Backup header: ERROR
Main partition table: OK
Backup partition table: OK

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: damaged

****************************************************************************
Caution: Found protective or hybrid MBR and corrupt GPT. Using GPT, but disk
verification and recovery are STRONGLY recommended.
****************************************************************************

Command (? for help): r

Recovery/transformation command (? for help): /
b	use backup GPT header (rebuilding main)
c	load backup partition table from disk (rebuilding main)
d	use main GPT header (rebuilding backup)
e	load main partition table from disk (rebuilding backup)
f	load MBR and build fresh GPT from it
g	convert GPT into MBR and exit
h	make hybrid MBR
i	show detailed information on a partition
l	load partition data from a backup file
m	return to main menu
o	print protective MBR data
p	print the partition table
q	quit without saving changes
t	transform BSD disklabel partition
v	verify disk
w	write table to disk and exit
x	extra functionality (experts only)
?	print this menu

Recovery/transformation command (? for help): d

Recovery/transformation command (? for help): v

No problems found. 7679999989 free sectors (28.6 TiB) available in 1
segments, the largest of which is 7679999989 (28.6 TiB) in size.

Recovery/transformation command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sdX.
The operation has completed successfully.
 
 2023-05-19 09:00:03
GPT fdisk (gdisk) version 1.0.9.1

Caution: invalid backup GPT header, but valid main header; regenerating
backup header from main header.

Warning! One or more CRCs don't match. You should repair the disk!
Main header: OK
Backup header: ERROR
Main partition table: OK
Backup partition table: OK

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: damaged

****************************************************************************
Caution: Found protective or hybrid MBR and corrupt GPT. Using GPT, but disk
verification and recovery are STRONGLY recommended.
****************************************************************************

Command (? for help): Love IT! 

I'm outnumbered.
Have a pleasant day.

EDIT: Thank you for your reply nl6720, sadly I've tried both already.

Last edited by countrybooter (2023-05-19 09:16:53)

Offline

#4 2023-05-19 09:11:11

nl6720
The Evil Wiki Admin
Registered: 2016-07-02
Posts: 710

Re: Are you an Expert with gdisk and know more than me?

If preserving the contents of the partition table is not a concern for you, then instead of repairing it, simply zap it all away:

# sgdisk -Z /dev/INSERT_DISK_HERE

Be warned that this command will not ask for confirmation!

Offline

#5 Yesterday 10:40:59

pilou
Member
Registered: Yesterday
Posts: 1

Re: Are you an Expert with gdisk and know more than me?

Hi,
I know it is a very old post, but I have the same issue today with a brand new USB SSD drive.
I made stupid dd writes from /dev/zero to the beginning and end of the drive, just to make sure there was not some hidden spy software in the not-allocated area.
Then I tried to write a brand new GPT partition with gparted and I constantly got the corrupt table message.
So I tried the gdisk recovery method to rebuild the backup GPT, but I never get anything better than that:

Warning! One or more CRCs don't match. You should repair the disk!
Main header: OK
Backup header: ERROR
Main partition table: OK
Backup partition table: OK

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: damaged

sgdisk -Z seemed to have wiped out any MBR or GPT thing, because when I ran gdisk right after that, I got:

GPT fdisk (gdisk) version 1.0.10

Partition table scan:
  MBR: not present
  BSD: not present
  APM: not present
  GPT: not present
[...]
Command (? for help): o
This option deletes all partitions and creates a new protective MBR.
Proceed? (Y/N): Y

Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): Y
OK; writing new GUID partition table (GPT) to /dev/sdc.
The operation has completed successfully.

And yet, when I run gdisk again, the backup header is in error again, the CRC's do not match etc.
It  looks like it is impossible to write the backup header anew.

Have you ever found a solution ?

Offline

#6 Yesterday 12:21:00

frostschutz
Member
Registered: 2013-11-15
Posts: 1,600

Re: Are you an Expert with gdisk and know more than me?

Well... it's not a fake SSD, is it? ;-)

Can you reproduce it with a loop or zram device?

truncate -s 1G test.img
losetup --find --show test.img # -> /dev/loop9 or whatever

modprobe zram
zramctl --find --size=1G # -> /dev/zram9 or whatever

If so that would kinda suggest it's a bug in the program itself ...

Otherwise I'm wondering if that device simply corrupts the last sector(s) thus the GPT backup by itself? Or there is some other process corrupting it.

You could test with badblocks (with optional last_block first_block parameters so it will only test end of disk specifically).

# test the last 64K of disk non-destructively

disk=/dev/sdx

lastb=$(($(blockdev --getsize64 "${disk}")-1))
firstb=$(($(blockdev --getsize64 "${disk}")-65536))

badblocks -v -s -n -t 0 -t random -t 255 -b 1 -c 4096 "${disk}" "${lastb}" "${firstb}"

And if that's not showing bad blocks, you'd have to look at the data directly in hexdump. But unless there is obvious corruption, that requires understanding the GPT header format to see what's actually wrong about it...

Also using hexdump etc. on a device caches data, so you don't actually see changes on subsequent calls, unless you take care to avoid caches (or forcibly drop caches between calls).

You can ignore a corrupt GPT backup (it will work fine with the primary) but if the device corrupts your data in general, it's no laughing matter...

Some chipsets have built in raid or encryption capabilities, and they use the last sectors of a drive for their metadata, that's how corruption could come about, but it shouldn't actually happen on the storage device presented to the user. Instead /dev/sdx would simply be a few sectors smaller, than the physical device...

It would be a different story if mdadm or dmraid was still running on that drive but partitioning tools should detect it since opening the device (exclusively) should fail...

Note that badblocks by itself is not sufficient to reliably detect fake media. You'd have run badblocks on a cryptsetup layer to be sure (fill it entirely with random data, see if you get the entire random data back). There are more dedicated tools (h2testw, fight flash fraud and the like) that work the same way...

Last edited by frostschutz (Yesterday 12:22:06)

Offline

Board footer

Powered by FluxBB