Quote:
Originally Posted by Torben Friis
What is the dd commands for backing up and restoring?
I assume that to back on a new replacement disk I have to use a live version of Linux.
|
Yes, it is best to boot off a live CD/DVD if you wish to make a bit-for-bit copy of the drive that has the operating system installed. But booting off the live CD/DVD is not necessary if you are just imaging a CD or an USB drive to your computer, for example.
Assuming that 'sdb' is a blank equivalent-size or bigger drive than 'sda', the 'dd' command for backing up a drive to another drive is:
Code:
dd if=/dev/sda of=/dev/sdb conv=notrunc,noerror
That will make an exact copy of the first drive onto the second drive: the Windows partitions, the Linux partitions, everything on that first drive.
To restore, just switch around the drives:
Code:
dd if=/dev/sdb of=/dev/sda conv=notrunc,noerror
What you are probably looking to do is something like this:
(This example assumed you are running off a live disc and have an external hard drive mounted.)
Code:
dd if=/dev/sda of=/external/drive/name_of_image.img conv=notrunc,noerror
That will save the drive's image as a file to the external drive.
The restore command would be like this:
Code:
dd if=/external/drive/name_of_image.img of=/dev/sda conv=notrunc,noerror
You can even mount the image file you made with the 'dd' command so you can go in and copy over the needed files:
Code:
mount -o loop /external/drive/name_of_image.img /mnt/something
cd /mnt/something
cp I_need_this.jpg I_need_that.doc /to/somewhere/else
Of course, do not blindly enter the examples into your console or data loss will most likely result. Look up and adjust your command's 'if=' and 'of=' locations accordingly.
I got my start with the 'dd' command from this excellent post:
http://www.linuxquestions.org/questi...ommand-362506/
There are tons of useful examples in that post. Be sure to read up on using the 'bs=' option in your command to make the transfer go a little faster. Setting this differ from one computer to another so I intentionally left this option out in the examples. The examples will still work -- just painfully slow if the source is a very large file/drive. Do read up on why 'conv=notrunc,noerror' is necessary, too.
Entering 'man dd' in your console will give you on-hand information about the 'dd' command and all of its options. That is, assuming your man pages have been installed. If man pages are not available, googling 'man dd' also worked, too.
My advice?
Practice, practice, practice. Especially the restoration part. Use an usb drive or even a floppy drive if you still have one somewhere. The smaller the drive is, the sooner you can find out if you were successful or not (dd has no progress bar). Practice on a computer where you can afford to reinstall the operating system back on from an OS installation disk. Don't have a spare computer to practice on? Install VirtualBox (
http://www.virtualbox.org/) or another similar visualization program and practice from within.
Do not practice on your everyday computer with all your documents, pictures, or whatever important irreplaceable data it might have. There is far too much risks of data loss when practicing the 'dd' command.
Once you're comfortable with using the 'dd' command and once you have ensured that you have at least one alternative backup copy of your important data, you can then use the 'dd' command to back up and restore your important data with. Even if you've gotten comfortable with using dd, it is highly recommended to practice or test a new 'dd' command setup before you put it into real world uses. Do confirm that you can restore back or access the image file after a successful backup with the 'dd' command.
'dd' should never be used casually. Double-check and triple-check your 'dd' commands before hitting that 'Enter' button. 'dd' is cold and merciless when mistakes are made on important data.
For the purpose of backing up my important data on a regular basis, I have moved on from 'dd' to 'rysnc' and sometime even just plain old 'cp'. On the Windows machines, I uses the 'robocopy' command. While the 'dd' command is very good and important tool to know, Haertig's post included many of the reasons for my switching over. Mainly, it is just easier, better use of backup storage space, eat up less time, and more reliable in the long run.
Good luck!