20. Adding a Hard Disk
Introduction to FreeBSD

The hard drive needs to be physically installed. Make sure the cable is on properly, pin 1 is the closest to the power plug.(ie. the red stripe goes toward the power plug). And make sure that there is power to the Drive.

Now reboot to FreeBSD. During Boot up, FreeBSD should detect the drive. If it doesn't, reboot using the "-c" option. At the boot prompt and go in to the visual config and make sure that the appropriate controller is enabled. If you have built a custom kernel and have disabled the extra IDE drive, or are adding a first SCSI drive to a kernel that has SCSI disabled, this is most likely the problem. If the kernel has the controller merely *disabled*, not removed, you can enable it in the visual config. Otherwise you will have to rebuild the kernel adding the appropriate controllers and devices.

If you missed the boot up section, type dmesg at the prompt after you have logged in. This will display your boot-up messages again.

/usr/> dmesg | more

If you are installing SCSI, be sure the drives are found by the SCSI BIOS and that the proper SCSI termination is enabled.

Once everything has been found, you are ready to start the FreeBSD configuration.


The first thing you will need to do is to clear out whatever might have been on the disk previously. Most hard-drive manufacturers ship new drives already partitioned and formatted to the DOS FAT filesystem. For the remainder of this example, we'll be using a hard-drive that was detected as sd1. In our case, it is the second SCSI device on the chain (with SCSI ID 1). Here's how to get rid of that FAT garbage:

dd if=/dev/zero of=/dev/rsd1 count=100

Now you need to prepare a ``disk label'' on the drive. We'll assume in this example that you plan on using the entire drive under FreeBSD:

disklabel -Brw sd1 auto

* substitute rsd1 and sd1 for the disk that you are adding, don't do this to a disk you are using. This basically kills everything on the disk, and prepares it for use by FreeBSD. If this works, you shouldn't need to use fdisk.

If you are planning to use the entire disk as one partition under FreeBSD, then you can use the single default partition just created by disk label, otherwise you will need to use the disklabel editor and create the smaller partitions. You might want to add a swap partition to the disk, for example.

To do get in to the disk label editor for IDE disk 1, type:

disklabel -e wd0

# /dev/rwd0c:
type: ESDI
disk: wd0s1	
bytes/sector: 512
sectors/track: 51
tracks/cylinder: 13
sectors/cylinder: 663
cylinders: 722
sectors/unit: 479298
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]
  a:    65536        0    4.2BSD        0     0     0 	# (Cyl.    0 - 98*)
  b:    85936    65536      swap                    	# (Cyl.   98*- 228*)
  c:   479298        0    unused        0     0       	# (Cyl.    0 - 722*)
  e:    61440   151472    4.2BSD        0     0     0 	# (Cyl.  228*- 321*)
  f:   266386   212912    4.2BSD        0     0     0 	# (Cyl.  321*- 722*)

Now comes the tricky part, getting the numbers right. The easiest way to allocate a partition is to select the number of cylinders you want to allocate to the partition and calculate from there. The size is the size of the partition in sectors. The offset is the last sector of the previous partition. Partition a starts at sector 0. Partitions need to start and end on cylinder boundaries. To find the cylinder boundary, multiply the tracks/cylinder # by the sectors/cylinder # and then multiply that by the number of cylinders you want to allocate. (Sectors * Tracks * Cylinders = Size_of_Partition) To find the offset, add the size of the previous partition to the offset of the previous partition. (Size + Offset = Offset_Of_Next_Partition)

The fstype is the type of filesystem you are putting on that partition. 4.2BSD is the filesystem type for a normal FreeBSD filesystem. swap is the filesystem type for a swap file. FAT is the filsystem type for DOS partitions. Partition a is reserved for the boot sector. Leaving it blank implies that you don't have/need a boot sector.

Partition b is reserved for the swap file. It cannot start with an offset of 0. There must be a partition that starts before it. Partition e can start at offset 0 and be any size, then the swap partition can be placed starting at the offset where partition e ended.

Partition c should not be changed. Start making your filesystems on partition e

Now you need to create a file system on the drive, you use the newfs command to do this. If you are using the whole disk, use the c partition automatically created by disklabel.

newfs /dev/rsd1c

The c partition always represents the entire device - so in this case we've just created a filesystem that spans the entire drive.

If you have separated the disk into smaller parts, you will need to use newfs to create a file system on each partition, except the swap partition.

Finally, you want to mount the drive. We'll assume here that you've created a ``mount point'' of /d2 (using mkdir).

mount /dev/sd1c /d2

If all went well, you should now see something like this:

#vinyl % df -k

Filesystem  1K-blocks     Used    Avail Capacity  Mounted on
/dev/sd0a       31775    13530    15703    46%    /
/dev/sd0s1f   1913091  1086207   673837    62%    /usr
/dev/sd0s1e     29727    12663    14686    46%    /var
procfs              4        4        0   100%    /proc
/dev/sd1c     4108717   616594  3163426    16%    /d2

Now you will need to create an entry in the /etc/fstab file so that it will get mounted each time you reboot. Otherwise you will have to execute the mount each time by hand. A fstab entry will need to be made for each partition you created, including the swap partition.

Also reference the man pages for: fstabmountdisklabeldmesgdd and newfs

Return to Table of Contents

Visit the Gifcom