Could it be possible to make a hot copy of a system?
There are several options that each have tradeoffs. You can not use dd
to clone a filesystem while it is mounted read/write or the clone will end up corrupt since the source is being changed during the copy so the destination will be partially out of date and partially not. If you really want to be able to use dd
to hot copy a partition, you can do so with LVM snapshots. This requires that you have installed the system using LVM in the first place, but then you can create a snapshot at any time, and since the snapshot is frozen and not mounted, you can safely dd
the snapshot, then remove the snapshot. The other down side to using dd
is that it wastes time copying all of the unused space in the volume, and requires the destination be at least as large, even if most of the source is unused.
Rather than use dd
, you can simply use traditional backup tools such as tar
or dump
to backup the snapshot. This has the advantage of not wasting time copying free space, and can be restored to a smaller partition as long as it has space for the files. You can also extract only some of the files to do a partial restore. You also don't have to use LVM with this method: as long as you are reasonably sure that no files are being modified when you make the backup, it is safe to do on a mounted filesystem. The worst thing that can happen is that an individual file that is modified during the backup will be corrupt, rather than the entire backup being corrupt, as can happen with dd
.
As you seem to have realized, after restoring the filesystem, you still need to reinstall grub to get the system to boot. I'm not sure why you got that error when you tried, but it seems you were using grub-legacy, since grub2 does not have a stage1.
Using something like rsync
or tar
to copy the partition may be simpler. I would mount the partition on a second mount point like /mnt
before the copy. These options also allows you to change the partition size or type. You may have structures on additional partitions as well. I often have separate partitions for /var
and /usr
. These will need to be considered as well.
You may need to dig into the grub
documentation to determine how to target the disk and partition correctly. install-grub
may make incorrect assumptions which don't do what you want.
There are tools like mondo
which allow you to create a bootable recovery CD with your OS installed on it.
I think there is no real option to do a reliable backup of a running system on the device level: Your file system would get too corrupted as you cannot freeze the current state and the backup operation takes a significant amount of time.
However you could try following options:
- Run the system within a VM. You can create a snapshot of the system and then do a backup of this snapshot. When backup is done, snapshot can be easily discarded. This solves the problems mentioned above.
- Do the backup on file-system level, not on device level. I can recommend rsnapshot for this.