19.3 Adding Disks

Originally contributed by David O'Brien.

This section describes how to add a new SCSI disk to a machine that currently only has a single drive. First, turn off the computer and install the drive in the computer following the instructions of the computer, controller, and drive manufacturers. Reboot the system and become root.

Inspect /var/run/dmesg.boot to ensure the new disk was found. In this example, the newly added SCSI drive should appear as da1.

FreeBSD runs on IBM-PC compatible computers, therefore it must take into account the PC BIOS partitions which are different from the traditional BSD partitions. A PC disk has up to four BIOS partition entries. If the disk is going to be truly dedicated to FreeBSD, use dedicated mode. Otherwise, FreeBSD will have to live within one of the PC BIOS partitions. FreeBSD calls the PC BIOS partitions slices so as not to confuse them with traditional BSD partitions. Slices may also be used on a disk that is dedicated to FreeBSD, but used in a computer that also has another operating system installed. This is a good way to avoid confusing the fdisk utility of non-FreeBSD operating systems.

In the slice case, the drive will be added as /dev/da1s1e. This is read as: SCSI disk, unit number 1 (second SCSI disk), slice 1 (PC BIOS partition 1), and e BSD partition. In the dedicated case, the drive will be added as /dev/da1e.

Due to the use of 32-bit integers to store the number of sectors, bsdlabel(8) is limited to 2^32-1 sectors per disk, or 2TB in most cases. The fdisk(8) format allows a starting sector of no more than 2^32-1 and a length of no more than 2^32-1, limiting partitions to 2TB and disks to 4TB, in most cases. The sunlabel(8) format is limited to 2^32-1 sectors per partition and 8 partitions for a total of 16TB. For larger disks, gpart(8) may be used to create GPT partitions. GPT has the added benefit of not being limited to 4 slices.

19.3.1 Using sysinstall(8)

  1. Navigating sysinstall

    sysinstall can be used to partition and label a new disk using its easy-to-use menus. As root, run sysinstall and enter the Configure menu. Within the FreeBSD Configuration Menu, scroll down and select the Fdisk option.

  2. fdisk Partition Editor

    Once inside fdisk, pressing A will use the entire disk for FreeBSD. When asked whether to “remain cooperative with any future possible operating systems”, answer YES. Write the changes to the disk using W. Exit the fdisk editor by pressing Q which will prompt about the “Master Boot Record”. Since the disk is being added to an already running system, choose None.

  3. Disk Label Editor

    Next, exit sysinstall and start it again. Follow the directions above, except this time choose the Label option. This will enter the Disk Label Editor. This editor is used to create traditional BSD partitions. A disk can have up to eight partitions, labeled a-h. A few of the partition labels have special uses. The a partition is used for the root partition (/). Only the disk the system boots from should have an a partition. The b partition is used for swap partitions, and there can be many disks with swap partitions. The c partition addresses the entire disk in dedicated mode, or the entire FreeBSD slice in slice mode. The other partitions are for general use.

    The label editor in sysinstall favors the e partition for non-root, non-swap partitions. Within the label editor, create a single file system by pressing C. When prompted if this will be a FS (file system) or swap, choose FS and type in a mount point such as /mnt). When adding a disk in post-install mode, sysinstall will not create entries in /etc/fstab, so the mount point you specify is not important.

    Press W to write the new label to the disk and create a file system on it. Ignore any errors from sysinstall indicating that it could not mount the new partition. Exit the label editor then sysinstall completely.

  4. Finish

    The last step is to edit /etc/fstab to add an entry for your new disk.

19.3.2 Using Command Line Utilities

19.3.2.1 Using Slices

The setup in the following example allows the new disk to work correctly with other operating systems that might be installed on the computer without confusing other operating systems' fdisk utilities. This method is recommended for new disk installs. Only use dedicated mode if there is a good reason to do so!

# dd if=/dev/zero of=/dev/da1 bs=1k count=1
# fdisk -BI da1 #Initialize your new disk
# bsdlabel -B -w da1s1 auto #Label it.
# bsdlabel -e da1s1 # Edit the bsdlabel just created and add any partitions.
# mkdir -p /1
# newfs /dev/da1s1e # Repeat this for every partition you created.
# mount /dev/da1s1e /1 # Mount the partition(s)
# vi /etc/fstab # Add the appropriate entry/entries to your /etc/fstab.

For an IDE disk, substitute ad for da.

19.3.2.2 Dedicated

If the new drive will not be shared with another operating system, dedicated mode can be used. This mode can confuse Microsoft operating systems; however, no damage will be done by them. To configure a disk in dedicated mode:

# dd if=/dev/zero of=/dev/da1 bs=1k count=1
# bsdlabel -Bw da1 auto
# bsdlabel -e da1				# create the `e' partition
# newfs /dev/da1e
# mkdir -p /1
# vi /etc/fstab				# add an entry for /dev/da1e
# mount /1

An alternate method is:

# dd if=/dev/zero of=/dev/da1 count=2
# bsdlabel /dev/da1 | bsdlabel -BR da1 /dev/stdin
# newfs /dev/da1e
# mkdir -p /1
# vi /etc/fstab					# add an entry for /dev/da1e
# mount /1