Yes, you need to backup both data and disk’s partition table. This is useful for:
- Replicating disk’s partition for Linux software RAID in case of disk failure.
- Dealing with corrupted partition table.
- Dealing with deleted partition table by mistake as data may still exists on the disk and can be accessed again with a correct partition table.
| Tutorial details | |
|---|---|
| Difficulty level | Advanced |
| Root privileges | Yes |
| Requirements | Linux terminal |
| Category | Disk Management |
| OS compatibility | AlmaLinux • Alpine • Amazon Linux • Arch • CentOS • Debian • Fedora • Linux • Mint • Mint • openSUSE • Pop!_OS • RHEL • Rocky • Slackware • Stream • SUSE • Ubuntu |
| Est. reading time | 5 minutes |
How to see my current partition table
Type the following command to list partitions of each device:
# fdisk -l
# fdisk -l /dev/sda
OR
# sfdisk -l
# sfdisk -l /dev/sda
Sample outputs:
How do I back-up Linux partition with sfdisk command?
To backup /dev/sda partition table, enter:
# sfdisk -d /dev/sda > sda.partition.table.12-30-2015.txt
Copy sda.partition.table.12-30-2015.txt to NFS mounted share or a USB pen drive.
How do I restore the Linux partition with sfdisk command to the disk?
# sfdisk /dev/sda < sda.partition.table.12-30-2015.txt
# sfdisk /dev/sda < /path/to/usb/pen/sda.partition.table.12-30-2015.txt
OR
# sfdisk -f /dev/sda < /media/usb/sda.partition.table.12-30-2015.txt
How do I replicate a disk partition table from /dev/sda to /dev/sdd with the same geometry?
This is useful for Linux based software RAID device. Say you replaced /dev/sdd and you want to rebuild the Linux software RAID array. The first step is to replicate a partition table from a disk to another disk:
# sfdisk -d /dev/sda | sfdisk -f /dev/sdd
Now, run the following to verify that both hard drives have the same partitioning:
# fdisk -l /dev/sda
# fdisk -l /dev/sdd
Finally, use mdadm to manage and rebuild your RAID device:
# mdadm --manage /dev/mdX --add /dev/sdd1
# mdadm --manage /dev/mdX --add /dev/sdd2
....
..
# mdadm --manage /dev/mdX --add /dev/sddN
Use the following watch command to see raid array sync progress using the /proc/mdstat. For instance:
# watch cat /proc/mdstat
BACKING UP THE PARTITION TABL
Backup up the Linux partition table
It is recommended that you save the layout of your devices. The target disk must be the same size. For example, if the old disk is 1TB, then ensure that the new disk is also 1TB in size. The sfdisk command helps you in two different ways.
Method #1: Dump in sfdisk compatible format
The first one as discussed earlier using the --dump option. For example, /dev/sdc:
# sfdisk --dump /dev/sdc > /path/to/sdc.dump
This /path/to/sdc.dump can later be restored by typing the following command when you replace /dev/sdc with a new disk:
# sfdisk /dev/sdc < /path/to/sdc.dump
Method #2: Full binary backup
Please note that if you want to do a full binary backup of all sectors where the partition table is stored, then use the --backup-pt-sectors option. This only works with Linux utilities version 2.38.xx or above:
$ /sbin/sfdisk --version
Outputs:
sfdisk from util-linux 2.38.1
It writes the sectors to ~/sfdisk-{device}-{offset}.bak files. The default name of the backup file can be changed with the --backup-file option if required. The backup files contain only raw data from the device. For example, if the device name is /dev/sdc or /dev/nvme1n1 (PCIe SSD), then:
# sfdisk --backup-pt-sectors /dev/sdc
# sfdisk --backup-pt-sectors /dev/nvme1n1
# verify using the ls command/file command #
# ls -l ~/sfdisk*.bak
# file ~/sfdisk-nvme1n1-0x00000000.bak
# dd if=~/sfdisk-sdc-0x00000200.bak of=/dev/sdc seek=$((0x00000200)) bs=1 conv=notrunc
⚠️ ❗ 🚨 A note about the --backup option
There is a --backup option, which is confusing and dangerous too. It also creates the same backup immediately after startup for other sfdisk commands. For example, backup the partition table before deleting all partitions from the partition table. This command needs to be used from a rescue disk. This is useful for experienced Linux sysadmins who want to backup first, then delete it and create a new partition table again. Most users can avoid such command option, and it is only added here to warn you or if you are an experienced sysadmin who needs such a functionality for edge cases. Stick with method #1 or #2. Example:
# sfdisk --backup --delete /dev/{DEVICE_NAME_HERE}
A note about disks with GPT (GUID Partition Table)
From the man page:
GPT fdisk (aka gdisk) is a text-mode menu-driven program for creation and manipulation of partition tables. It will automatically convert an old-style Master Boot Record (MBR) partition table or BSD disklabel stored without an MBR carrier partition to the newer Globally Unique Identifier (GUID) Partition Table (GPT) format, or will load a GUID partition table. When used with the -l command-line option, the program displays the current partition table and then exits.
Let us install gdisk on a Debian or Ubuntu Linux using apt-get command:
$ sudo apt-get install gdisk
Sample outputs:
Reading package lists... Done Building dependency tree Reading state information... Done The following extra packages will be installed: libicu52 The following NEW packages will be installed: gdisk libicu52 0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded. Need to get 6,937 kB of archives. After this operation, 28.7 MB of additional disk space will be used. Do you want to continue? [Y/n] y Get:1 http://archive.ubuntu.com/ubuntu/ trusty-updates/main gdisk amd64 0.8.8-1ubuntu0.1 [185 kB] Get:2 http://security.ubuntu.com/ubuntu/ trusty-security/main libicu52 amd64 52.1-3ubuntu0.4 [6,752 kB] Fetched 6,937 kB in 24s (284 kB/s) Selecting previously unselected package libicu52:amd64. (Reading database ... 65753 files and directories currently installed.) Preparing to unpack .../libicu52_52.1-3ubuntu0.4_amd64.deb ... Unpacking libicu52:amd64 (52.1-3ubuntu0.4) ... Selecting previously unselected package gdisk. Preparing to unpack .../gdisk_0.8.8-1ubuntu0.1_amd64.deb ... Unpacking gdisk (0.8.8-1ubuntu0.1) ... Processing triggers for man-db (2.6.7.1-1ubuntu1) ... Setting up libicu52:amd64 (52.1-3ubuntu0.4) ... Setting up gdisk (0.8.8-1ubuntu0.1) ... Processing triggers for libc-bin (2.19-0ubuntu6.6) ...
RHEL/CentOS/Fedora/Alma/Rocky/Oracle Linux user use the yum command (or dnf command) to install the same:
# yum install gdisk
Fedora Linux user use the dnf command to install the same:
# sudo dnf install gdisk
OpenSUSE Linux user use the yast command to install the same:
# yast install gdisk
Alpine Linux users try the apk command:
# apk add sgdisk
Please note that sgdisk command works with both Linux and Unix-like system such as FreeBSD and others.
How do I backup /dev/sda GPT partition table to a file?
To save partition data to a backup file called /root/sda_partition_table_12_30_2015, run:
# sgdisk --backup={/path/to/file} {/dev/device/here}
# sgdisk --backup=/root/sda_partition_table_12_30_2015 /dev/sda
How do I restore GPT partition table from a file?
To restore the backup use:
# sgdisk --load-backup={/path/to/file} {/dev/device/here}
# sgdisk --load-backup=/media/usb/sda_partition_table_12_30_2015 /dev/sda
How do I replicate GPT partition scheme from /dev/sda to /dev/sdd (RAID array rebuild)?
The syntax is:
# sgdisk -R {SECOND-DEVICE-NAME-HERE} /dev/sda
# sgdisk -R /dev/sdd /dev/sda
To randomize the GUID on the /dev/sdd, enter:
# sgdisk -G /dev/sdd
Finally, verify that both hard drives have the same partitioning schema:
# sgdisk -p /dev/sda
# sgdisk -p /dev/sdd
Finally, use the mdadm command as explained earlier to rebuild the RAID array on Linux.
Summing up
This guide helps sysadmins and developers who work primarily with bare metal Linux or Unix servers. You need to practice using a VM or space server and disks a bit in advance to get comfortable with the whole procedure. When restoring a partition, you need to boot from a rescue media and then feed the backup file to restore the partition on a new disk. Hence, it is recommended that you practice these commands in a lab environment first. See the following manual pages using the man command or help command:
$ man sgdisk
$ man fdisk
$ man mdadm
$ man sfdisk
🥺 Was this helpful? Please add a comment to show your appreciation or feedback.



Thanks
Thank you so much, easy to read and very useful
instructions for sfdisk –backup are either out of date or incomplete for an MBR disk, using sfdisk from util-linux 2.34
if not forcing a non-default backup file, you also need to issue commands in the sfdisk shell, which could (potentially) obliterate you partition table.
also, the man pages made no mention of this, which is very unnerving in a precarious recovery situation/
root@ooboonII:~# sfdisk --backup /dev/sdb Welcome to sfdisk (util-linux 2.34). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Checking that no-one is using this disk right now ... OK Backup files: MBR (offset 0, size 512): /root/sfdisk-sdb-0x00000000.bak Disk /dev/sdb: 1.84 TiB, 2000398934016 bytes, 3907029168 sectors Disk model: ASMT1051 Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 33553920 bytes Disklabel type: dos Disk identifier: 0x873766a9 Old situation: Device Boot Start End Sectors Size Id Type /dev/sdb1 * 2048 206847 204800 100M 7 HPFS/NTFS/exFAT /dev/sdb2 206848 3905974363 3905767516 1.8T 7 HPFS/NTFS/exFAT /dev/sdb3 3905976320 3907026943 1050624 513M 27 Hidden NTFS WinRE Type 'help' to get more information. >>>Thank you for the clear example of restoring a GPT partition backup from a file to a device.