LinuxCommandLibrary

partclone

Clone disk partitions

TLDR

Copy a partition into an image

$ sudo partclone.[ext4|btrfs|fat32|xfs|...] [[-c|--clone]] [[-s|--source]] [/dev/sdXY] [[-o|--output]] [path/to/backup.img]
copy

Restore a partition from an image
$ sudo partclone.[ext4|btrfs|fat32|xfs|...] [[-c|--clone]] [[-s|--source]] [path/to/backup.img] [[-o|--output]] [/dev/sdXY]
copy

Display help
$ partclone.[ext4|btrfs|fat32|xfs|...] [[-h|--help]]
copy

SYNOPSIS

partclone.<fstype> [options] <source> [destination]

Examples:
To backup: partclone.ext4 -s /dev/sda1 -o sda1.img
To restore: partclone.ext4 -r -s sda1.img -o /dev/sda1
Common <fstype> include: ext2, ext3, ext4, ntfs, fat32, xfs, btrfs, reiserfs, hfs+, etc.

PARAMETERS

-s, --source <source>
    Specify the source partition or image file for the operation.

-o, --output <destination>
    Specify the destination partition or image file for the operation.

-r, --restore
    Activate restore mode (default is backup/clone mode).

-c, --clone
    Activate clone (backup) mode (backup partition to image file).

-b, --batch
    Run in batch mode, suppressing all interactive prompts.

-z, --compression <level>
    Set compression level (0-9, 0 for no compression, 9 for best compression; 'auto' can be used).

-L, --logfile <file>
    Write all messages and progress to the specified log file.

-C, --checksum
    Enable data verification with checksums for integrity checking.

-d, --debug
    Display debug messages, useful for troubleshooting.

-F, --force
    Force the operation, overriding some safety checks.

-N, --nocheck
    Do not check the image header when restoring.

-q, --quiet
    Run in quiet mode, suppressing most output messages.

-v, --version
    Display the version information of partclone.

-h, --help
    Show the help message and available options.

DESCRIPTION

partclone is a powerful and versatile command-line utility designed for backing up and restoring disk partitions. Unlike dd, which performs a bit-by-bit copy of an entire partition (including empty space), partclone intelligently copies only the allocated blocks, significantly reducing image size and backup time.

It supports a wide range of file systems, including ext2/3/4, btrfs, xfs, ntfs, hfs+, reiserfs, and more. partclone can create image files of partitions and restore them to the same or different partitions. It offers features like compression, checksum verification, and the ability to clone to/from standard input/output, making it flexible for scripting and integration with other tools like gzip or pv. It's a core component widely used by Clonezilla for its disk imaging capabilities.

CAVEATS

  • For reliable backup and restore, the target partition must typically be unmounted. Operating on a mounted partition can lead to data inconsistency.
  • Restoring an image to a smaller partition than the original source partition may require manual resizing of the filesystem beforehand, or careful handling with other tools.
  • You must use the correct partclone.<fstype> executable corresponding to the filesystem type of the partition. Using the wrong one can lead to data corruption or errors.
  • partclone operates on partitions, not entire disks. It does not handle Master Boot Records (MBRs) or partition tables directly. These must be managed separately (e.g., with dd, fdisk, or parted).

COMMON USAGE PATTERNS

  • Backup a partition to an image:
    partclone.ext4 -s /dev/sda1 -o /mnt/backup/sda1.img
  • Backup a partition with compression (piping to gzip):
    partclone.ntfs -s /dev/sda2 | gzip -c > /mnt/backup/sda2.img.gz
  • Restore an image to a partition:
    partclone.ext4 -r -s /mnt/backup/sda1.img -o /dev/sda1
  • Restore a compressed image (piping from gunzip):
    gunzip -c /mnt/backup/sda2.img.gz | partclone.ntfs -r -o /dev/sda2

FILESYSTEM-SPECIFIC EXECUTABLES

partclone is not a single universal executable. Instead, it comes as a family of binaries, each tailored for a specific filesystem type (e.g., partclone.ext4, partclone.ntfs, partclone.btrfs, etc.). You must use the variant that matches the filesystem of the partition you intend to clone or restore. This design allows partclone to optimize its operations based on the underlying filesystem structure, leading to greater efficiency and reliability.

HISTORY

partclone was primarily developed by Steven Shiau and others, serving as the underlying engine for the renowned open-source disk cloning software Clonezilla. Its development commenced in the early 2000s, driven by the need for a more efficient and filesystem-aware alternative to dd for disk imaging. It was designed to provide a robust and versatile solution for cloning and restoring partitions across various Linux distributions and other operating systems, greatly enhancing the capabilities of live system rescue and backup environments.

SEE ALSO

dd(1), rsync(1), gzip(1), bzip2(1), xz(1), pv(1), gparted(8), fdisk(8), parted(8)

Copied to clipboard