Re: dd and mbr

From: Tomasz CEDRO <tomek_at_cedro.info>
Date: Wed, 12 Jan 2022 01:44:23 UTC
On Wed, Jan 12, 2022 at 2:04 AM Greg 'groggy' Lehey wrote:
>
> On Tuesday, 11 January 2022 at 15:04:33 +0100, Tomasz CEDRO wrote:
> > On Tue, Jan 11, 2022 at 11:05 AM Roderick wrote:
> >> The command:
> >> dd if=/dev/zero of=/dev/da0
> >> does not delete the mbr, I still see the partition table with
> >> fdisk. My questions:
>
> I'll address these issues at the bottom of this reply.
>
> >> (1) What does this command do?
> >> (2) How to delete the mbr with dd? How to address the whole disk with dd?
> >> In OpenBSD is simply
> >> dd if=/dev/zero of=/dev/rsd0c
> >> with perhaps a count argument.
> >> Rod.
> >
> > There seems to be a tricky sysctl introduced some time ago that
> > prevents some operations on mbr.. I got into that issuse some time ago
> > but don't remember details sorry..
>
> Thanks.  Yes, this is what I recall too.
> (..)
> The background: FreeBSD has been through many iterations of disk
> labeling.  Once there was a program called disklabel(8) which laid out
> the partition table.  It was a real pain, and since then it has
> morphed into bsdlabel(8), still a pain.  And since then we have GPT
> partition tables, which are the most modern iteration.  But on the way
> there have been many mechanisms to protect the first sector on the
> disk from accidental overwriting, and the current one is to set
> kern.geom.debugflags.  It's not really intended for end users, which
> is no excuse for not being documented more prominently.
>
> > I also do not like that FreeBSD system hides something from me like
> > Linux then requires searching for a magic solution.. I would prefer
> > to stay OpenBSD way you presented :-(
>
> I don't think that any of these are good solutions.
>
> Back to Rod:
>
> Where did you get the dd approach?  As others have said, at the very
> least you should have limited the length, otherwise you would
> overwrite the entire disk, one sector at a time.

Thanks Greg :-) That was exactly my case, "I just wanted to dd one
disk to another byte-to-byte"^TM no partitions play no data play just
raw copy from slower bootable (both mbr+uefi) pendrive to faster
bootable pendrive.. and then surprise surprise it turned out that new
disk did not have the first sector copied.. this is why I do not like
that approach to hide anything in the background or set some defaults
that was not there before.. I asked to dd whole disk but the disk was
not copied byte-to-byte.. I could not even later copy the first 512
bytes until some magic sysctl was changed :-)

-- 
CeDeROM, SQ7MHZ, http://www.tomek.cedro.info