You can use dd
to copy the entire partition, as in:
dd if=/dev/sda3 of=windows-xp.img
(Change /dev/sda3
and the output filename as necessary.) You'd then reverse the process to copy it back:
dd if=windows-xp.img of=/dev/sda3 bs=4096
Note that I've added bs=4096
as an option. This causes output to be sent in chunks of 4096 bytes, which is likely to be faster on most modern disks. (This will have little or no effect when creating the backup, though.)
Although using dd
, as you specified in your question, will work, it's inefficient. A better way is to use a tool called ntfsclone
, at least assuming the partition uses NTFS. (This is a Linux tool. Based on the fact that you specified dd
and said you're using a live CD, I'm assuming it's Linux.) To clone a partition with ntfsclone
, you'd use something like this:
ntfsclone --save-image --output windows-xp.img /dev/sda3
Restoring it requires a command like this:
ntfsclone --restore-image --overwrite /dev/sda3 windows-xp.img
There are more examples of its use near the end of the ntfsclone
man page (type man ntfsclone
to read it).
The advantage of ntfsclone
is that it uses a sparse file format, which means that it doesn't back up sectors that aren't in use. By contrast, dd
copies everything, so if the partition has lots of unused space, dd
will probably take longer and will definitely chew up more disk space. Depending on the state of the disk before you installed XP, compressing the dd
backup might not help that much, since the unused sectors might have old data on them.
Either way, there are a few caveats to keep in mind:
- Both
ntfsclone
and dd
will back up the boot loader data in the Windows partition, but not the boot loader on the disk's MBR. You'll have to back that up separately. (OTOH, you said that the disk is GPT, and Windows XP can't boot from GPT disks, except for some exotic Itanium builds, IIRC. Are you using this in a virtualization environment?)
- Both
dd
and ntfsclone
pose a risk of serious damage if you enter the wrong device filename, particularly when restoring the image. If the restore target is the wrong partition, you're likely to wipe out everything on that target, which could be disastrous. Be very careful!
- You need
root
privileges to execute these commands. Depending on your live CD environment, that might be the default, or you might have to add sudo
to the start of each command.
If you can give up dd usage you can try Clonezilla - its will be faster than dd (only used blocks are cloned). – g2mk – 2015-11-19T05:29:04.397