17/04/2008

How to create and restore partition images

You like your long-finely tuned Linux? You play around with a system often and would like to have a clean ready-to-use system in the back-hand if anything goes wrong? This might interest you then.

How to create images of partitions and restore them. (Without expensive software)

  1. Get a Live-Linux of your choice and start it
  2. Use the following command as superuser (sudo or root) to create a zipped image file of the partition of your choice
    dd if=/dev/hdax | gzip > /mntpoint/filename.img.gz
    or an uncompressed image by
    dd if=/dev/hdax of=/mntpoint/filename.img
    replace hdax by sdax where appropriate
  3. For recovering the image use (root)
    # gunzip -c /mntpoint/filename.img.gz | dd of=/dev/hdax
    or for the uncompressed version, have a look at this blog post.
    Again, replace hdax by sdax where appropriate. Ubuntu users: you need a root console (sudo -s)
A very good article about dd can be found on Wikipedia (dd)

If you want to save your image file on an external harddrive (which is probably a good idea) be careful with the file system you use and remember this limitation:

FAT32 allows for file sizes of maximal 4 GB (which most likely is much too small for any reasonable image file nowadays...)

You can use NTFS on an external harddrive but you need to mount your external harddrive by hand with read/write access - the magic word: ntfs-3g.
Another possibility to use NTFS-formatted external harddrives without manual mounting is to use a current live-cd from (x/k)ubuntu - they mount external harddrives always in read/write mode.
Backuping of a large file does indeed work, but the processing speed is very low (about 30 min for a 7,5 GB partition) due to the fact that ntfs-3g eats up a lot of processor power.

No comments: