Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to fdisk/disklabel whole disk for FreeBSD from command line?

9 views
Skip to first unread message

Marc Frajola

unread,
Feb 26, 2000, 3:00:00 AM2/26/00
to freebsd...@freebsd.org
Hi...

I have spent a bit of time messing around with the command-line
fdisk and disklabel commands, and have been unable to setup a proper
fdisk and FreeBSD partition label solely from the command line.

When I do 'fdisk -e /dev/rda1' or 'fdisk -u ...', that seems to
write an fdisk label, but I get 'No space left on device' or some such
message when I try to do 'disklabel -r -w da1 auto'.

Basically, I want to be able to automate an install, and can't
figure out how to get a shell script to completely initialize a proper
fdisk label AND FreeBSD disk label + boot blocks.

I know that I can use sysinstall to do this properly, but I really
need to do this from a shell script in an automated fashion. I have
tried using slice partitions with disklabel, and that doesn't work
either.

I have consulted the FreeBSD FAQ, and haven't been able to find the
answer there. I also sent this to freebsd-questions, and didn't get any
reply. Can anybody point me in the right direction?

...Marc...


To Unsubscribe: send mail to majo...@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message

Doug White

unread,
Feb 27, 2000, 3:00:00 AM2/27/00
to Marc Frajola
On Sat, 26 Feb 2000, Marc Frajola wrote:

> Hi...
>
> I have spent a bit of time messing around with the command-line
> fdisk and disklabel commands, and have been unable to setup a proper
> fdisk and FreeBSD partition label solely from the command line.

Somebody didn't check the usual places! :)

http://www.freebsd.org/tutorials/formatting-media/

Also if you are on a recent (3.4?) -STABLE or -CURRENT you have the
dangerous yet handy fdisk -e option.

You will certainly want to steal my code from the 'install' PicoBSD
floppy, which fdisk, disklabels, and newfs's the target disk
automatically.

Doug White | FreeBSD: The Power to Serve
dwh...@resnet.uoregon.edu | www.FreeBSD.org

Greg Lehey

unread,
Feb 28, 2000, 3:00:00 AM2/28/00
to Doug White
On Sunday, 27 February 2000 at 0:59:30 -0800, Doug White wrote:
> On Sat, 26 Feb 2000, Marc Frajola wrote:
>
>> Hi...
>>
>> I have spent a bit of time messing around with the command-line
>> fdisk and disklabel commands, and have been unable to setup a proper
>> fdisk and FreeBSD partition label solely from the command line.
>
> Somebody didn't check the usual places! :)
>
> http://www.freebsd.org/tutorials/formatting-media/
>
> Also if you are on a recent (3.4?) -STABLE or -CURRENT you have the
> dangerous yet handy fdisk -e option.

fdisk -e is doubly dangerous. OpenBSD uses -e to mean "edit the
label". In FreeBSD, it's more like "eradicate the label".

Greg
--
Finger gr...@lemis.com for PGP public key
See complete headers for address and phone numbers

Warner Losh

unread,
Feb 28, 2000, 3:00:00 AM2/28/00
to Greg Lehey
In message <2000022811...@freebie.lemis.com> Greg Lehey writes:
: fdisk -e is doubly dangerous. OpenBSD uses -e to mean "edit the

: label". In FreeBSD, it's more like "eradicate the label".

Personally, I'd like to see it changed from -e to -I. Since it is
only in 4.0, this shouldn't cause too many problems.

Comments?

Warner

Greg Lehey

unread,
Feb 28, 2000, 3:00:00 AM2/28/00
to Warner Losh
[copying -committers]

On Monday, 28 February 2000 at 1:47:36 -0700, Warner Losh wrote:
> In message <2000022811...@freebie.lemis.com> Greg Lehey writes:
> : fdisk -e is doubly dangerous. OpenBSD uses -e to mean "edit the
> : label". In FreeBSD, it's more like "eradicate the label".
>
> Personally, I'd like to see it changed from -e to -I. Since it is
> only in 4.0, this shouldn't cause too many problems.
>
> Comments?

Do other BSDs have something similar? We obviously have an
incompatibility here, and it would be nice to come to an agreement on
a standard syntax. It would also be nice to be able to warn people
before performing such a destructive step, and allow recovery if you
do it before stopping the program.

Greg
--
Finger gr...@lemis.com for PGP public key
See complete headers for address and phone numbers

Warner Losh

unread,
Feb 28, 2000, 3:00:00 AM2/28/00
to Greg Lehey
In message <2000022819...@freebie.lemis.com> Greg Lehey writes:
: Do other BSDs have something similar? We obviously have an

: incompatibility here, and it would be nice to come to an agreement on
: a standard syntax. It would also be nice to be able to warn people
: before performing such a destructive step, and allow recovery if you
: do it before stopping the program.

OpenBSD's fdisk is the the nly one that I've played around with. It
doesn't seem to have a command line option to create an empty disk.

Warner

Marc Frajola

unread,
Feb 29, 2000, 3:00:00 AM2/29/00
to Doug White
> On Sat, 26 Feb 2000, Marc Frajola wrote:
>
> > Hi...
> >
> > I have spent a bit of time messing around with the command-line
> > fdisk and disklabel commands, and have been unable to setup a proper
> > fdisk and FreeBSD partition label solely from the command line.
>
> Somebody didn't check the usual places! :)
>
> http://www.freebsd.org/tutorials/formatting-media/
>
> Also if you are on a recent (3.4?) -STABLE or -CURRENT you have the
> dangerous yet handy fdisk -e option.
>
> You will certainly want to steal my code from the 'install' PicoBSD
> floppy, which fdisk, disklabels, and newfs's the target disk
> automatically.
>
> Doug White | FreeBSD: The Power to Serve
> dwh...@resnet.uoregon.edu | www.FreeBSD.org

Doug,

Thanks very much for the reply. I checked out the URL you gave
(http://www.freebsd.org/tutorials/formatting-media/), and unfortunately
I'm still wondering how to create one FreeBSD fdisk slice so that
disklabel can actually create partitions.

The reason why I sent the message to freebsd-hackers was because
when I tried 'fdisk -e', it seems to assign a slice, BUT disklabel
gives an error like 'No space left on device' or some such thing after
running fdisk, making it obvious that the fdisk -e didn't work as I
thought it should.

I'm guessing I need to include a different combination of fdisk
options or there's a bug.

I will check out the 'install' PicoBSD floppy here shortly to
see if I can learn anything from that.

If anybody knows right off what the sequence of commands (complete
with arguments) to fdisk and disklabel a new drive to make a
"compatiblity mode" bootable FreeBSD system slice (and make it active),
I'd appreciate hearing from you.

...Marc...

Wes Peters

unread,
Feb 29, 2000, 3:00:00 AM2/29/00
to Warner Losh
Warner Losh wrote:
>
> In message <2000022811...@freebie.lemis.com> Greg Lehey writes:
> : fdisk -e is doubly dangerous. OpenBSD uses -e to mean "edit the
> : label". In FreeBSD, it's more like "eradicate the label".
>
> Personally, I'd like to see it changed from -e to -I. Since it is
> only in 4.0, this shouldn't cause too many problems.
>
> Comments?

Take a hint from vinum(8) and make it 'fdisk --no-future'?

Capital letters are certainly further from the norm, and it would no longer
clash with the OpenBSD usage.

--
"Where am I, and what am I doing in this handbasket?"

Wes Peters Softweyr LLC
w...@softweyr.com http://softweyr.com/

Warner Losh

unread,
Feb 29, 2000, 3:00:00 AM2/29/00
to Wes Peters
In message <38BB26E4...@softweyr.com> Wes Peters writes:
: Take a hint from vinum(8) and make it 'fdisk --no-future'?

:-)

: Capital letters are certainly further from the norm, and it would no longer


: clash with the OpenBSD usage.

Well, if there's good code that one could contribute back to the
OpenBSD tree, I'm sure they would accept it. Maybe they'd also
implement -I as well.

Warner

Marc Frajola

unread,
Mar 1, 2000, 3:00:00 AM3/1/00
to Doug White
On Tue, 29 Feb 2000, Doug White wrote:

> On Mon, 28 Feb 2000, Marc Frajola wrote:
>
> > Thanks very much for the reply. I checked out the URL you gave
> > (http://www.freebsd.org/tutorials/formatting-media/), and unfortunately
> > I'm still wondering how to create one FreeBSD fdisk slice so that
> > disklabel can actually create partitions.
> >
> > The reason why I sent the message to freebsd-hackers was because
> > when I tried 'fdisk -e', it seems to assign a slice, BUT disklabel
> > gives an error like 'No space left on device' or some such thing after
> > running fdisk, making it obvious that the fdisk -e didn't work as I
> > thought it should.
>
> What are you using for your command lines? You have to target the
> disklabel specifically at slice 1 on the disk otherwise disklabel will
> think you're trying to overwrite the slice table and get mad.

Here's what I did:

fdisk -e /dev/rda1


disklabel -r -w da1 auto

The disklabel command gives 'disklabel: No space left on device'.

> > I will check out the 'install' PicoBSD floppy here shortly to
> > see if I can learn anything from that.
>

> I just did that twice today and it definitely works :) The only problem I
> had with those is that the disk boot order (this is a L440GX+ board where
> you can configure it) was screwy (i.e. primary-master wasn't the preferred
> boot disk).

> > If anybody knows right off what the sequence of commands (complete
> > with arguments) to fdisk and disklabel a new drive to make a
> > "compatiblity mode" bootable FreeBSD system slice (and make it active),
> > I'd appreciate hearing from you.
>

> I have an awk script mercilessly stolen from phk that does the disklabel
> dirty work. Otherwise it's straightforward:
>
> fdisk -e wd0
> disklabel .. magic ..
> newfs /dev/wd0s1a

OK, may I ask what the ".. magic .." part is??

I am using SCSI drives (hence da). I tried doing 'camcontrol rescan
da1' as suggested by somebody on the mailing list, and that had no
effect on the problem.

When I use 'sysinstall', I can write an fdisk slice label and a
FreeBSD disk label properly, and all is well. I just can't automate it.

I glanced through the source code for disklabel and sysinstall. It
looks like sysinstall uses libdisk to write the label. The command-line
'disklabel' utility appears to use an ioctl to set the disklabel, and
the DIOCSDINFO call returns the error. My theory is that sysinstall
works because it does NOT go through the standard kernel interface (at
least if it does, I can't find the DIOCSDINFO call).

The reason the kernel returns the error appears to be because it
thinks one of the sizes given in the new label exceeds the size of the
fdisk slice.

Even if I try using 'disklabel -e da1' to edit the label, I still
get errors like 'disklabel: ioctl DIOCGDINFO: Invalid argument', so it
may not be something wrong with just the 'auto' mode on disklabel.

Anyway, I'm still very open to hints after spending several hours
trying to figure this out.

I noticed that 'fdisk -e /dev/rda1' seems to get the ending
cylinder number completely wrong, but even if I run fdisk entering what
I think are the proper numbers manually, disklabel still does not seem
to be happy.

As per your suggestion, I tried 'disklabel -r -w da1s1 auto', and
I get the following errors:

disklabel: ioctl DIOCGDINFO: Invalid argument
disklabel: auto: unknown disk type

So I'm doubt that disklabel really wants me to target slice 1
directly.

BTW, I'm using an Intel Xeon motherboard (SC450NX) with an Adaptec
2940U2W controller hooked up to a SCSI-to-SCSI RAID controller, and am
trying to do the fdisk/disklabel on the RAID drive. The BIOS reports
that the drive is slightly larger than what fdisk actually assigns to
the partition (in # of sectors -- I actually expected this slight
difference in size).

I really appreciate all the hints so far even though no solution
yet...

...Marc...

P.S.: If somebody who has PicoBSD source available could send me any
relevant scripts or source excerpts from it that deal with fdisk
or disklabel, it would be greatly appreciated.

Mike Smith

unread,
Mar 1, 2000, 3:00:00 AM3/1/00
to Marc Frajola
> > What are you using for your command lines? You have to target the
> > disklabel specifically at slice 1 on the disk otherwise disklabel will
> > think you're trying to overwrite the slice table and get mad.
>
> Here's what I did:
>
> fdisk -e /dev/rda1
> disklabel -r -w da1 auto
>
> The disklabel command gives 'disklabel: No space left on device'.

This is nonsensical; first you are trying to slice the disk, then you are
trying to initialise it sliceless without first removing the slices.

If you want the disk sliced, use disklabel on rda1sX, where X is the
slice you've created. If you want it unsliced, dd 8k of zeroes over the
beginning of da1 first.

--
\\ Give a man a fish, and you feed him for a day. \\ Mike Smith
\\ Tell him he should learn how to fish himself, \\ msm...@freebsd.org
\\ and he'll hate you for a lifetime. \\ msm...@cdrom.com

Doug White

unread,
Mar 1, 2000, 3:00:00 AM3/1/00
to Marc Frajola
On Mon, 28 Feb 2000, Marc Frajola wrote:

> Thanks very much for the reply. I checked out the URL you gave
> (http://www.freebsd.org/tutorials/formatting-media/), and unfortunately
> I'm still wondering how to create one FreeBSD fdisk slice so that
> disklabel can actually create partitions.
>
> The reason why I sent the message to freebsd-hackers was because
> when I tried 'fdisk -e', it seems to assign a slice, BUT disklabel
> gives an error like 'No space left on device' or some such thing after
> running fdisk, making it obvious that the fdisk -e didn't work as I
> thought it should.

What are you using for your command lines? You have to target the


disklabel specifically at slice 1 on the disk otherwise disklabel will
think you're trying to overwrite the slice table and get mad.

> I will check out the 'install' PicoBSD floppy here shortly to


> see if I can learn anything from that.

I just did that twice today and it definitely works :) The only problem I
had with those is that the disk boot order (this is a L440GX+ board where
you can configure it) was screwy (i.e. primary-master wasn't the preferred
boot disk).

> If anybody knows right off what the sequence of commands (complete
> with arguments) to fdisk and disklabel a new drive to make a
> "compatiblity mode" bootable FreeBSD system slice (and make it active),
> I'd appreciate hearing from you.

I have an awk script mercilessly stolen from phk that does the disklabel
dirty work. Otherwise it's straightforward:

fdisk -e wd0
disklabel .. magic ..
newfs /dev/wd0s1a

Doug White | FreeBSD: The Power to Serve
dwh...@resnet.uoregon.edu | www.FreeBSD.org

To Unsubscribe: send mail to majo...@FreeBSD.org

Greg Lehey

unread,
Mar 2, 2000, 3:00:00 AM3/2/00
to Mike Smith
On Wednesday, 1 March 2000 at 11:11:35 -0800, Mike Smith wrote:
>>> What are you using for your command lines? You have to target the
>>> disklabel specifically at slice 1 on the disk otherwise disklabel will
>>> think you're trying to overwrite the slice table and get mad.
>>
>> Here's what I did:
>>
>> fdisk -e /dev/rda1
>> disklabel -r -w da1 auto
>>
>> The disklabel command gives 'disklabel: No space left on device'.
>
> This is nonsensical; first you are trying to slice the disk, then you are
> trying to initialise it sliceless without first removing the slices.
>
> If you want the disk sliced, use disklabel on rda1sX, where X is the
> slice you've created. If you want it unsliced, dd 8k of zeroes over the
> beginning of da1 first.

You've got to admit that that's a workaround. What we really need is
some kind of "please start again from scratch" option.

Greg
--
Finger gr...@lemis.com for PGP public key
See complete headers for address and phone numbers

Warner Losh

unread,
Mar 4, 2000, 3:00:00 AM3/4/00
to Doug White
In message <Pine.BSF.4.21.000303...@resnet.uoregon.edu> Doug White writes:
: > fdisk -e /dev/rda1

: > disklabel -r -w da1 auto
:
: Yeah, this is wrong. You need to specify a slice.

But you can't specify a slice here. It won't work. If you give it
the whole path, disklabel won't even try. If you day da1s1, it will
complain that it can't fit a disklabel for the entire disk into the
slice smaller than the disk with some cryptic error message or another
:-).

: I generally don't depend on the 'auto' magic -- it breaks for IDE
: disks, and I'm not sure it works for slices either.

It breaks for all disk lables that aren't the entire disk.

: I'm looking at the script and notice that it doesn't select slice
: 1... somehow disklabel DTRT. It works here :-)

Well, you could look at my diskprep script that I just posted a
reference to.
http://people.freebsd.org/~imp/diskprep
(also needs patches to fdisk:
http://people.freebsd.org/~imp/fdisk-patch) I'd like to commit it to
FreeBSD after 4.0 goes out the door. We have many partital solutions
to this problem. It is time to make a simple, standard tool to do
this. No, sysinstall doesn't count here because it isn't simple and
cannot be driven from a script. The fla tool is limited to fla DOC2K
disks. The prepdisk in picobsd has too many things hard coded and
will work only for ide disks.

It is designed to create a sane slice (ala fdisk -I (since -e -> -I
soon)) and put a reasonable disklabel on it. By default it does only
one partition, but can be configured to do more. I wrote it to deal
with creating dozens of compact flash labeling when I'm given a hodge
podge of CF sizes and manufactures to create images for (sometimes 48M
parts are available, other times 45M parts, and each of those sizes
varies +- 300 blocks between vendors).

I have a microbsd-like wrapper that I put around it to actually
populate the disk, but it is no where near ready for prime time. Too
many local tweaks and special knowledge still in the scripts.

Warner

Doug White

unread,
Mar 4, 2000, 3:00:00 AM3/4/00
to Marc Frajola
On Wed, 1 Mar 2000, Marc Frajola wrote:

> > What are you using for your command lines? You have to target the
> > disklabel specifically at slice 1 on the disk otherwise disklabel will
> > think you're trying to overwrite the slice table and get mad.
>
> Here's what I did:
>

> fdisk -e /dev/rda1
> disklabel -r -w da1 auto

Yeah, this is wrong. You need to specify a slice.

I generally don't depend on the 'auto' magic -- it breaks for IDE


disks, and I'm not sure it works for slices either.

> OK, may I ask what the ".. magic .." part is??

Take a look at src/release/picobsd/install/floppy.tree/etc/prepdisk in the
source tree. This is an awk script that generates a root partition and
255MB of swap on the target disk by doing the higher math on the number of
sectors on the disk. You may have to change the disk type in the script
but otherwise it's the same for IDE and SCSI.

I'm looking at the script and notice that it doesn't select slice
1... somehow disklabel DTRT. It works here :-)

Doug White | FreeBSD: The Power to Serve
dwh...@resnet.uoregon.edu | www.FreeBSD.org

PS: http://www.freebsd.org/cgi/cvsweb.cgi is really handy for browsing the
source tree.

0 new messages