Difference between revisions of "Dd"
imported>ThorstenStaerk m |
imported>ThorstenStaerk |
||
Line 12: | Line 12: | ||
= Disk Backup = | = Disk Backup = | ||
+ | |||
+ | == Create a backup == | ||
Say we have a harddisk /dev/sda that we want to backup entirely (sector-by-sector) to a USB volume /dev/sdb1, mounted on /mnt/sdb1. We call this a ''dump'' or an ''image'' of /dev/sda. The dump shall be named ''backup.img''. Here is the dd command: | Say we have a harddisk /dev/sda that we want to backup entirely (sector-by-sector) to a USB volume /dev/sdb1, mounted on /mnt/sdb1. We call this a ''dump'' or an ''image'' of /dev/sda. The dump shall be named ''backup.img''. Here is the dd command: | ||
dd if=/dev/sda of=/mnt/sdb1/backup.img | dd if=/dev/sda of=/mnt/sdb1/backup.img | ||
In this command, '''if''' stands for '''i'''nput '''f'''ile and '''of''' for '''o'''utput '''f'''ile. | In this command, '''if''' stands for '''i'''nput '''f'''ile and '''of''' for '''o'''utput '''f'''ile. | ||
+ | == Restore a backup == | ||
To restore this backup, we boot from a live CD and do the command vice versa. | To restore this backup, we boot from a live CD and do the command vice versa. | ||
'''This can overwrite all content on your harddisk, this is the intention.''' | '''This can overwrite all content on your harddisk, this is the intention.''' | ||
dd if=/mnt/sdb1/backup.img of=/dev/sda | dd if=/mnt/sdb1/backup.img of=/dev/sda | ||
+ | == Clone a harddisk == | ||
To clone a disk A to B, both disks need to have the same capacity. It is very convenient for USB disks. Say our USB disk source is called /dev/sdb and the target is called /dev/sdc. Do it like this: | To clone a disk A to B, both disks need to have the same capacity. It is very convenient for USB disks. Say our USB disk source is called /dev/sdb and the target is called /dev/sdc. Do it like this: | ||
dd if=/dev/sdb of=/dev/sdc | dd if=/dev/sdb of=/dev/sdc | ||
Now if sdc has a bigger capacity, this capacity will be lost because the file system is not aware of it. | Now if sdc has a bigger capacity, this capacity will be lost because the file system is not aware of it. | ||
− | To transfer a disk image over the network, use | + | == Transfer a disk image == |
− | dd if=/dev/sdb | ssh root@target "(cat >backup.img)" | + | To transfer a disk image over the network to a computer named ''target'', use |
+ | dd if=/dev/sdb | ssh root@''target'' "(cat >backup.img)" | ||
+ | |||
+ | = create an iso image of a CD = | ||
+ | To create an iso image of a CD, read it block-by-block and save the blocks to a file: | ||
+ | dd if=/dev/cdrom of=cdimage.iso | ||
+ | |||
+ | * rescue a file that contains bad blocks | ||
+ | * analyze your disk by displaying selected [[blocks]] | ||
+ | * create your own operating system by dumping your bootloader to the boot sector | ||
+ | * benchmark the throughput of your disks |
Revision as of 09:55, 21 December 2008
dd is a utility to create a disk dump by reading every single block on a disk, e.g. your hard drive. However, its architecture is laid out so it can do much more than creating a dump. Here is what dd can do for you:
- manage a disk backup
- create a backup from a disk to a file
- restore a backup from a file to a disk
- clone a harddisk
- create a disk image and transfer it over the network
- create an iso image of a CD
- rescue a file that contains bad blocks
- analyze your disk by displaying selected blocks
- create your own operating system by dumping your bootloader to the boot sector
- benchmark the throughput of your disks
Contents
Disk Backup
Create a backup
Say we have a harddisk /dev/sda that we want to backup entirely (sector-by-sector) to a USB volume /dev/sdb1, mounted on /mnt/sdb1. We call this a dump or an image of /dev/sda. The dump shall be named backup.img. Here is the dd command:
dd if=/dev/sda of=/mnt/sdb1/backup.img
In this command, if stands for input file and of for output file.
Restore a backup
To restore this backup, we boot from a live CD and do the command vice versa. This can overwrite all content on your harddisk, this is the intention.
dd if=/mnt/sdb1/backup.img of=/dev/sda
Clone a harddisk
To clone a disk A to B, both disks need to have the same capacity. It is very convenient for USB disks. Say our USB disk source is called /dev/sdb and the target is called /dev/sdc. Do it like this:
dd if=/dev/sdb of=/dev/sdc
Now if sdc has a bigger capacity, this capacity will be lost because the file system is not aware of it.
Transfer a disk image
To transfer a disk image over the network to a computer named target, use
dd if=/dev/sdb | ssh root@target "(cat >backup.img)"
create an iso image of a CD
To create an iso image of a CD, read it block-by-block and save the blocks to a file:
dd if=/dev/cdrom of=cdimage.iso
- rescue a file that contains bad blocks
- analyze your disk by displaying selected blocks
- create your own operating system by dumping your bootloader to the boot sector
- benchmark the throughput of your disks