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

  • Proxmox How To Purge Ceph
  • VMWare ESXi/VSphere Disable Balloon Segfault in Services Solution
  • Apache Linux Debian Ubuntu Container how to manually restart without killing
  • Docker enable UTF8 in Container to stop seeing gibberish ? characters
  • Debian 8 How To Use Apt Update Archive sources.list
  • Debian Live CD Password
  • Forbidden You don't have permission to access this resource. [authz_core:error] [pid 338:tid 338] [client 1.2.3.4:55046] AH01630: client denied by server configuration:
  • The client needs a new connection for this request as the requested host name does not match the Server Name Indication (SNI) in use for this connection.
  • Asterisk RTP/audio not working in either direction in Docker NAT with a NAT client
  • dovecot: imap(root@localhost)<3702>: Error: Mailbox INBOX: mmap(size=352609044) failed with file /var/spool/mail/root/Maildir/dovecot.index.cache: Cannot allocate memory
  • Asterisk cannot find soundfile file.c:824 ast_openstream_full: File for-tech-support does not exist in any format
  • Apache Error solution - mktemp: failed to create directory via template '/var/lock/apache2.XXXXXXXXXX': No such file or directory
  • sysctl settings to reduce buffers and caches in Linux
  • Find /dev/sd block device of ata device - ata6: SATA link up 1.5 Gbps (SStatus 113 SControl 310) ata6.00: qc timeout (cmd 0xec) ata6.00: failed to IDENTIFY (I/O error, err_mask=0x4) ata6.00: revalidation failed (errno=-5)
  • Stuttering Audio on VOIP phones when first answering a call slow and fast audio
  • How to distribute the Microsoft VC Visual Studio Redistributable Files On Your Own
  • Nvidia video resolution and codec encode decode support matrix eg. h264 4k h265 HEVC VP9 Card List from GTX, RTX, Quadro
  • Japan and China ping time observations
  • ffmpeg convert to another format eg h265 to h264
  • Apache stop bots and hackers by using forensic logging.