LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Learn the DD command (https://www.linuxquestions.org/questions/linux-newbie-8/learn-the-dd-command-362506/)

AwesomeMachine 01-10-2006 02:32 PM

Correction noted
 
Quote:

Originally Posted by Lotharster
This is not correct. Both random and urandom can in theory produce output of any byte size. They use the kernel's entropy pool to compute the random numbers. This entropy pool is filled with random noise gathered from device drivers and other sources. The important difference between the two is that /dev/random produces only as many random bits as the entropy pool contains. This results in high quality randomness, which is neccessary for kryptographic keys. In case the user demands more random bytes than currently contained in the entropy pool, the process stops until the entropy pool is refilled (waggling your mouse helps). /dev/urandom, however, does not have this restriction. If the user demands more bits than currently in the entropy pool, it produces them using a pseudo random number generator. These pseudo random numbers should not be used as cryptographic keys.

[/QUOTE]


I have made the correction

AwesomeMachine 01-10-2006 03:35 PM

You need partitions first
 
Quote:

Originally Posted by jon_flanders
I would like to clone my 13 gb windows 98 drive, divided into c: programs and d: data to a 100 gb drive via usb which I would pre-partition to say, c: 20gb , d: 30 gb.

The goal would be to then simply pop the 100 gb drive into the ide ribbon in place of the 13 gb drive. My Linux drive is currently 30gb which is sufficient for my purposes. Here's the output of df currently:

[jon@localhost ~]$ df
Filesystem Size Used Avail Use% Mounted on
/dev/hdb5 4.9G 3.6G 1.1G 78% /
/dev/hdb3 5.7G 3.3G 2.3G 60% /home/data
/dev/hda1 5.8G 5.1G 663M 89% /mnt/win_c
/dev/hda5 6.9G 4.2G 2.8G 60% /mnt/win_d
[jon@localhost ~]$

I have unmounted partitions and unused space on the 30gb drive.

Is this doable? I know I can partition the hard drive in the usb via Mandriva's Harddrake. I've done that already with an old 3gb drive.

Jon Flanders

I want to make this clear that you have two drives in the case, connected to IDE. You want to take a third drive, connect it via usb, and copy the partitions on hda to it. You will be running a desktop linux installation, and like the GUI stuff. That's fine. You can use hotplug, and just plug in the usb drive. Wait a second. In a terminal window <dmesg | tail>. Look at where linux put the usb device. It will be hd something, or sd something. Once you know the right device, you can proceed to use cfdisk or parted to partition and format your new partitions. Sector size is 512, don't specify cylinders, heads is 255, sectors per track is 63. I want you to learn the partitioning tool by messing it up a few times(man cfdisk). That way, when you have to rescue a partition, and you don't have man, at least you will have learned the tool. cfdisk has a nice user interface. When the new partitions are created, use dd to transfer the data:

dd if=/dev/hda1 of=/dev/usbpartition bs=4096 conv=notrunc,noerror
dd if=/dev/hda5 of=/dev/usbpartition bs=4096 conv=notrunc,noerror

I know you can do it. I have faith in you.

AwesomeMachine 01-10-2006 03:41 PM

Partitions
 
Quote:

Originally Posted by jon_flanders
I would like to clone my 13 gb windows 98 drive, divided into c: programs and d: data to a 100 gb drive via usb which I would pre-partition to say, c: 20gb , d: 30 gb.

The goal would be to then simply pop the 100 gb drive into the ide ribbon in place of the 13 gb drive. My Linux drive is currently 30gb which is sufficient for my purposes. Here's the output of df currently:

[jon@localhost ~]$ df
Filesystem Size Used Avail Use% Mounted on
/dev/hdb5 4.9G 3.6G 1.1G 78% /
/dev/hdb3 5.7G 3.3G 2.3G 60% /home/data
/dev/hda1 5.8G 5.1G 663M 89% /mnt/win_c
/dev/hda5 6.9G 4.2G 2.8G 60% /mnt/win_d
[jon@localhost ~]$

I have unmounted partitions and unused space on the 30gb drive.

Is this doable? I know I can partition the hard drive in the usb via Mandriva's Harddrake. I've done that already with an old 3gb drive.

Jon Flanders

If you want the new partitions different sizes than the ones being copied, make the new partitions first. Hotplug the usb drive, <dmesg | tail> in a terminal, view the new device designation in dmesg, <man cfdisk>, or install cfdisk, partition disk.

dd if=/dev/hda1 of=/dev/usbpartition bs=4096 conv=notrunc,noerror
dd if=/dev/hda5 of=/dev/usbpartition bs=4096 conv=notrunc,noerror

Bengan 01-11-2006 10:37 AM

Would it be possible to copy a directory tree to an image file and vice versa?

Matir 01-11-2006 11:10 AM

Quote:

Originally Posted by Bengan
Would it be possible to copy a directory tree to an image file and vice versa?

Basically, no. The image file needs to contain a WHOLE filesystem. If you want to make a copy of a directory tree into a single file, use tar.

sfrazier9999 01-18-2006 05:39 PM

DD Hard Drive to a File
 
I have read through this article. Very in-depth and I appreciate what you have done to explain DD. I might be asking something that you give in your example, so I will apologize in advance, if not, here is my question.

I would like to copy either the entire hard drive or each partition to a single file for which I could restore back to another hard drive later. Kind of like copy one drive to another (making a duplicate), but I don't want to do that. I want to make a copy of a hard drive to a file, store the file some where and then be able to restore that file to another hard drive. End result would be an exact copy of the first drive. The reason I don't want to do a disk to disk copy is, that the new hard drive might be the same size or larger and I do this later.

Scenario # 1

PC has 2 hard drives.

1. I would like to DD the entire Hard Drive to a single file on the 2nd hard drive
A. What would that command look like if I can do it. However, if possible, can I
only copy actual data or will it copy sector by sector. In other words if /dev/sda
is 20 Gigs, my file will be 20 Gigs. Let's say there was only 7 Gigsof data on
drive, can my file be just 7 Gigs?


Scenario # 2

PC has 1 hard drive and a DVD Burner

1. Hard drive is 20 Gigs. I have 4 gigs of Data that I would like to copy to a
single file and burn it to a DVD.
A. What would the command look like to do that if possible.

jlinkels 01-19-2006 02:09 PM

You could better use tar (standard Linux) or star (enhanced tar, freely downloadable from the Internet) for this purpose. It does exactly what you want, preserves everything from the files, compresses if you want, and when unpacking you re-create the entire tree structure.

The advantage is that is does not matter on which disk or which partition you do this, even if your partition scheme is greatly different.

Since your partitions are different, you'd have to partition your disk anyway.

(I know it works, I cloned several machines like this)

The only problem might be your boot sector. You recreate that most easily by running grub-install from a live CD after you copied all the files.

jlinkels

microsoft/linux 01-19-2006 02:18 PM

would you mind posting the steps to do this? I know it's not the topic of this thread but....

AwesomeMachine 01-22-2006 05:12 AM

Quote:

Originally Posted by sfrazier9999
I have read through this article. Very in-depth and I appreciate what you have done to explain DD. I might be asking something that you give in your example, so I will apologize in advance, if not, here is my question.

I would like to copy either the entire hard drive or each partition to a single file for which I could restore back to another hard drive later. Kind of like copy one drive to another (making a duplicate), but I don't want to do that. I want to make a copy of a hard drive to a file, store the file some where and then be able to restore that file to another hard drive. End result would be an exact copy of the first drive. The reason I don't want to do a disk to disk copy is, that the new hard drive might be the same size or larger and I do this later.

Scenario # 1

PC has 2 hard drives.

1. I would like to DD the entire Hard Drive to a single file on the 2nd hard drive
A. What would that command look like if I can do it. However, if possible, can I
only copy actual data or will it copy sector by sector. In other words if /dev/sda
is 20 Gigs, my file will be 20 Gigs. Let's say there was only 7 Gigsof data on
drive, can my file be just 7 Gigs?


Scenario # 2

PC has 1 hard drive and a DVD Burner

1. Hard drive is 20 Gigs. I have 4 gigs of Data that I would like to copy to a
single file and burn it to a DVD.
A. What would the command look like to do that if possible.

Thanks for the kudos on the OP. The way you do what you want <of=/path/file> instead of a device

jlinkels 01-22-2006 07:47 PM

Quote:

Originally Posted by microsoft/linux
would you mind posting the steps to do this? I know it's not the topic of this thread but....

apt-get install star
man star

jlinkels

blakegrover 01-27-2006 11:50 AM

I've got a question and I read through thr first page of this thread but I was wonddering if you knew of a way to do the thing I am trying to do. First this is my system setup:

1 DVD Burner
1 80 GB Hard Drive - used for my iso files and backups
1 30 GB Hard Drive - Used for my linux system
1 Swappable hard drive

What I would like to do is we have a lot of servers for our hosting service and we would like to copy the hard drives that are in each type of machine onto a DVD disc and a hard drive so in case we have a problem with a machine we can either copy the extra hard drive for that machine to a new one and put in the machine and get it working or have a copy on a dvd and jsut copy the dvd to a new hard drive.

The only way I can do it right now is I use dd to copy the hard drive from our server in my swappable hard drive bay over my 80 GB hard drive and then I can pull it out and put in the new one and copy over the data back. I have noticed you can use dd to make iso's but I don't know if the dvd will have all the partitions like the hard drive. I also noticed if the hard drive being copied is bigger than the source you need to skip the first part of the drive.

Can you help me know which commands I would need to use to do the following?

1. Copy a hard drive to a directory on my computer as a ISO. I think this one will do it:
dd if=/dev/hda of=/data/beta.iso bs=2048 conv=notrunc
2. Take an iso and copy it onto the hard drive to make it look like the previous hard drive.
3. Also be able to use the same ISO and burn a DVD.

Thanks for your help and if you have any suggestions on how I could do it differently I am open to suggestions.

Thanks
Blake

blakegrover 01-27-2006 11:53 AM

I just read this last page and it looks like other have suggested to use tar, could I use the if=/path/my.iso ? If so that would help a lot.

p.s. sorry about posting and not reading this last page, you have a great FAQ on this command

Thanks
Blake

AwesomeMachine 01-29-2006 09:39 AM

.iso files and dd
 
Quote:

Originally Posted by blakegrover
I've got a question and I read through thr first page of this thread but I was wonddering if you knew of a way to do the thing I am trying to do. First this is my system setup:

1 DVD Burner
1 80 GB Hard Drive - used for my iso files and backups
1 30 GB Hard Drive - Used for my linux system
1 Swappable hard drive

What I would like to do is we have a lot of servers for our hosting service and we would like to copy the hard drives that are in each type of machine onto a DVD disc and a hard drive so in case we have a problem with a machine we can either copy the extra hard drive for that machine to a new one and put in the machine and get it working or have a copy on a dvd and jsut copy the dvd to a new hard drive.

The only way I can do it right now is I use dd to copy the hard drive from our server in my swappable hard drive bay over my 80 GB hard drive and then I can pull it out and put in the new one and copy over the data back. I have noticed you can use dd to make iso's but I don't know if the dvd will have all the partitions like the hard drive. I also noticed if the hard drive being copied is bigger than the source you need to skip the first part of the drive.

Can you help me know which commands I would need to use to do the following?

1. Copy a hard drive to a directory on my computer as a ISO. I think this one will do it:
dd if=/dev/hda of=/data/beta.iso bs=2048 conv=notrunc
2. Take an iso and copy it onto the hard drive to make it look like the previous hard drive.
3. Also be able to use the same ISO and burn a DVD.

Thanks for your help and if you have any suggestions on how I could do it differently I am open to suggestions.

Thanks
Blake

Blake, Thanks for the kudos on the post, and to the excellent string of replies. I try to reply to every question myself, but I compliment others who have replied excellently, and have even caused me to edit the post.

DD is a bitstream duplicator. It reads/writes bit for bit. The copy is an exact bitstream duplicate of the original. Therefore, whatever file system is used for the original will be used for the copy. In other words, naming a file with an iso extension does not cause dd to write an iso9660 filesystem if the source file system is not iso9660. You can, however, write other file systems to a DVD with mkisofs and growisofs. There are linux programs available to back up to DVD, if you don't want to learn the other two commands. The fact that dd won't write to optical media is an endless pain, but that is the way it has to be.

jlinkels 02-07-2006 08:17 PM

I would like to add something about the "you copy a file system" statement.

Recently I copied a disk to another one with a bigger size. I used to use tar for this, but I did it with dd this time.

The new disk booted & worked fine, but when I issued a "df" command, all my partition sizes were reported wrong. Indeed, "df" reported all partition sizes like they were on the old, smaller disk.

This obviously happened because I copied the entire FILE SYSTEM, not the data. At the end of the day I tar-ed all the partitions, put the tar files on a different partition. Reformatted the partitions and un-tar-ed everything again, and all was fine.

IMHO this demonstrates clearly that if you want to CLONE a disk, you should use "dd". But if you want to copy a [disk | partition] to something with a different size, you should use "tar".

jlinkels

Matir 02-07-2006 08:34 PM

You could copy it (with dd) and use a resizing tool to make the filesystem occupy the full space of the new partition.


All times are GMT -5. The time now is 11:17 PM.