RHEL: Back-up/Replicate a partition table

# Tested on RHEL 5, 6 & 7


# Given the importance of disk's partition table, one should consider to make a backup
# in a regular basis in order to be able to restore it in case it will get corrupted,
# modified or deleted by mistake.

# We may still have the data unchanged on the disk but without a correct partition table
# it may be almost impossible to recover it.

# To get a disk's table partition we can use the 'fdisk -l' command:


fdisk -l /dev/sda

   Disk /dev/sda: 32.2 GB, 32212254720 bytes
   255 heads, 63 sectors/track, 3916 cylinders
   Units = cylinders of 16065 * 512 = 8225280 bytes

      Device Boot      Start         End      Blocks   Id  System
   /dev/sda1   *           1          33      265041   83  Linux
   /dev/sda2              34        1958    15462562+  8e  Linux LVM
   /dev/sda3            1959        2088     1044225   8e  Linux LVM
   /dev/sda4            2089        2349     2096482+   5  Extended
   /dev/sda5            2089        2349     2096451   83  Linux


# This output may be stored in a text file. Then we could use this information to
# recreate partitions manually.

# Apart from this method we may use 'sfdisk' command to inject partition table to
# a disk:
# First we get disk's partition table to a text file (-d for "dump"):

sfdisk -d /dev/sda
   # partition table of /dev/sda
   unit: sectors

   /dev/sda1 : start=       63, size=   530082, Id=83
   /dev/sda2 : start=   530145, size= 30925125, Id=8e
   /dev/sda3 : start= 31455270, size=  2088450, Id=8e
   /dev/sda4 : start= 33543720, size=  4192965, Id= 5
   /dev/sda5 : start= 33543783, size=  4192902, Id=83

sfdisk -d /dev/sda > sda_partition_table

# and then, when needed, we could restore the partition table to the disk:

sfdisk /dev/sda < sda_partition_table

# Force option, '-f', may be useful in certain cases where a normal update is not possible



# Tip:  We can use 'sfdisk' to replicate a partition table from a disk to another disk with
# the same geometry:

sfdisk -d /dev/sda | sfdisk [-f] /dev/sdb
0 (0)
Article Rating (No Votes)
Rate this article
Attachments
There are no attachments for this article.
Comments
There are no comments for this article. Be the first to post a comment.
Full Name
Email Address
Security Code Security Code
Related Articles RSS Feed
Install OpenVPN On CentOS / RHEL 7
Viewed 2005 times since Fri, May 15, 2020
RHEL: Allowing users to ’su’ to "root" / Allowing ’root’ to login directly to the system using ’ssh’
Viewed 1861 times since Sat, Jun 2, 2018
Using etckeeper with git
Viewed 5605 times since Sun, Jun 3, 2018
SSH: Execute Remote Command or Script – Linux
Viewed 1541 times since Mon, Feb 18, 2019
Jak ustawić LVM, jak robić snapshoty oraz automatycznie powiększać LV, czyli małe howto
Viewed 3558 times since Sun, May 20, 2018
CentOS / RHEL 7 : Configuring an NFS server and NFS client Linux NFS
Viewed 15203 times since Fri, Feb 21, 2020
Yum Update: DB_RUNRECOVERY Fatal error, run database recovery
Viewed 2592 times since Fri, Jan 17, 2020
ZPOOL: Grow a zpool by adding new device(s)
Viewed 4751 times since Sun, Jun 3, 2018
HOWTO: Use SSL/port 465 in smarthost stunnel
Viewed 2619 times since Fri, Sep 28, 2018
Linux Kernel /etc/sysctl.conf Security Hardening
Viewed 22465 times since Fri, Aug 3, 2018