Home » Questions » Computers [ Ask a new question ]

In linux, how do I create/restore an image snapshot of my entire drive?

In linux, how do I create/restore an image snapshot of my entire drive?

I'm too spoiled by Windows utilities that take a digital snapshot of your entire drive, which you can then restore from in the event of a drive crash. (e.g. like Time Machine for Mac OS X).

Asked by: Guest | Views: 254
Total answers/comments: 5
Guest [Entry]

The tool you want (which most closely resembles Time Machine) is called rsnapshot. Unlike normal backup tools it copies only things that have changed, and it allows you easily to travel to many points in time. You can tell it how much disk space it is allowed to have, and it adjusts the number of snapshots kept to stay within that limit. A very nice tool.
Guest [Entry]

"PartImage runs from the command line or as a text GUI. It has one important advantage over dd:

Partimage will only copy data from the used portions of the partition. For speed and efficiency, free blocks are not written to the image file. This is unlike the 'dd' command, which also copies empty blocks."
Guest [Entry]

"If you're wanting a file-level backup like time machine, then I highly recommend rsnapshot as Norman suggested.

If you're wanting a full image backup and restore type solution, like norton ghost, then I've found CloneZilla to work quite well. I boot the live CD, and then use another machine as an SSH server to backup/restore the image(s) to/from.

(I even managed to get the live version working via PXE boot for an old tablet laptop I had with no CD drive and no booting of USB, but it was a lot of fiddling.)

And you can use it for windows machines too."
Guest [Entry]

"I always worried about using dd when the drives were differently sized. Or had different numbers of heads/sectors/tracks/etc.

dd is very useful when snapshotting and reflashing the same drive. Especially USB drives or windows partitions. But when going from a 500Meg to a 1500Meg drive, I get concerned.

Besides, when my drive fails, I like to be able to use it as an excuse to upgrade to a newer OS.

All that said, good old tar does a nice job! GNU-tar includes diff-tar-against-files, only-update-files-that-have-changed, and only-archive-files-newer-than-date options.

(I should mention: I did run into a bug a few years back that required me to download and install a newer version of GNU-tar. (Something to do with very long pathnames and multiple volumes.) No big deal. Just be aware that's always an option.)

You should probably exclude /proc, /sys, and perhaps /var/log/lastlog or /mnt. (I usually back up to an external drive mounted under /mnt. Backing up the backup -- not so good!)

Including /dev can be worthwhile. gnu-tar will handle devices properly (mknod). Though you probably won't use the backed up /dev during a restore. (Occasionally its nice to see what permissions or links you had set up before.)

Also, you might want to dump fdisk & rpm info before backing up. E.g.

/sbin/sfdisk -l /dev/sda > /....../info_sda
rpm -qa | sort > /...../info_rpms
rpm -qa --qf ""%{ARCH} \t %{NAME}-%{VERSION}-%{RELEASE}\n"" | sort -k2,2 > /........./info_rpms_arch

As well as mounting any ""optional"" user-mounted filesystems."
Guest [Entry]

"Here's the full steps for another method, works for moving from one hard drive to another, and even cloning a machine if the hardware is similar.

First, create an image of a good working system. Do this as root.

# cd /
# tar cpzf hostname.tgz / --exclude=hostname.tgz --exclude=proc --exclude=lost+found --exclude=mnt --exclude=sys --exclude=home --exclude=usr/src

Backup the kernel images

# mount /boot
# cd /boot
# tar cpzf boot.tgz *

Boot the machine you want the image deployed on with a live cd/gentoo cd. Mount that hard drive and partition it appropriately:

# fdisk /dev/hda
/dev/hda1 /boot
/dev/hda2 swap
/dev/hda3 /tmp
/dev/hda4 /

Add filesystems

# mke2fs /dev/hda1
# mkswap /dev/hda2
# mke2fs -j /dev/hda3
# mke2fs -j /dev/hda4

Mount drives:

# mount /dev/hda4 /mnt/new_root
# mkdir /mnt/new_root/tmp
# mkdir /mnt/new_root/boot
# mkdir /mnt/new_root/proc
# mkdir /mnt/new_root/sys
# mount /dev/hda3 /mnt/new_root/tmp
# mount /dev/hda1 /mnt/new_root/boot
# swapon /dev/hda2
# mount -t proc proc /mnt/new_root/proc

Copy over the hostname.tgz file onto this machine.

Extract it into the root of the new machine /mnt/new_root

# tar -xzf hostname.tgz

Chroot into the new environment.

# chroot /mnt/new_root /bin/bash
# env-update && source /etc/profile

Verify /boot/grub/grub.conf and /etc/fstab

Setup grub on the hard drive:

# grep -v rootfs /proc/mounts > /etc/mtab
# grub-install /dev/hda

Exit and umount drives, reboot the machine."