How to copy partition table details from one drive to another in Linux ?

Today we will look at an interesting post how to copy partition table of one hard drive to another in linux.

Lets look it at step-wise to understand the scenario.

1. Backup the partition table to a file

[root@ngelinux ~]# sfdisk -d /dev/sda > sda_partitions
[root@ngelinux ~]# cat sda_partitions
# partition table of /dev/sda
unit: sectors

/dev/sda1 : start=     2048, size=  1024000, Id=83, bootable
/dev/sda2 : start=  1026048, size= 13654016, Id=8e
/dev/sda3 : start=        0, size=        0, Id= 0
/dev/sda4 : start=        0, size=        0, Id= 0

 

2. Restoring the partition table from the file to disk

[root@ngelinux ~]# sfdisk -f /dev/sda < /mnt/sda_partitions

 

3. Copy the partition table to another disk directly

[root@ngelinux ~]# sfdisk -d /dev/sda | sfdisk -f /dev/sdb

 

4. In the end, we can use mdadm to manage and rebuild our RAID devices.

[root@ngelinux ~]# mdadm --manage /dev/mdX --add /dev/sdb1
[root@ngelinux ~]# mdadm --manage /dev/mdX --add /dev/sdb2
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments