Simple rsync command to clone entire disks.
Welcome, Guest.
"When tyranny becomes law, rebellion becomes duty." -Thomas Jefferson

Author Topic: Simple rsync command to clone entire disks.  (Read 526 times)

Offline Crimson

  • Contributor
  • *******
  • Posts: 624
  • Defeating a sandwich only makes it tastier.
    • «FC» FunHouse Clan
Simple rsync command to clone entire disks.
« on: October 04, 2020, 04:14:13 PM »
I've been searching the internet for a simple solution, and I think I've found what I'm looking for. I have a fairly primitive setup, an HP 8000 USDT with a single 120GB SSD running Ubuntu Server 20.04. I have it setup just the way I want it, and I want to clone the ENTIRE SSD to another SSD. This way if the primary SSD fails, I can simply swap the primary SSD with the backup (cloned) SSD and everything will work with minimal downtime.


I THINK I found this solution with rsync, but I'm unsure on how to properly perform this task.

Say if my primary SSD is at /dev/sda and I've mounted my backup SSD at /dev/sdb, would I simply run...


Code: [Select]
rsync /dev/sda /dev/sdb
...Would that make an identical bootable clone?

Custom Linux PC AMD Ryzen 5 1600 Radeon™ RX 5700 XT 32GB DDR4 1TB M.2 NVMe 4TB Storage

Offline CwF

  • Elite Member
  • *****
  • Posts: 474
Re: Simple rsync command to clone entire disks.
« Reply #1 on: October 04, 2020, 07:56:54 PM »
...Would that make an identical bootable clone?
..kind of, and not.

How much of that 120GB does the system actually use, and is it full disk encryption?
If the answer is a few tens of gigs and not encrypted, then you could install a second OS instance on the backup disk and just image the entire primary disk to a FILE.

Offline Crimson

  • Contributor
  • *******
  • Posts: 624
  • Defeating a sandwich only makes it tastier.
    • «FC» FunHouse Clan
Re: Simple rsync command to clone entire disks.
« Reply #2 on: October 05, 2020, 12:35:55 AM »
Both of the SSD's are identical. I wanna say the server is occupying the entire disk, but is actually using a small fraction of that. No encryption that I'm aware of, it's pretty much a vanilla Ubuntu Server running Apache2, MariaDB, phpBB3, Postfix, and Webmin.

Sounds like imaging the primary disk to a file is the way to go. I'm so used to popping in an Acronis DVD and clicking a few things, BOOM!, Cloned!

CLI is very intimidating for me when it comes to these things. I already broke one installation trying Acronis. Maybe I should try Clonezilla?
Custom Linux PC AMD Ryzen 5 1600 Radeon™ RX 5700 XT 32GB DDR4 1TB M.2 NVMe 4TB Storage

Offline CwF

  • Elite Member
  • *****
  • Posts: 474
Re: Simple rsync command to clone entire disks.
« Reply #3 on: October 05, 2020, 01:00:48 AM »
Both of the SSD's are identical. . Maybe I should try Clonezilla?
A second OS is needed since an identical disk can not be mounted with the same uuid. So a simple system with the package 'qemu-utils'. This includes all you need.
For a disk to a file

Code: [Select]
qemu-img convert -p -c -O qcow2 /dev/sda /path/to/file.qcow2-c compresses therefore qcow2 needs to be the format
for file to disk

Code: [Select]
qemu-img convert -p -O raw /path/to/file.qcow2 /dev/sda-p fro progress, no -c, -O chooses raw or file format
Use bleachbit or a few other utilities to zero free space from within the running system before you make the image, this will allow the compression to work better - it WILL image extra data in a dirty filesystem, deleted files, etc, so zero the free space.
My cli/ncurses OS's are ~1GB, my base OS's are as tiny as 1.2GB, as big as 20ish.
An encrypted disk's image is the disk size. Without that, a typical OS will image and compress to about 50-60% of what your running OS told you. With further prep you can compress it to 30-40%. It's highly likely your OS will pack into a few Gigs, plus all your personal data, which is why you should separate that stuff...
So the spare disk could have a simple OS and a few copies of the primary OS, and still leave room for non-OS file backup since it is NOT a copy it can be mounted and run along side the primary OS. Grub can include both disk, from both disk...