FreeBSD 6.x bsdlabel (disklabel)

To clear invalid or wacky disk labels and devices from /dev (devfs):

freebsd-dhcp# ls /dev/ad1*
/dev/ad1        /dev/ad1s1
freebsd-server# dd if=/dev/zero of=/dev/ad1 bs=512 count=1
1+0 records in
1+0 records out
512 bytes transferred in 0.000551 secs (929244 bytes/sec)
freebsd-server# ls /dev/ad1*
/dev/ad1
freebsd-server#

Then fdisk:

freebsd-server# fdisk -i /dev/ad1
******* Working on device /dev/ad1 *******
parameters extracted from in-core disklabel are:
cylinders=177536 heads=15 sectors/track=63 (945 blks/cyl)

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

Do you want to change our idea of what BIOS thinks ? [n]
fdisk: invalid fdisk partition table found
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 165 (0xa5),(FreeBSD/NetBSD/386BSD)
    start 63, size 167771457 (81919 Meg), flag 80 (active)
        beg: cyl 0/ head 1/ sector 1;
        end: cyl 383/ head 14/ sector 63
Do you want to change it? [n]
The data for partition 2 is:

Do you want to change it? [n]
The data for partition 3 is:

Do you want to change it? [n]
The data for partition 4 is:

Do you want to change it? [n]
Partition 1 is marked active
Do you want to change the active partition? [n]

We haven't changed the partition table yet.  This is your last chance.
parameters extracted from in-core disklabel are:
cylinders=177536 heads=15 sectors/track=63 (945 blks/cyl)

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

Information from DOS bootblock is:
1: sysid 165 (0xa5),(FreeBSD/NetBSD/386BSD)
    start 63, size 167771457 (81919 Meg), flag 80 (active)
        beg: cyl 0/ head 1/ sector 1;
        end: cyl 383/ head 14/ sector 63
2: 
3: 
4: 
Should we write new partition table? [n] y
freebsd-server# ls /dev/ad1*
/dev/ad1        /dev/ad1s1

Create label template (example file below)

freebsd-server# cat disklabel_ad1.txt
# /dev/ad1s1:
8 partitions:
#        size   offset    fstype   [fsize bsize bps/cpg]
  a:     256M        0    4.2BSD     1024  4096    64   # /
  b:     512M        *      swap                        # swap
  c:        *        *    unused        0     0         # "raw" part, don't edit
  d:       2G        *    4.2BSD     1024  4096    64   # /var
  e:     512M        *    4.2BSD     1024  4096    64   # /tmp
  f:        *        *    4.2BSD     1024  4096    64   # /usr
freebsd-server#

Create labels

freebsd-server# bsdlabel -R -B ad1s1 disklabel_ad1.txt
freebsd-server#  ls /dev/ad1*
/dev/ad1        /dev/ad1s1a     /dev/ad1s1c     /dev/ad1s1e
/dev/ad1s1      /dev/ad1s1b     /dev/ad1s1d     /dev/ad1s1f
freebsd-server# bsdlabel ad1s1
# /dev/ad1s1:
8 partitions:
#        size   offset    fstype   [fsize bsize bps/cpg]
  a:   524288        0    4.2BSD     1024  4096    64
  b:  1048576   524288      swap
  c: 167771457        0    unused        0     0         # "raw" part, don't edit
  d:  4194304  1572864    4.2BSD     1024  4096    64
  e:  1048576  5767168    4.2BSD     1024  4096    64
  f: 160955713  6815744    4.2BSD     1024  4096    64
freebsd-server#

Once can then create new filesystems on the bsd partitions if needed:

newfs /dev/ad1s1a
newfs /dev/ad1s1d
newfs /dev/ad1s1e
newfs /dev/ad1s1f

We skip /dev/ad1s1b since it is swap