Everyone has nightmares about losing their machines. If the worst happens, you should be OK… if you took a backup.
A colleague of mine, Colin Markwell, compiled a helpful little guide to doing just this with Knoppix. (I liked this, as Knoppix once saved me from a very difficult situation!). He pointed out to me:
“note the links at the bottom of the file where most of the info came from. My notes are pretty-much just a compilation of info from them” Still helpful, Colin!
Here’s the guide, not prettily formatted, but easy to follow.
------------------------------------------------------------------------------
BACKUP AND RESTORE USING KNOPPIX
------------------------------------------------------------------------------
-----------
ENVIRONMENT
-----------
Source: The first partition of the first hard drive (/dev/hda1), which is
10Gb and formatted with the FAT32 file system.
Destination: A ext3 partition on an external hard disk (/mnt/sda2).
----------
BACKING UP
----------
Boot into Knoppix and mount "sda2" (destination drive we're backing up to)
by right-clicking on the icon and selecting "mount", then make it writable
by right-clicking the icon again and selecting Actions > Change read/write
mode. Open a root shell (KDE Menu > Knoppix > Root shell).
Back up the Master Boot Record - MBR - (this contains code to boot first
partition and the partition table for up to 4 primary partitions):
dd if=/dev/hda of=/mnt/sda2/hda-mbr-20041124 count=1 bs=512
Note: bs = block size (in bytes) - the MBR is 512 bytes long.
Back up the partition:
dd if=/dev/hda1 bs=1k conv=sync,noerror | gzip >/mnt/sda2/hda1-20041124.gz
Note: gzip compression used to backup faster and reduce the file size.
sync,noerror ensures that if there's a problem reading the source drive, dd
still writes the correct number of bytes so that later data isn't incorrectly
offset. Using a block size of 1k minimises the amount of data lost if a block
can't be read.
Make a note of the partition sizes:
fdisk -l /dev/hda >/mnt/sda2/hda-partition-info.txt
To back up the extended partition table (Not used this in the restore, as I
was restoring to a smaller drive and only wanted to restore the first
primary partition):
sfdisk -d /dev/hda | dd of=/mnt/sda2/hda-partition-table-20041124
---------
RESTORING
---------
Boot into Knoppix and mount "sda2" (drive that contains the backup)
by right-clicking on the icon, DON'T make it writable (prevents accidently
overwriting the backup). Open a root shell (KDE Menu > Knoppix > Root shell).
If you need to create the partition (not necessary if restoring the partition
table as part of backing up the mbr, or if the partition already exists):
fdisk /dev/hda
n [new partition]
p [primary]
1 [1st partition]
<accept default first cylinder>
1275 [end cylinder - obtained from hda-partition-info.txt]
Note: The partition can be larger than the source partition if necessary
p [print table - confirm size matches the source partition]
t [change partition's system ID - use l to list]
c ["Win95 FAT32 (LBA)"] - NTFS is 7 I think
a [toggle bootable flag on]
1 [1st partition]
w [write and quit]
Reboot Knoppix so everything's aware of the new partition layout.
Restore the MBR (without the partition table):
dd of=/dev/hda if=/mnt/sda2/hda-mbr-20041124 bs=446 count=1
Note: The partition table is at the end, bs=446 ensures we don't overwrite it.
To restore the partition table too, leave off the "bs" and "count" arguments.
Restore the partition:
gunzip -c /mnt/sda2/hda1-20041124.gz | dd of=/dev/hda1 bs=1k conv=sync,noerror
To restore the extended partition table (Not used this in the restore, as I
was restoring to a smaller drive and only wanted to restore the first primary
partition):
sfdisk /dev/hda </mnt/sda2/hda-partition-table-20041124
Reboot Knoppix so everything's aware of the new partition layout.
----------------
SPLITTING BACKUP
----------------
Splits into 1Gb files, named as follows:
hda1-20041124.gz.00
hda1-20041124.gz.01
hda1-20041124.gz.02 ...and so on.
dd if=/dev/hda1 bs=1k conv=sync,noerror | gzip -c | split -b 1024m -d - /mnt/sda2/hda1-20041124.gz.
Note the dot at the end of the command
------------------
JOINING TO RESTORE
------------------
cat hda1-20041124.gz.* | gunzip -c | dd of=/dev/hda1
--------------------------
FORMATTING A NEW PARTITION
--------------------------
Format a partition with the FAT32 file system:
mkfs.vfat -F 32 /dev/whatever
Note that this is useful as Windows XP doesn't allow you to format partitions
larger than 32Gb with FAT32.
-----------------------------------
BACKING UP OVER A NETWORK USING SSH
-----------------------------------
Preparation
-----------
On the machine containing the backup destination:
Open a root shell (KDE menu > Knoppix > Root shell)
Change the root password: (Enter this when prompted by ssh on the client)
passwd
Start the ssh daemon:
/etc/init.d/ssh start
Backing up partitions
---------------------
On the machine that is to be backed up:
Backup MBR:
dd if=/dev/hda count=1 bs=512 | ssh -c blowfish root@192.168.7.11 "dd of=/mnt/sda2/oldpc-mbr-20041127"
Backup /dev/hda1
Method 1: Compress on source machine and send over network compressed to a file:
dd if=/dev/hda1 bs=1k conv=sync,noerror | gzip -c | ssh -c blowfish root@192.168.7.11 "dd of=/mnt/sda2/oldpc-hda1-20041127.gz"
Method 2: Send over the network uncompressed and compress on the
destination machine. Use this if you're backing up a slow machine to a
quick machine over a quick network:
dd if=/dev/hda1 bs=1k conv=sync,noerror | ssh -c blowfish root@192.168.7.11 "dd bs=1 | gzip >/mnt/sda2/oldpc-hda1-20041127.gz"
Method 3: Don't compress. Use if backing up slow machines over a quick
network:
dd if=/dev/hda1 bs=1k conv=sync,noerror | ssh -c blowfish root@192.168.7.11 "dd of=/mnt/sda2/oldpc-hda1-20041127"
(replace filename with device (e.g. /dev/hda1) if restoring partition, rather than backing up to a file)
Method 4: Compress, send over network, uncompress. Use if backing up
over a slow network.
[NOT TESTED]
dd if=/dev/hda1 bs=1k conv=sync,noerror | gzip -c | ssh -c blowfish root@192.168.7.11 "gzip -d -c | dd of=/mnt/sda2/oldpc-hda1-20041127"
(replace filename with device (e.g. /dev/hda1) if restoring partition, rather than backing up to a file)
Copy across partition table information
fdisk -l /dev/hda | ssh -c blowfish root@192.168.7.11 "cat >/mnt/sda2/oldpc-partitions.txt"
Use "top" to monitor CPU performance (gzip + ssh bottlenecks) and KDE System
Guard to monitor network usage (KDE menu > System > KDE System Guard, look
under Network > Interfaces > eth0 > Receiver > Data, drag+drop onto graph
grid thing as "Multimeter" type).
Backing up files
----------------
On the source machine:
Mount relevant partition (for example):
mount /mnt/hda1
Copy files:
cd /mnt/hda1
tar cv . | ssh -c blowfish root@192.168.7.11 "cd /mnt/sda1/OldPC-C ; tar x"
To compress files using gzip, use the z flag:
tar zcv . | ssh -c blowfish root@192.168.7.11 "cd /mnt/sda1/OldPC-C ; tar zx"
Note that a list of files being copied will be output to the screen on the
source machine (due to the tar "v" flag).
--------------------------------------
BACKING UP OVER A NETWORK USING NETCAT
--------------------------------------
This doesn't use encryption, so may be faster than ssh if CPU resources
are limited.
Backing up partitions
---------------------
Backup MBR:
On the destination machine, enter the following:
netcat -l -p 10000 | dd of=/mnt/sda2/hda-mbr-20060326
"-l" = listen for incoming connection
"-p 10000" = listen on port 10000 - change if required.
On the source machine, enter the following:
dd if=/dev/hda count=1 bs=512 | netcat -w 5 192.168.7.11 10000
Backup /dev/hda1:
Destination machine:
netcat -l -p 10000 | dd of=hda1-20060326.bin
Source machine:
dd if=/dev/hda1 bs=1k conv=sync,noerror | netcat -w 5 192.168.7.11 10000
Compressing on source machine (sent over network compressed):
dd if=/dev/hda1 bs=1k conv=sync,noerror | gzip -c | netcat -w 5 192.168.7.11 10000
Compressing on destination machine (sent over network uncompressed):
netcat -l -p 10000 | gzip -c | dd of=hda1-20060326.gz
Copying across partition table info:
Destination machine:
netcat -l -p 10000 >hda-partition-info.txt
Source machine:
fdisk -l /dev/hda | netcat -w 5 192.168.7.11 10000
Backing up files
----------------
On the destination server, go to the directory you want the files to be
copied to and enter the following:
netcat -l -p 10000 | tar x
If you want to see a list of files on the destination server as they're
copied, add the "v" switch to tar:
netcat -l -p 10000 | tar xv
Ensure the destination server is running before running the command
on the source machine.
On the source machine, go to the directory you want the files to be copied
from and enter the following:
tar c . | netcat -w 5 192.168.7.11 10000
"-w 5" = wait 5 seconds for input before closing connection and ending.
If you want to see a list of files on the source machine as they're copied,
add a "v" option to tar:
tar cv . | netcat -w 5 192.168.7.11 10000
If you want to gzip compress the files as they go over the network, add
the "z" option to tar:
Destination:
netcat -l -p 10000 | tar zx
Source:
tar zc . | netcat -w 5 192.168.7.11 10000
-----------------------------------------------------
BACKUP/RESTORE TO A SHARED DRIVE ON A WINDOWS MACHINE
-----------------------------------------------------
Mount the shared drive:
mkdir /mnt/win_share
smbmount //192.168.0.1/shared /mnt/win_share -o username=colin,password=secret
Then backup/restore as you would do locally.
[ From: http://www.okmoore.com/imagedrive.html ]
-------------------
INFORMATION SOURCES
-------------------
http://www.inference.phy.cam.ac.uk/saw27/notes/backup-hard-disk-partitions.html
http://www.rajeevnet.com/hacks_hints/os_clone/os_cloning.html
http://wiki.linuxquestions.org/wiki/Dd