LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Qustions re using 'dd' command (https://www.linuxquestions.org/questions/linux-newbie-8/qustions-re-using-dd-command-4175685570/)

DownSouth 11-21-2020 01:03 AM

Qustions re using 'dd' command
 
Hello

I'm intending to use the 'dd' command to transfer a Linux installation from one USB
to another USB. The target partition will be slightly larger than the source partition.
I have researched the details of the command and triple checked with other reliable
sources. However, there are a couple of questions I need answered before I begin.

I will use a host system, plug in the source USB and once it's mounted plug in the
target USB & run the command from the host system. Process will be performed
on a fairly basic machine with just 2GB ram.

First question: do both USBs need to be mounted or, just the source USB?

Logic suggests they should both be mounted, but logic without experience is why
a worthwhile forum such as LQ is necessary. :-)

Second question - the numerical figure in the command to specify the data transfer
rate - should that be kept to a fairly low level (say, 4096) to ensure accuracy?
The source partition is about 12GB.

thanks
DownSouth

lvm_ 11-21-2020 01:38 AM

If the source device is being written to during copying you may will end up with corrupted target filesystem, so the source device must be either not mounted at all or mounted read-only. Target must not be mounted as modifying a mounted filesystem bypassing its driver will result in all sorts of nasty consequences. If target device is larger you will have to resize partitions and filesystems after copying to utilize all available space. Restricting bandwidth will not affect copying accuracy, its primary and only goal is to manage system load.

berndbausch 11-21-2020 01:43 AM

If you want to copy one partition (e.g. /dev/sdb1) to another (e.g. /dev/sdc1), neither the source nor the target should be mounted. The command would be something like
Code:

dd if=/dev/sdb1 of=/dev/sdc1 bs=1M
I am not aware of a dd parameter that specifies the data transfer rate. It goes as fast as it can. The bs parameter in my example indicates the amount of data tranferred by a single read and write request. The larger it is, the fewer I/O requests are generated, leading to less overhead and better performance.

ondoho 11-21-2020 01:53 AM

Quote:

Originally Posted by DownSouth (Post 6187401)
First question: do both USBs need to be mounted or, just the source USB?

Logic suggests they should both be mounted, but logic without experience is why
a worthwhile forum such as LQ is necessary. :-)

Mounting is for filesystems.
dd does not (necessarily) deal with filesystems, mounting is not required, might even be harmful to write operations.

Quote:

Originally Posted by berndbausch (Post 6187412)
I am not aware of a dd parameter that specifies the data transfer rate. It goes as fast as it can. The bs parameter in my example indicates the amount of data tranferred by a single read and write request. The larger it is, the fewer I/O requests are generated, leading to less overhead and better performance.

That said, the default blocksize is so small that it will go significantly slower.
I usually use bs=4M, but if there's enough memory one could go int GBs... e.g. bs=1G
This does not affect accuracy in any way whatsoever.
dd is always bit-precise.

DownSouth 11-21-2020 02:18 AM

Many thanks for the detailed responses, everyone.

Just one more question - bs=4M, given that the host machine only has 2GB ram could I (safely)
raise that to bs=10M? Thinking of the other comment that the less I/O requests there are the
better the performance. Or, would keeping to bs=4M be recommended for that machine?

syg00 11-21-2020 02:33 AM

The bs parameter is merely logical - I did some low-level tracing and it appears to make no difference to the actual physical I/O performed. I use 4M on much larger systems, purely out of habit.

DownSouth 11-21-2020 03:55 AM

Quote:

Originally Posted by syg00 (Post 6187426)
The bs parameter is merely logical - I did some low-level tracing and it appears to make no difference to the actual physical I/O performed. I use 4M on much larger systems, purely out of habit.

Thanks - appreciate you responding.

computersavvy 11-22-2020 10:20 AM

Quote:

Originally Posted by DownSouth (Post 6187425)
Many thanks for the detailed responses, everyone.

Just one more question - bs=4M, given that the host machine only has 2GB ram could I (safely)
raise that to bs=10M? Thinking of the other comment that the less I/O requests there are the
better the performance. Or, would keeping to bs=4M be recommended for that machine?

With 2G memory you would be ahead to check how much memory is actually free with the system operating. Use the "free" command and it will tell you how much is available, used, free, and more. I would suggest using any block size you choose up to about half of the free memory number, although you should make it in increments of 1K multiples. If your memory starts to get full then it will begin to swap excessively and really slow things down.

As has already been mentioned, having both source and destination unmounted is best.

DownSouth 12-09-2020 03:35 AM

Quote:

Originally Posted by computersavvy (Post 6187814)
With 2G memory you would be ahead to check how much memory is actually free with the system operating. Use the "free" command and it will tell you how much is available, used, free, and more. I would suggest using any block size you choose up to about half of the free memory number, although you should make it in increments of 1K multiples. If your memory starts to get full then it will begin to swap excessively and really slow things down.

As has already been mentioned, having both source and destination unmounted is best.

Computersavvy, I somehow missed your response at the time. However, I am still grateful
for the input - have used the "free" command and all appears OK. My belated thanks.


All times are GMT -5. The time now is 08:51 AM.