Advertisement
v1ral_ITS

Creating entire disk drive backup .img files | And Restorein

Feb 14th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.00 KB | None | 0 0
  1. Creating an Image File
  2.  
  3. Another way to clone a drive is to create a disk image that you can move around and restore as you would a bootable USB.
  4.  
  5. Creating image files allows you to save multiple backups to a single destination, such as a large portable hard drive. Again, this process only requires one command:
  6.  
  7. dd if=/dev/sdX of=path/to/your-backup.img
  8.  
  9. To save space, you can have dd compress your backup.
  10.  
  11. dd if=/dev/sdX | gzip -c > path/to/your-backup.img.gz
  12.  
  13. This command shrinks your backup into an IMG.GZ file, one of the many compression formats Linux can handle.
  14.  
  15.  
  16. Restoring a Drive
  17.  
  18. What good are those backups if you can’t use them? When you’re ready to restore a clone, you have two options. If you used the first approach, simply swap the two destinations.
  19.  
  20. dd if=/dev/sdY of=/dev/sdX
  21.  
  22. When restoring from an image file, the same concept applies:
  23.  
  24. dd if=path/to/your-backup.img of=/dev/sdX
  25.  
  26. If your image file is compressed, then things get a little different. Use this command instead:
  27.  
  28. gunzip -c /path/to/your-backup.img.gz | dd of=/dev/sdX
  29.  
  30. To be clear, gunzip is g unzip, as in the opposite of g zip This command decrompresses your backup. Then dd replaces the existing drive with this image.
  31.  
  32.  
  33.  
  34. Parameters to Consider
  35.  
  36. You can alter your command by sticking a parameter at the end. By default, dd can take a while to transfer data. You can speed up the process by increasing the block size. Do so by adding bs= at the end.
  37.  
  38. dd if=/dev/sdX of=/dev/sdY bs=64
  39.  
  40. This example increases the default block size from 512 bytes to 64 kilobytes.
  41.  
  42. conv=noerror tells dd to continue despite any errors that occur. The default behavior is to stop, resulting in an incomplete file. Keep in mind that ignoring errors isn’t always safe. The resulting file may be corrupted.
  43.  
  44. conv=sync adds input blocks with zeroes whenever there are any read errors. This way data offsets remain in sync.
  45.  
  46. You can combine these last two as conv=noerror,sync if you so desire. There is no space after the comma.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement