Frequently Asked Questions for FreeBSD 2.X : Installation : How can I add my new hard disk to my FreeBSD system?
Previous: I can't get past the boot manager's `F?' prompt.
Next: I have bad blocks on my hard drive!

2.17. How can I add my new hard disk to my FreeBSD system?

The easiest way to do this is from the installation program. You can start the installation program by running /stand/sysinstall as root.

Alternatively, if you still have the install floppy, you can just reboot from that and use the partition & label editors while the system is totally quiescent.

If the above does not work for you, or if you're a total masochist who likes arcane interfaces, this is how to use disklabel(8) manually:

WARNING: There is no substitute for reading carefully & understanding what you are doing! Things described here may DESTROY your system. Proceed with caution! Remember, a BACKUP is your friend!

sysinstall used to be broken up to 2.1.5-RELEASE and will insist on mounting something at / in the disklabel editor. You will have to manually run disklabel(8) before you can run newfs(8). This means doing the math for partitions yourself. This is rumoured to be easy :-) See if you can obtain a skeletal label with ''disklabel -r <diskname>'' (eg. ''disklabel -r /dev/rwd0s2'', assuming that your new disk is wd0, the first IDE drive, and the FreeBSD slice is the second one, s2). You should see something like:-

# /dev/rwd0s2:
type: ESDI
disk: wd0s2
label: 
flags:
bytes/sector: 512
sectors/track: 63
tracks/cylinder: 64
sectors/cylinder: 4032
cylinders: 610
sectors/unit: 2459520
rpm: 3600
interleave: 1
trackskew: 0
cylinderskew: 0
headswitch: 0           # milliseconds
track-to-track seek: 0  # milliseconds
drivedata: 0 

8 partitions:
#        size   offset    fstype   [fsize bsize bps/cpg]
  c:  2459520        0    unused        0     0         # (Cyl.    0 - 609)
  e:  2459520        0    4.2BSD        0     0     0   # (Cyl.    0 - 609)

Make sure that the size is correct, in this case, 2459520 sectors/unit x 512 bytes/sector / 2**20 (1 Megabyte) = 1200 Megabytes. The rest of the stuff (b/s, t/c, s/c, interleave, etc.) should get suitable defaults from disklabel, but see this note for older disks. 'fsize' is the Fragment size for the filesystem, and 'bsize' is the Block size. 'c' is the partition covering the entire slice (or entire disk for a non-sliced disk), and must remain as it is. It should not be used for a filesystem. The 'c' partition is magic in that it is faked by the kernel even if no disklabel exists.

In the trivial case, where you want a single filesystem spanning the whole slice, the entry for 'e' has to be corrected. Setting fsize to 1024 and bsize to 8192 (8 fragments/block), which are reasonable values for a filesystem, the correct entry for 'e' would be:-

  e:  2459520        0    4.2BSD     1024  8192

Now, the (slightly) harder case, where we want 2 partitions for 2 filesystems. Following the BSD naming conventions, the partitions will be wd0s2e & wd0s2f. Suppose we split up the 1200 MB into 300 MB for 'e' and the remaining 900 MB for 'f'. The partition entries would be:-

8 partitions:
#        size   offset    fstype   [fsize bsize bps/cpg]
  c:  2459520        0    unused        0     0         # (Cyl.    0 - 609)
  e:   614400        0    4.2BSD     1024  8192
  f:  1843200   614400    4.2BSD     1024  8192

Note: You can directly edit the disklabel with ''disklabel -e wd0s2''. See disklabel(8).

If you have at least FreeBSD 2.1.5, and you want to dedicate an entire disk to FreeBSD without any care for other systems, you might shorten the steps above to something like:

# dd if=/dev/zero of=/dev/rwd0 count=100
# disklabel -Brw wd0 auto
# disklabel -e wd0

The first dd command ensures there is no old junk at the beginning of the disk that might confuse the disk code in the kernel. Following is an automatic skeleton label generation using the defaults that have been probed from the disk at boot time. Editing this label continues as described above.

You're done! Time to initialise the filesystems with something like:-

            newfs -d0 /dev/rwd0s2e
            newfs -d0 /dev/rwd0s2f
        

Depending on the disk name and slice number, it might be required that you run the script /dev/MAKEDEV before in order to create the desired device nodes.

And mount your new filesystems (See mount(8)):-

            mount /dev/wd0s2e /mnt/foo
            mount /dev/wd0s2f /mnt/bar
        

You may wish to edit /etc/fstab to automatically mount the filesystems at boot time.

Glossary:

Fragment Size (fsize)

The basic unit of storage for ffs. See M. McKusick, W. Joy, S. Leffler, and R. Fabry, "A Fast File System for UNIX", ACM Transactions on Computer Systems 2, 3, pp 181-197, August 1984, (reprinted in the BSD System Manager's Manual, SMM:5) or /usr/share/doc/smm/05.fastfs/paper.ascii.gz on your system.

Block Size (bsize)

A block comprises one or more fragments. See the reference above and <sys/disklabel.h>

Disklabel Characteristics for Older Disks (ESDI)

You may need to provide more information to disklabel if you happen to own a ``true disk'', i.e. one with a uniform geometry, real heads, sectors, and cylinders, such as an old ESDI drive. All of this should be easily obtainable from the drive case, owner's manual, fellow sufferers, etc. :-)

BSD Filesystem Naming Conventions

Partition 'a' is by convention reserved for a bootable partition, and partition 'b' for swap space. Regular partition names should start with 'd'. ('d' used to be magic in 386BSD 0.1 through FreeBSD 2.0, thus partition 'e' is often used for the first non-bootable partition containing a filesystem.)

Warning about swap space

The space required by the BSD partition table is allowed for in the file system. It's not allowed for by the swap partition. So don't start swap at cylinder 0, either offset it or put a file system in partition 'a'.


Frequently Asked Questions for FreeBSD 2.X : Installation : How can I add my new hard disk to my FreeBSD system?
Previous: I can't get past the boot manager's `F?' prompt.
Next: I have bad blocks on my hard drive!