LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Will adding data to a hdd that already has data on it using the “dd” command overwrite the pre-existing data? (https://www.linuxquestions.org/questions/linux-newbie-8/will-adding-data-to-a-hdd-that-already-has-data-on-it-using-the-%93dd%94-command-overwrite-the-pre-existing-data-4175660483/)

hddfsck 09-07-2019 12:27 AM

Will adding data to a hdd that already has data on it using the “dd” command overwrite the pre-existing data?
 
Will adding data to a hdd that already has data on it, by using the "dd" command, overwrite that pre-existing data? I do NOT want to overwrite any data. Data is being copied over from 1 hdd to another one, both of which do not have an OS and only have 1 partition each.

DD COMMAND (example from article):
Code:

dd if=/dev/sda1 of=/dev/sdb1
The dd command is for copying over an entire partition, which is what I want to do. This commands seems to be what I need, though I am not sure what to use for "of". The partition name is NOT an 'sdxx', but rather just a name I gave it when encrypting the partition. Lsblk shows "sdx", and then "ABC" for the partition name.

I imagine I would use
Code:

"dd if=/dev/sdXX of=/dev/ABC"
since the partition name is "ABC".

I don't know if the dd command needs to include "bs=#" or not.

source: #4 from - https://tecadmin.net/drive-and-parti...th-dd-command/

Thanks.

syg00 09-07-2019 01:37 AM

The question is certainly now more understandable since your edit. However, withholding information is not going to help you get decent answers. Post the entire lsblk - uneditted. Your interpretation of what it shows is not useful.

berndbausch 09-07-2019 01:39 AM

What exactly do you want to achieve? Copy a harddisk partition to another harddisk partition, or to a file, or something different?

By definition, if you copy something from disk A to disk B, you overwrite all or part of whatever there is on disk B.

This command:
Code:

dd if=/dev/sdXX of=/dev/ABC.img
will copy the content of sdXX (presumably a SCSI disk) to a file named /dev/ABC.img. ABC.img is almost certainly not a device file. Since /dev is a RAM-based filesystem in most modern Linux distros, you will very quickly fill /dev and the command will fail.

EDIT: Section #4 on the referenced web page copies an entire disk to another disk. But you seem to have pre-existing data on the destination disk that you don't want to overwrite. It's still not clear to me what you want to achieve.

ondoho 09-07-2019 01:45 AM

Quote:

Originally Posted by hddfsck (Post 6034080)
Will adding data to a hdd that already has data on it, by using the "dd" command, overwrite that pre-existing data?
...
Code:

dd if=/dev/sda1 of=/dev/sdb1

YES, this command WILL overwrite (or rather make unusable) ALL existing data on /dev/sdb1.
You can, however, tell dd to write to a file instead of straight to the hardware.
Example:
Code:

dd if=/dev/sda1 of=/where/sdb1/is/mounted/sda1.bak
bs=<something_larger> is recommended because the default blocksize is very small (historical reasons i guess), and it would take very long to copy.

hddfsck 09-07-2019 02:35 AM

Quote:

Originally Posted by ondoho (Post 6034094)
YES, this command WILL overwrite (or rather make unusable) ALL existing data on /dev/sdb1.
You can, however, tell dd to write to a file instead of straight to the hardware.
Example:
Code:

dd if=/dev/sda1 of=/where/sdb1/is/mounted/sda1.bak
bs=<something_larger> is recommended because the default blocksize is very small (historical reasons i guess), and it would take very long to copy.

Thanks! What if...

3 hdd's:

I use the dd command to copy the 1st hdd partition to the 2nd hdd partition which is completely a 'blank' hdd. Could I then copy and paste from the 2nd hdd to the 3rd hdd (that already has data on it that I can't delete) and end up with a bit-by-bit of the original files(hdd1) but now on hdd 3? I don't think this will work - I will end up just copying the files over, but not bit-by-bit.

The purpose of copying the files by copy and paste to the 3rd hdd is to keep the encryption on the 3rd hdd.

Also, to add "bs", should I change the command to "dd if-/dev/sdx" bs=4096 of=/dev/sdb" ?

I can't have it write straight to the hardware because I will lose my encryption, but thanks.

hddfsck 09-07-2019 02:42 AM

Quote:

Originally Posted by berndbausch (Post 6034093)
What exactly do you want to achieve? Copy a harddisk partition to another harddisk partition, or to a file, or something different?

By definition, if you copy something from disk A to disk B, you overwrite all or part of whatever there is on disk B.

This command:
Code:

dd if=/dev/sdXX of=/dev/ABC.img
will copy the content of sdXX (presumably a SCSI disk) to a file named /dev/ABC.img. ABC.img is almost certainly not a device file. Since /dev is a RAM-based filesystem in most modern Linux distros, you will very quickly fill /dev and the command will fail.

EDIT: Section #4 on the referenced web page copies an entire disk to another disk. But you seem to have pre-existing data on the destination disk that you don't want to overwrite. It's still not clear to me what you want to achieve.

I want to copy the content of one hdd to another hdd. The destination hdd has data on it that can't be deleted. My goal, which I can not figure out how to do, is to copy the data from source hdd, bit-by-bit, to the hdd that 'already' has data on it, in which this partition is encrypted (only 1 partition on hdd), and do it in a way whereby I do not lose the encryption.

So, keep the encryption on final destination hdd and get it there bit by bit. Thanks.

hddfsck 09-07-2019 03:46 AM

Quote:

Originally Posted by ondoho (Post 6034094)
YES, this command WILL overwrite (or rather make unusable) ALL existing data on /dev/sdb1.
You can, however, tell dd to write to a file instead of straight to the hardware.
Example:
Code:

dd if=/dev/sda1 of=/where/sdb1/is/mounted/sda1.bak
bs=<something_larger> is recommended because the default blocksize is very small (historical reasons i guess), and it would take very long to copy.

... Using the dd command, If I have the hdd write to a file that I make on the destination hdd, can I keep my encryption on the destination drive?; I need to keep my encryption and write it in dd.

I Know that if i use a cloning device that if the contents being sent over to the destination hdd are not coming from an encrypted hdd, then the destination hdd will lose its encryption, if it originally had it.

Thanks.

berndbausch 09-07-2019 03:55 AM

Quote:

Originally Posted by hddfsck (Post 6034107)

So, keep the encryption on final destination hdd and get it there bit by bit. Thanks.

In this case, don't copy the source disk to /dev/sdX, but to the device file that represents the decrypted partition.

I may be able to provide more detailed instructions if you tell us how the destination partition is encrypted, and how you plan to use the encrypted disk. Will you attach it to a Linux computer or a different OS? Also, do you need to keep the encryption on the destination disk, or is it OK to wipe it out and re-encrypt it with a Linux-compatible method like LUKS?

hddfsck 09-07-2019 04:04 AM

Quote:

Originally Posted by berndbausch (Post 6034119)
In this case, don't copy the source disk to /dev/sdX, but to the device file that represents the decrypted partition.

I may be able to provide more detailed instructions if you tell us how the destination partition is encrypted, and how you plan to use the encrypted disk. Will you attach it to a Linux computer or a different OS? Also, do you need to keep the encryption on the destination disk, or is it OK to wipe it out and re-encrypt it with a Linux-compatible method like LUKS?

Thanks. Sounds like you are saying to create a 'file' on the destination hdd and copy the source hdd files via dd there. The encryption is LUKS and no it is not ok to wipe it out. It will be attached to a linux-OS only. But you also said that the device file would be on the "decrypted partition"; this is not good. Yes, getting the source files to the destination hdd via dd without encryption would be better than not getting it there at all, but, if possible, I was trying to see if I could do both, encryption and dd, to the destination hdd. Thanks.

zeebra 09-07-2019 04:11 AM

I think what he wants to do is to write data from source X to a location on disk destination Y with dd.

Let's say dd if=/dev/sda1 of=/dev/sda2/somefolder BS=Y. Would the data from source X then be readable through the destination folder, and would it be sane to write it to the folder in that way?

It would be possible to test this with some smaller disks, like USB sticks. Say one encrypted one 4gb with something on and write into a folder on another usb disk. Some people might already know the answer, I don't know the answer for sure, I just have a feeling it would work. Disk data is decrypted first, source could be anything.

berndbausch 09-07-2019 04:35 AM

Quote:

Originally Posted by hddfsck (Post 6034123)
Sounds like you are saying to create a 'file' on the destination hdd and copy the source hdd files via dd there

No.
Quote:

The encryption is LUKS and no it is not ok to wipe it out. It will be attached to a linux-OS only.
Attach the destination disk to the computer and identify its device file, let's say /dev/sdX. Then
Code:

cryptsetup luksOpen /dev/sdX mydestination
You will have to enter the correct passphrase. This will create a device file named /dev/dm-Y (where Y is a number) and a symbolic link /dev/mapper/mydestination that points to /dev/dm-Y. Everything written to /dev/mapper/mydestination is encrypted, then written to /dev/sdX. When you read from /dev/mapper/mydestination, data is first read from /dev/sdX, then decrypted.

Copy the source disk to this device file. Close the decrypted device with
Code:

cryptsetup luksClose /dev/mapper/mydestination
After this, an encrypted copy of your source disk is on /dev/sdX.

ehartman 09-07-2019 06:03 AM

Quote:

Originally Posted by hddfsck (Post 6034080)
Will adding data to a hdd that already has data on it, by using the "dd" command, overwrite that pre-existing data? I do NOT want to overwrite any data. Data is being copied over from 1 hdd to another one, both of which do not have an OS and only have 1 partition each.

DD COMMAND (example from article):
Code:

dd if=/dev/sda1 of=/dev/sdb1

If /dev/sdb1 (or whatever you're using as the of= partition) is EMPTY: no, there is nothing TO overwrite.
If the partition is not empty: yes, you will overwrite everything that's already there.

dd is essentially a block by block copy, so it doesn't look at the contents of the destination at all, it will make essentially a copy of the source partition to it.

BTW: the destination partition must be at least as big as the source (if=) one, or the copy will fail because of lack of space.
The arguments of dd are
if= input file (or partition, or device)
of= output file (or ...)

system001 09-07-2019 07:57 AM

after reading you originasl post i'm not even going to bother to read the rest of the post. from what your saying you're simply combining two drives, right? if so and you have the space for the operation on the one drive simply use gpoarted to do it.

install gparted if not installed
launch gparted
look at the space of the drive you want to copy, shrink it's partition down to just 10% over what's being used
look at the drive you want to copy to, shrink it's partition to just over 10% over what's being used
now look at the amount of free space you now have on the drive you want to copy to, do you have enough space to copy the one partition to?
if so then do your copy.

hddfsck 09-08-2019 09:45 AM

Quote:

Originally Posted by berndbausch (Post 6034131)
No.


Attach the destination disk to the computer and identify its device file, let's say /dev/sdX. Then
[code]
cryptsetup luksOpen /dev/sdX mydestination

"This will create a device file named /dev/dm-Y (where Y is a number) and a symbolic link /dev/mapper/mydestination that points to /dev/dm-Y. Everything written to /dev/mapper/mydestination is encrypted, then written to /dev/sdX. When you read from /dev/mapper/mydestination, data is first read from /dev/sdX, then decrypted."

Copy the source disk to this device file. Close the decrypted device with
Code:

cryptsetup luksClose /dev/mapper/mydestination
After this, an encrypted copy of your source disk is on /dev/sdX.

Thanks.
Copy the source disk to this device file.

#1) Which file? (1) /dev/dm-Y or (2) /dev/mapper/mydestination ?

Seems like you are referring to "/dev/dm-Y" since that is "file" and the other is a "symbolic link".

#2) The files are going to be copied "byte-by-byte"? I have deleted files on the source disk and if in trying to get those files back the disk gets corrupted, I need to have an exact replica, byte-by-byte, that I can use to try to get those files back.

Just to be sure: you do know that I (1) already have data on the destination drive and (2) the destination drive IS already encrypted with LUKS? I think you do. Thanks.

hddfsck 09-08-2019 09:47 AM

Quote:

Originally Posted by ehartman (Post 6034155)
If /dev/sdb1 (or whatever you're using as the of= partition) is EMPTY: no, there is nothing TO overwrite.
If the partition is not empty: yes, you will overwrite everything that's already there.

dd is essentially a block by block copy, so it doesn't look at the contents of the destination at all, it will make essentially a copy of the source partition to it.

BTW: the destination partition must be at least as big as the source (if=) one, or the copy will fail because of lack of space.
The arguments of dd are
if= input file (or partition, or device)
of= output file (or ...)

Thanks. Sounds like you are saying that the method that I described "if,of" will not work for my particular circumstance.


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