Linux how to copy GPT partition table with dd

The old MBR 512 bytes partition table is no longer valid if you are using GPT. 

To copy a GPT table with dd to another disk do it like so:

Below sda is the source disk and destination disk is sdb (change to meet your needs).

Depending on how you use this, you have to be careful.  The assumption is that you should only dump the partition table back to a disk you will newly format.  If not you'll need to check the exact location where the partition table ends, otherwise you'd overwrite some data on the first partition.  This should not be a problem if you are just dumping the first 33 sectors as I show here, but be careful still.

Normally the way I show below SHOULD be OK as most GPT partitions I've seen installed by Windows or Linux show that the gpt table's final sector ends at 33, which means my final calculation and dd command SHOULD work but you should always double check that your partition table backup looks the same as the original disk.

If you blindly copy my command, this also assumes that your sector size is 512 bytes per sector.

Use a tool like gdisk to make sure:

gdisk -l /dev/sda

****************************************************************************
Caution: Found protective or hybrid MBR and corrupt GPT. Using GPT, but disk
verification and recovery are STRONGLY recommended.
****************************************************************************
Disk part-table-second.img: 2048 sectors, 1024.0 KiB
Sector size (logical): 512 bytes
Disk identifier (GUID): 6BC0607D-3981-4A24-A7DF-5106B48DA0A1
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 1000215182
Partitions will be aligned on 2048-sector boundaries
Total free space is 6933 sectors (3.4 MiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048          206847   100.0 MiB   EF00  EFI system partition
   2          206848          239615   16.0 MiB    8E00  Microsoft reserved ...
   3          239616       998008663   475.8 GiB   0700  Basic data partition
   4       998008832       999167999   566.0 MiB   2700  
   5       999170048      1000212479   509.0 MiB   2700  


We can see above that it says the partition table begins at sector 2 and ends at sector 33.

This would mean that we should backup using this calculation:

sector size * ending sector of partition table

To be lazy we'll say 33 sectors * 512 bytes/per sector = 16896 bytes

This would mean our backup amount would be 16896 bytes.

dd if=/dev/sda of=sda-gpt-partition-realtechtalk.img bs=16896 count=1

You can restore it like this:

dd if=sda-gpt-partition-realtechtalk.img of=/dev/yourdrive

Another fool proof way of checking if your partition table backup is good is to do a gdisk -l on the .img you dumped and compare to the actual /dev/sda, they should be the same.  If not you've made a mistake.

 

 


Tags:

linux, gpt, partition, ddthe, mbr, bytes, valid, dd, disk, sda, destination, sdb, dev, bs, img,

Latest Articles

  • Cisco How To Use a Third Party SIP Phone (eg. Avaya, 3CX)
  • Cisco Unified Communication Manager (CUCM) - How To Add Phones
  • pptp / pptpd not working in DD-WRT iptables / router
  • systemd-journald high memory usage solution
  • How to Install FreePBX in Linux Debian Ubuntu Mint Guide
  • How To Install Cisco's CUCM (Cisco Unified Communication Manager) 12 Guide
  • Linux Ubuntu Redhat How To Extract Images from PDF
  • Linux and Windows Dual Boot Issue NIC Won't work After Booting Windows
  • Cisco CME How To Enable ACD hunt groups
  • How to install gns3 on Linux Ubuntu Mint
  • How to convert audio for Asterisk .wav format
  • Using Cisco CME Router with Asterisk as a dial-peer
  • Cisco CME How To Configure SIP Trunk VOIP
  • Virtualbox host Only Network Error Failed to save host network interface parameter - Cannot change gateway IP of host only network
  • Cisco CME and C7200 Router Testing and Learning Environment on Ubuntu 20+ Setup Tutorial Guide
  • Abusive IP ranges blacklist
  • How to Install Any OS on a Physical Drive from Windows Using VMware Workstation (Linux, Windows, BSD)
  • CDN Cloudflare how to set and preserve the real IP of the client without modifying application code on Apache
  • CentOS 7 fix Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=container error was 14: curl#6 -
  • Ubuntu Debian How To Install Recommended Packages Automatically