0

I want to create a full disk backup of a linux installation (including gpt, bootloader). The system is installed on a 128GB SSD but only ~32GB are used with partitions, the rest is unallocated space. How can I backup this system without cloning the whole unallocated part? I tried dd on only the first ~32GB of the drive but then noticed, that this will not include the GPT backup at the end of the disk. My main concern here are time and disc space for backup. I can zip the whole dd image to ~4GB but this takes ~20min in addition to the ~15min for copying the whole drive.

bobbolous
  • 3
  • 1
  • I alredy found this post which explicitly warns about the problem with gpt: https://serverfault.com/questions/446529/create-image-of-a-usb-drive-without-unallocated-partition – bobbolous Sep 06 '20 at 13:59
  • 1
    Just copy the partitions. – Michael Hampton Sep 06 '20 at 15:01
  • To my understanding copying the single partitions and merging them again includes a lot of manual calculation of which sectors to be included/excluded. Then for a recover you need to know where to put the single pieces (otherwise you may end up with a GPT backup somewhere in the middle of a drive). I was hoping that this is some kind of common issue that has already been solved with a single line command. – bobbolous Sep 07 '20 at 13:23

2 Answers2

1

You can easily clone any of the partitions by pointing dd to the corresponding device at /dev, let's say /dev/sdb1, or clone the whole disk by pointing dd to the whole disk device:

Clone partition:

dd if=/dev/sdb1 bs=4096 of=sdb1.img

Clone whole disk:

dd if=/dev/sdb bs=4096 of=sdb.img

Now the thing is, if you want to backup the GPT backup at the end of the disk (you might not need to), you have no other choice than backing up the whole disk.

If the size of the resulting file is a concern, you could just compress it as you say, of course it will take longer.

Linux has already incorporated the, originally written for Solaris, hole detection technology SEEK_HOLE option in file seek operations, which allows to jump over zeroed zones, thus, if you are using a fairly recent kernel, dd should be able to jump over zeros in the storage device. For that to be possible dd version must also have been adapted to this new hole seeking mechanism.

https://www.man7.org/linux/man-pages/man2/lseek.2.html

Daniel J.
  • 214
  • 1
  • 5
0

Because you are using GPT, the boot loader is in UEFI firmware and EFI partition, and there is no MBR. The EFI partitions is a usually formatted as FAT32 file system.

There are multiple backup types with advantages and disadvantages:

  • offline full disk image - you can use clonezilla for this. You need to bring the system offline and attach the disk to another system or boot from CD/network.
  • offline partition image for all partitions + GPT partition table export - clonezilla run from CD/NET or disks attached to another running system. And for GTP: sgdisk --backup=gpt-sdX-$HOSTNAME-$(date +%F_%H%M%S).txt sdX
  • online LVM, ZFS, btrfs snapshot and backup of the snapshot to have a consistent backup
  • online application backup - if you have DBs and other applications they might have snapshoting and/or exporting mechanisms.

From the Clonezilla main page:

Many File systems are supported: (1) ext2, ext3, ext4, reiserfs, reiser4, xfs, jfs, btrfs, f2fs and nilfs2 of GNU/Linux, (2) FAT12, FAT16, FAT32, NTFS of MS Windows, (3) HFS+ of Mac OS, (4) UFS of FreeBSD, NetBSD, and OpenBSD, (5) minix of Minix, and (6) VMFS3 and VMFS5 of VMWare ESX. Therefore you can clone GNU/Linux, MS windows, Intel-based Mac OS, FreeBSD, NetBSD, OpenBSD, Minix, VMWare ESX and Chrome OS/Chromium OS, no matter it's 32-bit (x86) or 64-bit (x86-64) OS. For these file systems, only used blocks in partition are saved and restored by Partclone. For unsupported file system, sector-to-sector copy is done by dd in Clonezilla

Mircea Vutcovici
  • 16,706
  • 4
  • 52
  • 80
  • Thanks for your answer. Can clonezilla for a offline backup ignore the unallocated parts by default? – bobbolous Sep 07 '20 at 13:31
  • By defualt it is copying only allocated clusters. It is file system aware for ntfs, ext2,3,4 maybe for others too. For file systems that it doesn't recognize or that are encrypted, it will copy block by block. – Mircea Vutcovici Sep 07 '20 at 14:31