Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 12 Jan 2022 12:04:02 +1100
From:      Greg 'groggy' Lehey <grog@FreeBSD.org>
To:        Tomasz CEDRO <tomek@cedro.info>
Cc:        Roderick <hruodr@gmail.com>, FreeBSD Questions List <questions@freebsd.org>
Subject:   Re: dd and mbr
Message-ID:  <20220112010402.GG61872@eureka.lemis.com>
In-Reply-To: <CAM8r67By518wp_1p9%2BJ5p7CE6Zj1M97Rm%2BaA-CSA-qtSVgyidw@mail.gmail.com>
References:  <4af920fc-eff1-a92e-d36e-1ba97079864c@gmail.com> <CAM8r67By518wp_1p9%2BJ5p7CE6Zj1M97Rm%2BaA-CSA-qtSVgyidw@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help

--Sw7tCqrGA+HQ0/zt
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

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.

> Try:
> sysctl kern.geom.debugflags=16
> sysctl kern.geom.part.check_integrity=0

With this information I was able to find comments on the topic at
http://www.lemis.com/grog/diary-apr2009.php?subtitle=&article=D15-11#D15-11
and
http://www.lemis.com/grog/diary-jul2015.php?subtitle=Recovering%20the%20Microsoft%20box&article=D-20150725-014511#D-20150725-014511

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.

Probably you're trying to repartition the disk.  And there are more
modern tools than that:

 # gpart destroy -F da0

This will remove the MBR if there is one, and present you with a disk
that doesn't have any partition structure.

Then you can create your MBR or (preferably) GPT partition table:

 # gpart create -s gpt da0

Then you can add partitions:

 # gpart add -s 64k -t freebsd-boot da0
 # gpart bootcode -b /boot/pmbr -p /boot/gptboot -i 1 da0
 # gpart add -s 10g -t freebsd-ufs da0
 # gpart add -s 10g -t freebsd-swap da0
 # gpart add -t freebsd-ufs da0

The -i 1 for the bootcode is the partition number of the first
partition you added.  The -s 64k and -s 10g are the partition sizes.
The third partition takes up the rest of the disk.  With this method
(clearly flexible) you would have four partitions: boot partition
/dev/da0p1, root partition /dev/da0p2, swap partition /dev/da0p3 and
/usr or /home or whatever at /dev/da0p3.  Note particularly the new
method of putting the boot code in a separate partition

You can still use the old MBR partition scheme, but I would strongly
recommend against it.  You can't use disks bigger than 2 TB.  And the
man page for fdisk(8) starts with the warning:

  This command is obsolete.  Users are advised to use gpart(8) instead.

If you do use it, from memory partition c (used to mean entire disk)
no longer has any meaning.  This is what you refer to in:

> In OpenBSD is simply
>
> dd if=/dev/zero of=/dev/rsd0c

That was a kludge, and we're well rid of it.

I have a page on gpart partitioning at
http://www.lemis.com/grog/HOWTO/gpart.php
mainly for my own use.  You may find something of interest there.

Greg
--
Sent from my desktop computer.
See complete headers for address and phone numbers.
This message is digitally signed.  If your Microsoft mail program
reports problems, please read http://lemis.com/broken-MUA.php

--Sw7tCqrGA+HQ0/zt
Content-Type: application/pgp-signature; name="signature.asc"

-----BEGIN PGP SIGNATURE-----

iEYEARECAAYFAmHeKQIACgkQIubykFB6QiO5WwCggJ8lX1s5opObxa+iP5S38I4G
6TAAnibzOfJ2AYdqelFESe2/7rEvnCUt
=319i
-----END PGP SIGNATURE-----

--Sw7tCqrGA+HQ0/zt--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20220112010402.GG61872>