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

  • How high can a Xeon CPU get?
  • bash fix PATH environment variable "command not found" solution
  • Ubuntu Linux Mint Debian Redhat Youtube Cannot Play HD or 4K videos, dropped frames or high CPU usage with Nvidia or AMD Driver
  • hostapd example configuration for high speed AC on 5GHz using WPA2
  • hostapd how to enable and use WPS to connect wireless devices like printers
  • Dell Server Workstation iDRAC Dead after Firmware Update Solution R720, R320, R730
  • Cloned VM/Server/Computer in Linux won't boot and goes to initramfs busybox Solution
  • How To Add Windows 7 8 10 11 to GRUB Boot List Dual Booting
  • How to configure OpenDKIM on Linux with Postfix and setup bind zonefile
  • Debian Ubuntu 10/11/12 Linux how to get tftpd-hpa server setup tutorial
  • efibootmgr: option requires an argument -- 'd' efibootmgr version 15 grub-install.real: error: efibootmgr failed to register the boot entry: Operation not permitted.
  • Apache Error Won't start SSL Cert Issue Solution Unable to configure verify locations for client authentication SSL Library Error: 151441510 error:0906D066:PEM routines:PEM_read_bio:bad end line SSL Library Error: 185090057 error:0B084009:x509 certif
  • Linux Debian Mint Ubuntu Bridge br0 gets random IP
  • redis requirements
  • How to kill a docker swarm
  • docker swarm silly issues
  • isc-dhcp-server dhcpd how to get longer lease
  • nvidia cannot resume from sleep Comm: nvidia-sleep.sh Tainted: Linux Ubuntu Mint Debian
  • zfs and LUKS how to recover in Linux
  • [error] (28)No space left on device: Cannot create SSLMutex Apache Solution Linux CentOS Ubuntu Debian Mint