pendrive clone impossible ?

Polytropon freebsd at
Sat Nov 30 21:33:31 UTC 2019

On Sat, 30 Nov 2019 22:08:21 +0100, Tomasz CEDRO wrote:
> I have to clone a pendrive, the same one to another almost the same
> (number of sectors differs a bit). The problem is that DD does not
> seem to do the job. It always worked for me.
> Also I am not really able to clone the MBR:
> 1. dd if=/dev/da0 of=/dev/da1 bs=512 count=1 does not copy anything.

What is the error message that dd provides?

> 2. dd if=/dev/zero of=/dev/da1 bs=512 count=1 zeroes the mbr.
> 3. dd if=/dev/random of=/dev/da1 bs=512 count=1 randoms the mbr.
> 4. dd if=/dev/da0 of=da0.mbt bs=512 count1; dd if=da0.mbr bc=512
> count=1 does NOT copy the mbr.

The last command seems to be a bit "damaged", I think it should
read (separated into two commands for better readability):

	dd if=/dev/da0 of=da0.mbr bs=512 count=1
	dd if=da0.mbr of=/dev/da0 bs=512 count=1

Again, what is the error message of the 2nd dd command?

> 5. mdconfig -a -tvnode da0.mbr; dd if=/dev/md0 of=/dev/da1 bc=512
> count=1 does put the data into mbr, but still da1 seems to have no
> partitions!!!

Have you tried copying more than just the first 512 bytes,
let's say, the first whole MB? Of course the rest of the
partitions would be "incomplete" and therefore not readable,
but you should at least get the partition information when
you use gpart or ye olde fdisk to read it.

> While size of the drives differs a bit, the last partition contains
> FreeBSD LiveCD image and is much smaller than the partition so it can
> be truncated with no problem because there are zeros after.

That should be no problem. Partitions can always be smaller

But... you're mentioning a FreeBSD Live CD image. Maybe that
one is dedicated, i. e., doesn't actually have any partitions
with the meaning of "DOS primary partitions" (which is what
gpart or fdisk would list, as mentioned above). However, at
least gpart should show at least _some_ information, or you
use "disklabel /dev/da<number>" and compare source and target
data. In case of a dedicated partitioning (with partition
meaning an _actual_ partition in the context of a BSD label,
"the thing with the letters"), you should at least find one
partition (the "a" partition, bootable).

So it's no entirely clear if you try to deal with a MBR disk,
something dedicated, or GPT? Everything is possible. :-)

> Does GEOM in any way prevents me from using disk that has corrupt MBR?

That is possible. Try "sysctl kern.geom.debugflags=0x16" which
was, at least in the past, often a way to make things work
again. :-)

> Why I cannot write a MBR from a file but I can from a md0?

To dd, a virtual node shouldn't be needed to operate on MBRs.
The if= and of= parameters will (should!) accept plain files
just like real devices.

Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...

More information about the freebsd-questions mailing list