Create a single UFS partition on entire hard disk without interaction in shell

hi there :D

i want to know how can i partitionate/format and mount a entire
hardisk in a single partition UFS with one script without interaction....

the script receive just the hd name like "/dev/ad4"
then....make the partition with the fullsize with filesystem UFS

somebody can help-me?

im using a freebsd 8


thanks and happy new year!


Luiz
 
if some moderator read this change the title
to:
Create a single partition UFS on entire hard disk without interaction in shell

sorry
 
If you know you'll never be booting from this disk, something brutal like # glabel label [i]label_name[/i] /dev/ad4 && newfs -U /dev/label/[i]label_name[/i] stuffed into a script might work.

Maybe? Be careful out there, especially with scripts.
 
The information you need to do this can be found in the fdisk man page, in the CONFIGURATION FILE section.
To understand this file better you can ask fdisk to create such a file from an existing MBR.
Code:
     -p      Print a slice table in fdisk configuration file format and exit;
             see CONFIGURATION FILE, below

First the MBR in the default displayp
Code:
#  fdisk ad0
******* Working on device /dev/ad0 *******
parameters extracted from in-core disklabel are:
cylinders=4961616 heads=1 sectors/track=63 (63 blks/cyl)

Figures below won't work with BIOS for partitions not in cyl 1
parameters to be used for BIOS calculations are:
cylinders=4961616 heads=1 sectors/track=63 (63 blks/cyl)

Media sector size is 512
Warning: BIOS sector numbering starts with sector 1
Information from DOS bootblock is:
The data for partition 1 is:
sysid 166 (0xa6),(OpenBSD)
    start 63, size 78156162 (38162 Meg), flag 0
        beg: cyl 0/ head 1/ sector 1;
        end: cyl 1023/ head 254/ sector 63
The data for partition 2 is:
sysid 165 (0xa5),(FreeBSD/NetBSD/386BSD)
    start 78156225, size 78140160 (38154 Meg), flag 0
        beg: cyl 1023/ head 255/ sector 63;
        end: cyl 1023/ head 254/ sector 63
The data for partition 3 is:
sysid 165 (0xa5),(FreeBSD/NetBSD/386BSD)
    start 156296385, size 39086145 (19085 Meg), flag 80 (active)
        beg: cyl 1023/ head 255/ sector 63;
        end: cyl 1023/ head 254/ sector 63
The data for partition 4 is:
<UNUSED>
With the -p option the output is:
Code:
# fdisk -p ad0
# /dev/ad0
g c4961616 h1 s63
p 1 0xa6 63 78156162
p 2 0xa5 78156225 78140160
p 3 0xa5 156296385 39086145
a 3
The g describes the geometry of
4961616 cylinders, 1 head and 63 sectors. Actually FreeBSD sees this differently then OpenBSD, but anyway ;)

The first p line says the first slice has an ID of A6, which is OpenBSD, defines the slice to start at sector 63 with a size of 78156162 sectors.

Slice 2 with id A5 starts at 78156225 and it's size is 78140160.
Something similar for the 3rd slice.

The last line a 3 means that the 3rd slice is active, or in other words that this slice should be used when the computer is booted.

Although this configuration file has been derived from an existing MBR it could be used to configure another hard disk.

Redirect the output to file first:
Code:
# fdisk -p ad0 >fdisk-mbr.conf
After editing you could initialize a second disk in the system with:
Code:
# fdisk -f fdisk-mbr.conf -iv ad2
Actually it is better to use the -t option to preview or test what the result would be
Code:
# fdisk -f fdisk-mbr.conf -ivt ad2

******* Working on device /dev/ad2 *******
fdisk: WARNING line 2: number of cylinders (4961616) may be out-of-range
    (must be within 1-1024 for normal BIOS operation, unless the entire disk
    is dedicated to FreeBSD)
parameters extracted from in-core disklabel are:
cylinders=4961616 heads=1 sectors/track=63 (63 blks/cyl)

Figures below won't work with BIOS for partitions not in cyl 1
parameters to be used for BIOS calculations are:
cylinders=4961616 heads=1 sectors/track=63 (63 blks/cyl)

Information from DOS bootblock is:
1: sysid 166 (0xa6),(OpenBSD)
    start 63, size 78156162 (38162 Meg), flag 0
        beg: cyl 1/ head 0/ sector 1;
        end: cyl 510/ head 0/ sector 63
2: sysid 165 (0xa5),(FreeBSD/NetBSD/386BSD)
    start 78156225, size 78140160 (38154 Meg), flag 0
        beg: cyl 511/ head 0/ sector 1;
        end: cyl 766/ head 0/ sector 63
3: sysid 165 (0xa5),(FreeBSD/NetBSD/386BSD)
    start 156296385, size 39086145 (19085 Meg), flag 80 (active)
        beg: cyl 767/ head 0/ sector 1;
        end: cyl 637/ head 0/ sector 63
4: <UNUSED>
In my next post I will give you an example to rewrite this disk to 1 big MBR partition.

Because FreeBSD has a long tradition of interpreting disk geometry wrongly,I first have to reboot this machine in OpenBSD to check the correct geometry.

<rant>
I really don't understand why a small BSD project like OpenBSD has no problems with disk geometry, while giant FreeBSD still hasn't figured out to correctly deal with disk geometry. For a FreeBSD install, I always have to rely on an OpenBSD install disk.
</rant> ;)
 
First of all there is an easier way, by using the "-i" flag
Code:
# # fdisk -It ad0
******* Working on device /dev/ad0 *******
parameters extracted from in-core disklabel are:
cylinders=4961616 heads=1 sectors/track=63 (63 blks/cyl)

Figures below won't work with BIOS for partitions not in cyl 1
parameters to be used for BIOS calculations are:
cylinders=4961616 heads=1 sectors/track=63 (63 blks/cyl)

Information from DOS bootblock is:
1: sysid 165 (0xa5),(FreeBSD/NetBSD/386BSD)
    start 63, size 312581745 (152627 Meg), flag 80 (active)
        beg: cyl 1/ head 0/ sector 1;
        end: cyl 335/ head 0/ sector 63
2: <UNUSED>
3: <UNUSED>
4: <UNUSED>
Remember that I used -t in order not to mess up the current MBR ;)

Another way is to use a configuration file like this
Code:
 # /dev/ad0
g c19457 h255 s63
p 1 0xa5 63 312581808 
p 2 0 1 1
p 3 0 1 1
p 4 0 1 1
a 1
The first p line creates the slice. The other lines delete the existing other slices (actually not needed if you use the "-i option).

The info for the g geometry specification I got from the OpenBSD fdisk output:
Code:
# fdisk wd0
Disk: wd0       [color=blue]geometry: 19457/255/63[/color] [312581808 Sectors]
Offset: 0       Signature: 0xAA55
            Starting         Ending         LBA Info:
 #: id      C   H   S -      C   H   S [       start:        size ]
-------------------------------------------------------------------------------
*0: A6      0   1   1 -   4864 254  63 [          63:    78156162 ] OpenBSD
 1: A5   4865   0   1 -   9728 254  63 [    78156225:    78140160 ] FreeBSD
 2: A5   9729   0   1 -  12161 254  63 [   156296385:    39086145 ] FreeBSD
 3: 00      0   0   0 -      0   0   0 [           0:           0 ] unused

A test run with the "-t" flag
Code:
 fdisk -f mbr-new -itv ad0
******* Working on device /dev/ad0 *******
fdisk: WARNING line 2: number of cylinders (19457) may be out-of-range
    (must be within 1-1024 for normal BIOS operation, unless the entire disk
    is dedicated to FreeBSD)
fdisk: WARNING: adjusting size of partition 1 from 312581808 to 312576642
    to end on a cylinder boundary
parameters extracted from in-core disklabel are:
cylinders=4961616 heads=1 sectors/track=63 (63 blks/cyl)

Figures below won't work with BIOS for partitions not in cyl 1
parameters to be used for BIOS calculations are:
cylinders=19457 heads=255 sectors/track=63 (16065 blks/cyl)

Information from DOS bootblock is:
1: sysid 165 (0xa5),(FreeBSD/NetBSD/386BSD)
    start 63, size 312576642 (152625 Meg), flag 80 (active)
        beg: cyl 0/ head 1/ sector 1;
        end: cyl 0/ head 254/ sector 63
2: <UNUSED>
3: <UNUSED>
4: <UNUSED>
As you can fdisk did not use the 312581808 figure, but rounded it down to 312576642.

The disklabel program also allows to use a similar configuration file to label the slice.

BTW with creating the slice/partition table you are not done yet. If you want this disk to boot, you have to write the boot code to the MBR. The fdisk man page has all the details
 
J65nko said:
<rant>
I really don't understand why a small BSD project like OpenBSD has no problems with disk geometry, while giant FreeBSD still hasn't figured out to correctly deal with disk geometry. For a FreeBSD install, I always have to rely on an OpenBSD install disk.
</rant> ;)
To what exactly are you referring? FreeBSD doesn't have any geometry problems that I've run into excepting for a bit of rounding when using the older style of partitioning. GPT when it's added to sysinstall doesn't have that problem.
 
You do not have to partition the disk for single filesystem. I'm using the whole disk as a raw device, filesystem is created without partition table.

From dictionary:
Partition - a division into or distribution in portions or shares.

:p
 
LuizBiazus said:
i want to know how can i partitionate/format and mount a entire
hardisk in a single partition UFS with one script without interaction....
Look fdisk with keys -B and -I
And bsdlabel with keys -B -w
 
im new in this new bsd magnifc world
but i think that freebsd in this point is pre-historic

now i comprehend that i must to make a label and after format by the label name and not by the device like on linux systems

i think that it should follow the linux patterns

if /dev/sda is the device all the partitions are: /dev/sdaX :)
following...



Hey fronclynne it works sweet like suggar!!!
Code:
#I holp it help someone :P
dd if=/dev/zero of=/dev/ad4  bs=512  count=1 #Clear partition table...etc...
glabel label -v hd2 /dev/ad4  #to creates a label called "Hd2"
mkdir /hd2 # to creates a mount point
mount /dev/label/hd2 /hd2 #mounting

I supose that is what they call "dedicaded" right?!

about a fdisk way

at first thanks J65nko for your gr8 explanation
but take a look:


Code:
(root@thunder)~# dd if=/dev/zero of=/dev/ad4  bs=512  count=1
1+0 records in
1+0 records out
512 bytes transferred in 0.000524 secs (977017 bytes/sec)
(root@thunder)~# fdisk -It ad4
******* Working on device /dev/ad4 *******
fdisk: invalid fdisk partition table found
parameters extracted from in-core disklabel are:
cylinders=4161 heads=16 sectors/track=63 (1008 blks/cyl)

Figures below won't work with BIOS for partitions not in cyl 1
parameters to be used for BIOS calculations are:
cylinders=4161 heads=16 sectors/track=63 (1008 blks/cyl)

Information from DOS bootblock is:
1: sysid 165 (0xa5),(FreeBSD/NetBSD/386BSD)
    start 63, size 4194225 (2047 Meg), flag 80 (active)
        beg: cyl 0/ head 1/ sector 1;
        end: cyl 64/ head 15/ sector 63
2: <UNUSED>
3: <UNUSED>
4: <UNUSED>
(root@thunder)~# fdisk -p ad4
fdisk: invalid fdisk partition table found
fdisk: read_s0: No such file or directory

dont works :-(




hey speedy

yes i dont need partitons i just need to use a entire hardisk with UFS
i read some time ago that raw disks have more I/O performance
is it true?
other question is... it dont crashes when have no more space on device?

can u show for us and for the peaple who will visit this post how u do to use ur entire disk in raw with single FS?!





Thanks for all replies brothers.... its hard to see forum´s like this those days! ;-)
 
those lines :
Code:
(root@thunder)~# fdisk -p ad4
fdisk: invalid fdisk partition table found
fdisk: read_s0: No such file or directory
are placed by mistake ... i was using -t so it doesnt apply :p
effects of first day year :p


well :
Code:
 fdisk -I ad4
******* Working on device /dev/ad4 *******
fdisk: Class not found
are more illustrative..
 
LuizBiazus said:
at first thanks J65nko for your gr8 explanation, but take a look:

Code:
(root@thunder)~# dd if=/dev/zero of=/dev/ad4  bs=512  count=1
1+0 records in
1+0 records out
512 bytes transferred in 0.000524 secs (977017 bytes/sec)
(root@thunder)~# fdisk -It ad4
******* Working on device /dev/ad4 *******
fdisk: invalid fdisk partition table found
parameters extracted from in-core disklabel are:
cylinders=4161 heads=16 sectors/track=63 (1008 blks/cyl)

Figures below won't work with BIOS for partitions not in cyl 1
parameters to be used for BIOS calculations are:
cylinders=4161 heads=16 sectors/track=63 (1008 blks/cyl)

Information from DOS bootblock is:
1: sysid 165 (0xa5),(FreeBSD/NetBSD/386BSD)
    start 63, size 4194225 (2047 Meg), flag 80 (active)
        beg: cyl 0/ head 1/ sector 1;
        end: cyl 64/ head 15/ sector 63
2: <UNUSED>
3: <UNUSED>
4: <UNUSED>
(root@thunder)~# fdisk -p ad4
fdisk: invalid fdisk partition table found
fdisk: read_s0: No such file or directory

Of course this doesn't work, you forgot to omit the the -t option. From the fdisk man page
Code:
 -t      Test mode; do not write slice values.  Generally used with the -f
	     option to see what would be written to the slice table.  Implies
	     -v.
I used -t for testing, because I didn't want to lose my OpenBSD and 2 FBSD installs. On your empty disk, you can without problems omit that "-t".
So if you really want to update the MBR, you should use
Code:
# fdisk -I ad4
 
yes i dont need partitons i just need to use a entire hardisk with UFS
i read some time ago that raw disks have more I/O performance
is it true?
I doubt it's true.
other question is... it dont crashes when have no more space on device?
Such a things are handled by filesystem, not device.
can u show for us and for the peaple who will visit this post how u do to use ur entire disk in raw with single FS?!
Nothing is simpler, just create the filesystem on /dev/da0 instead of da0s1a. Mount /dev/da0 afterward. Pretty much as you do with floppy.
 
LuizBiazus said:
yes i dont need partitons i just need to use a entire hardisk with UFS
i read some time ago that raw disks have more I/O performance
is it true?

This can be true when using ZFS, since ZFS is capable of optimising at that level; it is probably not true for many or any other filesystems (& certainly not for UFS/FFS).
 
J65nko said:
Of course this doesn't work, you forfot to omit the the -t option. From the fdisk man page
Code:
 -t      Test mode; do not write slice values.  Generally used with the -f
	     option to see what would be written to the slice table.  Implies
	     -v.
I used -t for testing, because I didn't want to lose my OpenBSD and 2 FBSD installs. On your empty disk, you can without problems omit that "-t".
So if you really want to update the MBR, you should use
Code:
# fdisk -I ad4

i did it... i tried with the test and it fails
after a tried with full command (how u can see on my last post):

LuizBiazus those lines :

(root@thunder)~# fdisk -p ad4
fdisk: invalid fdisk partition table found
fdisk: read_s0: No such file or directory

are placed by mistake ... i was using -t so it doesnt apply
effects of first day year


well :

fdisk -I ad4
******* Working on device /dev/ad4 *******
fdisk: Class not foundare more illustrative..

thanks

Luiz
 
Speedy said:
I doubt it's true.
Such a things are handled by filesystem, not device.
Nothing is simpler, just create the filesystem on /dev/da0 instead of da0s1a. Mount /dev/da0 afterward. Pretty much as you do with floppy.

copy! thanks :)
 
fronclynne said:
This can be true when using ZFS, since ZFS is capable of optimising at that level; it is probably not true for many or any other filesystems (& certainly not for UFS/FFS).

hummm... i dont now if is a good thing trade zfs to ufs2 hehe

well ... i will use the way u teach-me :)
thank u very much ;)
 
i saw that i jump one step of the solution ... how i cant edit there i go again:

Code:
dd if=/dev/zero of=/dev/ad4  bs=512  count=1 #Clear partition table...etc...
glabel label -v hd2 /dev/ad4  #to creates a label called "hd2"
[b]newfs -U /dev/label/hd2[/b]
mkdir /hd2 # to creates a mount point
mount /dev/label/hd2 /hd2 #mounting
 
Back
Top