Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save AlexTMjugador/9ed3871a147cc494bf59c02abb5d573e to your computer and use it in GitHub Desktop.
Save AlexTMjugador/9ed3871a147cc494bf59c02abb5d573e to your computer and use it in GitHub Desktop.
Clone a ext4 partition from a computer to another over the network, even if they have different sizes, as long as the filesystem contents fit in the destination partition. UUIDs and labels are copied, so bootloader and mount configurations do not need to be updated.
# Source computer commands (run these first):
$ sudo mount -o ro /dev/sda2 /mnt
$ socat -dd -u EXEC:"sudo tar -C /mnt --acls --xattrs --numeric-owner -vcf - ." TCP-LISTEN:2212
# Destination computer commands (the UUIDs and labels can be obtained with lsblk on the source computer).
# 192.168.0.2 is the IP address of the source computer:
$ sudo mkfs.ext4 -U <source filesystem UUID> -L <source filesystem label> /dev/nvme0n1p2
# Set partition UUID with fdisk (enter expert mode)
$ sudo mount /dev/nvme0n1p2 /mnt
$ socat -dd -u TCP:192.168.0.2:2212 EXEC:"sudo tar -C /mnt --overwrite --numeric-owner -vpxf -"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment