Restore gpt partition table linux

Properly backup and restore partition table in Linux [100% Working]

In my last article I gave you an overview on Public key Infrastructure (PKI) and shared the steps to generate a self signed certificate using openssl in Linux. Next let me show you the steps to clone partition table from one disk to another to repair or backup and restore partition table in Linux. The steps from this article to backup and restore partition table are performed on centOS 7 and can also be executed on RHEL 7 Linux node.

 2 ways to backup and restore partition table in Linux (CentOS / RHEL 7)

Clone and Restore partition table using ‘sfdisk’ command

Backup Partition Table

Run the command below to backup the partition table on device /dev/sda to /root/partition-sda.img :

[root@node2 ~]# sfdisk -d /dev/sda > /root/partition-sda.img
[root@node2 ~]# ls -l /root/partition-sda.img -rw-r--r-- 1 root root 259 Apr 18 14:52 /root/partition-sda.img

As you can see the output is a ASCII type text file.

[root@node2 ~]# file /root/partition-sda.img /root/partition-sda.img: ASCII text
[root@node2 ~]# cat /root/partition-sda.img # partition table of /dev/sda unit: sectors /dev/sda1 : start= 2048, size= 1048576, bootable /dev/sda2 : start= 1050624, size= 57688064, : start= 0, size= 0, : start= 0, size= 0, >

Restore Partition Table

You should then copy /root/partition-sda.img to some other storage, for example a portable USB disk.

If the partition is damaged and needs to be restored from backup, please connect your USB disk to the server and boot the server with installation media and enter rescue mode.

Do not mount the root partition at this time — select «Skip» when the system asks if you want to mount the root partition on /mnt/sysimage.

Create a temporary directory, for example /mnt/temp and mount the filesystem of your USB device which contains your backup.

# mkdir /mnt/temp # mount /dev/sdb1 /mnt/temp/ # cd /mnt/temp/

where /dev/sdb1 is the file system of the USB disk. After that, run:

To verify that the partition table has been restored, run:

Clone and Restore partition table using “dd” command

The MBR (Master Boot Record) occupies the first 446 bytes of the disk while the partition table occupies the next 64 bytes. We can use » dd » to dump the range from 447 — 510 bytes in the first sector.

Читайте также:  Просмотр системного лога linux

Backup Partition Table

For example, if the harddisk is /dev/sda , then run the command below:

# dd if=/dev/sda of=/root/partition-sda.img bs=1 count=64 skip=446

Restore Partition Table

You should then copy /root/partition-sda.img to some other storage, for example a portable USB disk.

If the partition is damaged and needs to be restored from backup, please connect your USB disk to the server and boot the server with installation media and enter rescue mode.

Do not mount the root partition at this time — select «Skip» when the system asks if you want to mount the root partition on /mnt/sysimage .

Create a temporary directory, for example /mnt/temp and mount the filesystem of your USB device which contains your backup.

# mkdir /mnt/temp # mount /dev/sdb1 /mnt/temp/ # cd /mnt/temp/

where /dev/sdb1 is the file system of the USB disk. After that, run:

# dd if=/mnt/temp/partition-sda.img of=/dev/sda bs=1 count=64 seek=446

To verify that the partition table has been restored, run:

The methods above assume that the hard drive has no bad blocks or any type of physical problems. The two methods only support MS-DOS partition tables, not GPT partition tables.

Lastly I hope the steps from the article to backup and restore partition table using sfdisk and dd command on Linux was helpful. So, let me know your suggestions and feedback using the comment section.

Related keywords: linux clone partition table, linux repair partition table, sfdisk

Didn’t find what you were looking for? Perform a quick search across GoLinuxCloud

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

Buy GoLinuxCloud a Coffee

For any other feedbacks or questions you can either use the comments section or contact me form.

Thank You for your support!!

2 thoughts on “Properly backup and restore partition table in Linux [100% Working]”

“On GPT partitions you cannot perform such backup and restore of partition table.” My understanding is the gdisk does precisely this. And that sfdisk, the current version, also supports this. So why use fdisk? Reply

Thank you for highlighting this, let me verify and may be I can either update this article or add another one for GPT partitions as well Reply

Читайте также:  Paint net linux mint

Источник

I accidentally overwrote my GPT, how do I restore it with gdisk?

gpt fdisk question I have a Hitachi drive which got its GPT corrupted, it came out of a Windows 8 computer which is less than a year old. That pretty much guarantees it was in EFI mode correct? I am trying to recover my GPT file structure on the hitachi 1 terabyte drive. I’m no computer expert, but for a novice I’m pretty proficient and can fix most computer problems and follow clear instructions. I was trying to fix my son’s computer and so I took out his harddrive and tried to reformat it. Instead of the software reformatting the external drive 1 it reformated the internal drive 0, so I lost my OS and C partition. I have the drive out and hooked up to my laptop to try and repair the file structure. I have attached my initial findings using GPT fdisk. When I choose option 2 to rebuild GPT it says the partitions overlap. I am confused on what this means or what the next step is. I would be appreciative of any help you can offer. Here is what I get when I run gdisk:

GPT fdisk (gdisk) version 0.8.10 Type device filename, or press to exit: 1: Caution: invalid backup GPT header, but valid main header; regenerating backup header from main header. Warning! Read error 0! Misbehavior now likely! Caution! After loading partitions, the CRC doesn't check out! Warning! Error 0 reading partition table for CRC check! Warning! One or more CRCs don't match. You should repair the disk! Partition table scan: MBR: MBR only BSD: not present APM: not present GPT: damaged Found valid MBR and corrupt GPT. Which do you want to use? (Using the GPT MAY permit recovery of GPT data.) 1 - MBR 2 - GPT 3 - Create blank GPT Your answer: 2 Warning! Main partition table overlaps the first partition by 34 blocks! You will need to delete this partition or resize it in another utility. Warning! Secondary partition table overlaps the last partition by 15650193771697010572 blocks! You will need to delete this partition or resize it in another utility. Command (? for help): e b back up GPT data to a file c change a partition's name d delete a partition i show detailed information on a partition l list known partition types n add a new partition o create a new empty GUID partition table (GPT) p print the partition table q quit without saving changes r recovery and transformation options (experts only) s sort partitions t change a partition's type code v verify disk w write table to disk and exit x extra functionality (experts only) ? print this menu Command (? for help): l 0700 Microsoft basic data 0c01 Microsoft reserved 2700 Windows RE 3000 ONIE boot 3001 ONIE config 4100 PowerPC PReP boot 4200 Windows LDM data 4201 Windows LDM metadata 7501 IBM GPFS 7f00 ChromeOS kernel 7f01 ChromeOS root 7f02 ChromeOS reserved 8200 Linux swap 8300 Linux filesystem 8301 Linux reserved 8302 Linux /home 8400 Intel Rapid Start 8e00 Linux LVM a500 FreeBSD disklabel a501 FreeBSD boot a502 FreeBSD swap a503 FreeBSD UFS a504 FreeBSD ZFS a505 FreeBSD Vinum/RAID a580 Midnight BSD data a581 Midnight BSD boot a582 Midnight BSD swap a583 Midnight BSD UFS a584 Midnight BSD ZFS a585 Midnight BSD Vinum a800 Apple UFS a901 NetBSD swap a902 NetBSD FFS a903 NetBSD LFS a904 NetBSD concatenated a905 NetBSD encrypted a906 NetBSD RAID ab00 Apple boot af00 Apple HFS/HFS+ af01 Apple RAID af02 Apple RAID offline af03 Apple label af04 AppleTV recovery af05 Apple Core Storage be00 Solaris boot bf00 Solaris root bf01 Solaris /usr & Mac Z bf02 Solaris swap bf03 Solaris backup bf04 Solaris /var bf05 Solaris /home bf06 Solaris alternate se bf07 Solaris Reserved 1 bf08 Solaris Reserved 2 bf09 Solaris Reserved 3 bf0a Solaris Reserved 4 bf0b Solaris Reserved 5 c001 HP-UX data c002 HP-UX service ea00 Freedesktop $BOOT eb00 Haiku BFS ed00 Sony system partitio ed01 Lenovo system partit Press the key to see more codes: ef00 EFI System ef01 MBR partition scheme ef02 BIOS boot partition fb00 VMWare VMFS fb01 VMWare reserved fc00 VMWare kcore crash p fd00 Linux RAID Command (? for help): ? b back up GPT data to a file c change a partition's name d delete a partition i show detailed information on a partition l list known partition types n add a new partition o create a new empty GUID partition table (GPT) p print the partition table q quit without saving changes r recovery and transformation options (experts only) s sort partitions t change a partition's type code v verify disk w write table to disk and exit x extra functionality (experts only) ? print this menu Command (? for help): 

Источник

Оцените статью
Adblock
detector