From ab02d87e4f9acdc1cb35805e93bf24c819ad035a Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Fri, 19 Sep 2014 11:31:07 +0200 Subject: sfdisk: add --backup and --backup-file The option --backup force sfdisk to store *all* fragments of the partition table (including MBR partition tables store in the extended partitions) to $HOME/sfdisk--.bak The options -O, -backup-file allows to override the default path, but sfdisk still appends -.bak to the . The backup files always contain only raw data from the device, so it's possible to use dd(1) to restore original data on the device. The original sfdisk also supported -O , but semantic was little bit different: - all was based on 512-byte sectors - all sectors was stored to the one file in format |||... this original concept makes the backup files specific to sfdisk and with dependence on sector size. The new concept is the same we already use for wipefs(8) backup files. Example (disk with GPT): # sfdisk /dev/sda --backup Welcome to sfdisk (util-linux 2.25.202-f4deb-dirty). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Backup files: PMBR (offset 0, size 512): /root/sfdisk-sda-0x00000000.bak GPT Header (offset 512, size 512): /root/sfdisk-sda-0x00000200.bak GPT Entries (offset 1024, size 16384): /root/sfdisk-sda-0x00000400.bak Signed-off-by: Karel Zak --- disk-utils/sfdisk.c | 126 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 113 insertions(+), 13 deletions(-) (limited to 'disk-utils/sfdisk.c') diff --git a/disk-utils/sfdisk.c b/disk-utils/sfdisk.c index 45121f5e6..1a6db9877 100644 --- a/disk-utils/sfdisk.c +++ b/disk-utils/sfdisk.c @@ -39,6 +39,7 @@ #include "closestream.h" #include "colors.h" #include "blkdev.h" +#include "all-io.h" #include "libfdisk.h" #include "fdisk-list.h" @@ -75,6 +76,7 @@ struct sfdisk { int act; /* action */ int partno; /* -N , default -1 */ const char *label; /* --label