User Tools

Site Tools


computing:storage:disk_images

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
computing:storage:disk_images [2011/11/28 15:52]
gcooper
computing:storage:disk_images [2019/10/25 09:02] (current)
gcooper
Line 1: Line 1:
-====== Working with Disk Images ======+====== Working with Disk Images in Linux ======
  
-See also: [[computing:storage:backup_cf_ssh|Backing Up Your Compact Flash Using SSH]]+See also: **[[computing:backup:backup_cf_ssh|Backing Up Your Compact Flash Using SSH]]**
  
 ===== RSYNC To Download ISO Images ===== ===== RSYNC To Download ISO Images =====
Line 9: Line 9:
 ==== Check an rsync server for the file you want ==== ==== Check an rsync server for the file you want ====
  
-Remember the trailing backslash.+:!: Remember the trailing backslash.
  
 <file> <file>
-rsync rsync://ftp.ibiblio.org/Linux/distributions/smeserver/releases/7/iso/+rsync rsync://distro.ibiblio.org/smeserver/releases/testing/8.0beta7/iso/i386/
 </file> </file>
  
Line 23: Line 23:
 <file> <file>
 cd destination/dir cd destination/dir
-mv old_smeserver.iso smeserver.iso+mv smeserver-8.0beta6-i386.iso smeserver-i386.iso
 </file> </file>
  
-Start the download (backslash is line continuation character):+:!: Note that the dot at the end is important! 
 + 
 +Start the download:
  
 <file> <file>
-rsync -avv --stats distro.ibiblio.org::distros/smeserver/releases/testing/8/iso/i386/smeserver.iso .+rsync -avv --stats distro.ibiblio.org::smeserver/releases/testing/8.0beta7/iso/i386/smeserver-i386.iso .
 </file> </file>
  
Line 38: Line 40:
 </file> </file>
  
-==== View Disk Partitions ====+===== View Disk Partitions =====
  
 To view disk and USB pen drive partitions, log in as root and enter. To view disk and USB pen drive partitions, log in as root and enter.
Line 52: Line 54:
 Floppy Images Floppy Images
  
-==== Create an image of a floppy disk ====+===== Create an image of a floppy disk =====
  
 <file> <file>
Line 64: Line 66:
 </file> </file>
  
-==== CD/DVD (ISO) Images ====+===== CD/DVD (ISO) Images =====
  
 To mount an ISO image To mount an ISO image
Line 92: Line 94:
 </file> </file>
  
-==== To make an ISO image from files on your hard drive ====+===== To make an ISO image from files on your hard drive =====
  
 Create a directory which holds the files you want. Then use the mkisofs command. Create a directory which holds the files you want. Then use the mkisofs command.
Line 102: Line 104:
 This results in a file called ''cd.iso'' in folder ''/tmp'' which contains all the files and directories in ''/some/directory/''. This results in a file called ''cd.iso'' in folder ''/tmp'' which contains all the files and directories in ''/some/directory/''.
  
-==== To verify an ISO image file to a CD disk ====+===== To verify an ISO image file to a CD disk =====
  
 Use the md5sum command. Note that a difference in the md5sums does NOT guarantee a failed burn, but if the md5sums are the same, it is most probably a good disk/image. To improve your chances of a successful disk-to-image comparison, be sure to fully erase CD/RW disks (not 'quick') and burn using 'disk at once' (DAO). Use the md5sum command. Note that a difference in the md5sums does NOT guarantee a failed burn, but if the md5sums are the same, it is most probably a good disk/image. To improve your chances of a successful disk-to-image comparison, be sure to fully erase CD/RW disks (not 'quick') and burn using 'disk at once' (DAO).
Line 122: Line 124:
 For more info, see the man pages for mkisofs, losetup, and dd, or see the CD-Writing-HOWTO at http://www.tldp.org. For more info, see the man pages for mkisofs, losetup, and dd, or see the CD-Writing-HOWTO at http://www.tldp.org.
  
-==== DVD (ISO) Images ====+===== DVD (ISO) Images =====
  
 You can back up a DVD (even a movie) to your hard drive and restore it easily from the Linux command line. You can back up a DVD (even a movie) to your hard drive and restore it easily from the Linux command line.
  
-Assuming your DVD drive is ''/dev/hdc'', execute the following from the command line:+Assuming your DVD drive is ''/dev/sr0'', execute the following from the command line:
  
 <file> <file>
-dd if=/dev/dvd of=dvd.iso+dd if=/dev/sr0 of=dvd.iso
 </file> </file>
  
Line 135: Line 137:
  
 <file> <file>
-diff /dev/dvd dvd.iso -r+diff /dev/sr0 dvd.iso -r
 </file> </file>
  
Line 152: Line 154:
 </file> </file>
  
-==== Compact Flash or USB Key ====+===== Compact Flash or USB Key ===== 
 + 
 +==== Unmount the Filesystem ====
  
 Many newer linux distributions will automatically mount flash media once it's been inserted. You may have to unmount the media first before imaging. If you see the flash card mounted on the desktop GUI, try right clicking on the icon and selecting "umount". Many newer linux distributions will automatically mount flash media once it's been inserted. You may have to unmount the media first before imaging. If you see the flash card mounted on the desktop GUI, try right clicking on the icon and selecting "umount".
  
-Alternately at the command prompt, try:+Alternately at the command prompt, show the mounted filesystems and unmount like this:
  
 <file> <file>
-umount /dev/sdx+mount 
 + 
 +umount /dev/sdxy
 </file> </file>
  
-where "x" is a lower-case letter. You can usually determine the proper device name to use with "''fdisk -l''or "''dmesg''". You may need to be root for these commands. +where "x" and "y" are lower-case letters of the device and partition to unmount 
-Backup an Existing Device+ 
 +You can usually determine the proper device name to use with ''fdisk -l'' or ''dmesg''. You probably need to be root (or use ''sudo''for these commands. 
 + 
 +==== Backup an Existing Device ====
  
 This command assumes you have a flash device ''/dev/sdf'' and you are logged in as a regular user, not root: This command assumes you have a flash device ''/dev/sdf'' and you are logged in as a regular user, not root:
  
 <file> <file>
-sudo sh -c "dd if=/dev/sdf | gzip > Desktop/2GBUSB.backup.img.gz"+sudo sh -c "dd if=/dev/sdf | gzip > Desktop/8GBUSB.backup.img.gz"
 </file> </file>
  
-Restore the Device+==== Restore the Device ====
  
 You might issue the following command as root to write an image onto the CF or USB key: You might issue the following command as root to write an image onto the CF or USB key:
  
 <file> <file>
-gunzip -c /path/to/imagefile.img.gz > /dev/sda+gunzip -c /path/to/imagefile.img.gz > /dev/sdf
 </file> </file>
  
Line 182: Line 191:
  
 <file> <file>
-sudo sh -c "gunzip -c /path/to/imagefile.img.gz > /dev/sda"+sudo sh -c "gunzip -c /path/to/imagefile.img.gz > /dev/sdf"
 </file> </file>
  
 Warning, if you are not sure where your CF device is, you could easily overwrite all data on another disk drive in your system! Warning, if you are not sure where your CF device is, you could easily overwrite all data on another disk drive in your system!
  
-==== DD Rescue ====+===== DD Rescue =====
  
 DD Rescue is a tool for disk data recovery. More info is [[computing:storage:data_recovery|here]]. DD Rescue is a tool for disk data recovery. More info is [[computing:storage:data_recovery|here]].
  
-==== DD Command ====+===== DD Command =====
  
 The dd command copies data from one place to another. Sometimes cat can do the same thing (with redirection), but dd has options to translate data, selectively copy only part of a data stream, and buffer its reads and writes. The dd command copies data from one place to another. Sometimes cat can do the same thing (with redirection), but dd has options to translate data, selectively copy only part of a data stream, and buffer its reads and writes.
Line 201: Line 210:
 Since dd can be easily used to munge a hard drive, it (hopefully) is a superuser-only tool. Since dd can be easily used to munge a hard drive, it (hopefully) is a superuser-only tool.
  
-=== Examples ===+==== Examples ====
  
-== Creating and Restoring a hard drive backup image ==+=== Creating and Restoring a hard drive backup image ===
  
 The main options to be concerned about are if= (input file) and of= (output file). By default, dd reads from stdin and writes to stdout. Here is an example of a use for dd: The main options to be concerned about are if= (input file) and of= (output file). By default, dd reads from stdin and writes to stdout. Here is an example of a use for dd:
Line 230: Line 239:
 </file> </file>
  
-==== Backing up your Master Boot Record (MBR) ====+===== Backing up your Master Boot Record (MBR) =====
  
 You should do this before you edit your partition table so that you can put it back if you mess things up. You should do this before you edit your partition table so that you can put it back if you mess things up.
Line 244: Line 253:
 </file> </file>
  
-==== Getting around file size limitations using split ====+===== Getting around file size limitations using split =====
  
 When making images, it's possible to run up against the operating system (filesystem) file size limitations. One way to work around a given file size limitation is to use the split command. When making images, it's possible to run up against the operating system (filesystem) file size limitations. One way to work around a given file size limitation is to use the split command.
Line 269: Line 278:
  
 Cat recombines contents of the compressed and split image files to stdout, in order. Results are piped through gzip for decompression and are then written to the first partition of the hard drive with dd. Cat recombines contents of the compressed and split image files to stdout, in order. Results are piped through gzip for decompression and are then written to the first partition of the hard drive with dd.
 +
 +===== Image one Disk to Another over a Network =====
 +
 +http://www.pantz.org/software/dd/drivecopywithsshanddd.html
 +
 +First, determine which disk to work with and zero out the unused space on the source disk to make compressing the image much easier:
 +
 +<file>
 +lshw -C disk
 +
 +dd if=/dev/zero of=0bits bs=20M; rm 0bits
 +</file>
 +
 +Then boot any bootable linux distro (like sysrescuecd or a CentOS Live CD) on the source machine (holding the disk you want to image) and do something like the following.
 +
 +Create a compressed disk image as a file on a remote (perhaps intermediary) host:
 +
 +<file>
 +dd if=/dev/sdx | gzip -c | ssh user@hostname 'dd of=image_of_sdx.img.gz'
 +</file>
 +
 +Copy (image) a disk (securely) directly to a disk on a remote host:
 +
 +<file>
 +dd if=/dev/sdx | gzip -c | ssh user@hostname 'gunzip -c | dd of=/dev/sdx'
 +</file>
 +
 +Assuming ''sdx'' is the destination drive on the destination machine, the following restores the image to a local disk on the destination machine. To restore the image boot a Linux distro on the destination machine to restore and pull the image that you created and dump it back with the command:
 +
 +<file>
 +ssh user@hostname dd if=filename.img.gz | gunzip -c | dd of=/dev/sdx
 +</file>
 +
 +This will usually take a few hours so be prepared.
 +
computing/storage/disk_images.1322520752.txt.gz · Last modified: 2011/11/28 15:52 by gcooper