On my Debian 8 server HDD /dev/sda crashed. mdadm informed me via email and I had the disk replaced.After the server was back up I copied over my GPT from using sgdisk -R /dev/sdb /dev/sda. The second I hit Enter on my keyboard I realized my mistake.So now I have an empty GPT on both disks. My question is if it is possible to re-create the GPT on /dev/sdb as the server is still running as I did not reboot since copying the wrong GPT?I did a backup with sfdisk -d /dev/sdb > sdb.partition.table before the faulty HDD was replaced. But as I did not do a backup with sgdisk the backup is completely useless, if I am correct?Additionally I have this output from fdisk -l from before copying the GPT:Disk /dev/sdb: 2.7 TiB, 3000592982016 bytes, 5860533168 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 4096 bytesI/O size (minimum/optimal): 4096 bytes / 4096 bytesDisklabel type: gptDisk identifier: 454774BD-960F-45C6-8C82-AE5C156444E0Device        Start        End    Sectors  Size Type/dev/sdb1      4096   33558527   33554432   16G Linux RAID/dev/sdb2  33558528   34607103    1048576  512M Linux RAID/dev/sdb3  34607104 5860533134 5825926031  2.7T Linux RAID/dev/sdb4      2048       4095       2048    1M BIOS bootPartition table entries are not in disk order.Disk /dev/md0: 16 GiB, 17171349504 bytes, 33537792 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 4096 bytesI/O size (minimum/optimal): 4096 bytes / 4096 bytesDisk /dev/md1: 511.7 MiB, 536543232 bytes, 1047936 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 4096 bytesI/O size (minimum/optimal): 4096 bytes / 4096 bytesDisk /dev/md2: 2.7 TiB, 2982739705856 bytes, 5825663488 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 4096 bytesI/O size (minimum/optimal): 4096 bytes / 4096 bytes
(Re-)Create GPT from existing partitions on Debian 8
gpt;partition table
After researching a bit and after trying out tools such as testdisk, I did not find a defintive way to restore my original GPT on /dev/sdbSo I tried using cgdisk and it was successfull, as I still had the original sector layout of /dev/sdb noted down:Disk identifier: 9F95A04D-3ECB-144D-B2A0-55CDD986072BDevice        Start        End    Sectors  Size Type/dev/sdb1      4096   33558527   33554432   16G Linux RAID/dev/sdb2  33558528   34607103    1048576  512M Linux RAID/dev/sdb3  34607104 5860533134 5825926031  2.7T Linux RAID/dev/sdb4      2048       4095       2048    1M BIOS bootWith this information I created partitions with the same starting sectors, the same number of sectors used and the same file system types as stated above.After writing the GPT on /dev/sdb, fdisk -l /dev/sdb gave me the same output as above.I then copied over the GPT by using sgdisk -R /dev/sda /dev/sdb (this time in the correct order) and fdisk -l /dev/sda showed me the exact same sector layout for /dev/sda as for /dev/sdb:Disk identifier: 4CB38488-8B72-44AA-8449-4E4692165893Device        Start        End    Sectors  Size Type/dev/sdb1      4096   33558527   33554432   16G Linux RAID/dev/sdb2  33558528   34607103    1048576  512M Linux RAID/dev/sdb3  34607104 5860533134 5825926031  2.7T Linux RAID/dev/sdb4      2048       4095       2048    1M BIOS bootAll that was left to do, was to resync the RAID-Volumes using mdadm and re-install grub2. After resyncing was done, as mentioned, I re-installed grub2 on /dev/sda (I re-installed it /dev/sdb too, just to be sure) and generated a new devicemap. (I had to flush the HDD buffers to avoid the grub2 core image warnings, though) I rebooted the server and it came up again just fine.IMPORTANT: I only did this GPT tinkering because I have a complete backup of my server as I was not 100% sure this would work and I could have destroyed my partitions.