Subject: bug#21070: GPT backup corruption causes parted and linux installer to crash

From: CeDeROM <[email-masked]>
Date: Wed, 15 Jul 2015 19:39:45 +0000

I have found a solution for that - use GDISK and rewrite GPT partition table.

Still, it would be nice parted to do the job :-)

root@lubuntu:~# gdisk
The program 'gdisk' can be found in the following packages:
 * gdisk
 * gdisk-noicu
Try: apt-get install <selected package>
root@lubuntu:~# apt-get install gdisk
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  gdisk
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 186 kB of archives.
After this operation, 761 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu/ trusty/main gdisk amd64
0.8.8-1build1 [186 kB]
Fetched 186 kB in 1s (154 kB/s)
Selecting previously unselected package gdisk.
(Reading database ... 113515 files and directories currently installed.)
Preparing to unpack .../gdisk_0.8.8-1build1_amd64.deb ...
Unpacking gdisk (0.8.8-1build1) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Setting up gdisk (0.8.8-1build1) ...
root@lubuntu:~# gdisk
GPT fdisk (gdisk) version 0.8.8

Type device filename, or press <Enter> to exit: /dev/sda
Warning! Disk size is smaller than the main header indicates! Loading
secondary header from the last sector of the disk! You should use 'v' to
verify disk integrity, and perhaps options on the experts' menu to repair
the disk.
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!

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): p
Disk /dev/sda: 3907029168 sectors, 1.8 TiB
Logical sector size: 512 bytes
Disk identifier (GUID): BFD8B9FE-8BF3-4AF3-B04C-326FC7FB5569
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 7812499934
Partitions will be aligned on 2048-sector boundaries
Total free space is 6890901949 sectors (3.2 TiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048          206847   100.0 MiB   EF00  EFI system partition
   2          206848          468991   128.0 MiB   0C01  Microsoft reserved part
   3          468992       307199999   146.3 GiB   0700  Basic data partition
   4       307200000       614399999   146.5 GiB   A500  FreeBSD
   5       614400000       921599999   146.5 GiB   0700  Basic data partition

Command (? for help): w
Caution! Secondary header was placed beyond the disk's limits! Moving the
header, but other problems may occur!

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/sda.
The operation has completed successfully.
root@lubuntu:~# parted
GNU Parted 2.3
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Model: ATA WDC WD20EFRX-68E (scsi)
Disk /dev/sda: 2000GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt

Number  Start   End    Size   File system  Name                          Flags
 1      1049kB  106MB  105MB               EFI system partition          boot
 2      106MB   240MB  134MB               Microsoft reserved partition  msftres
 3      240MB   157GB  157GB               Basic data partition
  msftdata
 4      157GB   315GB  157GB               FreeBSD
 5      315GB   472GB  157GB               Basic data partition
  msftdata

(parted)

-- 
CeDeROM, SQ7MHZ, http://www.tomek.cedro.info