FreeBSD: How To Add A Second Hard Disk

Posted on in Categories , , , last updated August 27, 2008

Q. How do I add a second hard disk to my FreeBSD server? How do I partition, label and mount a new hard disk under FreeBSD for backup or additional data?

A. There are two ways to install a new hard disk under FreeBSD system. You can use all command line utilities such as fdisk,bsdlabel and newfs to create partitions, label and format it. This method requires complete understanding of BSD partitions and other stuff.

Using sysinstall – Easy way to add a new hard disk

The sysinstall utility is used for installing and configuring FreeBSD systems including hard disks. sysinstall offers options to partition and label a new disk using its easy to use menus. Login as root user. Run sysinstall and enter the Configure menu. Within the FreeBSD Configuration Menu, scroll down and select the Fdisk option:
# sysinstall
Alternatively, use sudo (if configured) to run sysinstall:
$ sudo sysinstall

WARNING! These examples may result into data loss or crash your computer if executed without proper care. This FAQ assumes that you have added a hard disk to the system. Also, replace ad to da (if using SCSI hard disk). Please note that any existing data on 2nd hard disk will get wiped out. Make sure you have backup of all import data and config files.
Fig.01: Scroll down to Configure and press [enter]
Fig.01: Scroll down to Configure and press [enter]
Fig.02: Select Fdisk and press [enter]
Fig.02: Select Fdisk and press [enter]
Fig.03: Select the appropriate drive and press [enter]
Fig.03: Select the appropriate drive and press [enter]

The new drive will probably be the second in the list with a name like ad1 or ad2 and so on. In above example it is ad6.

Using fdisk

Once inside fdisk, pressing A will use the entire disk for FreeBSD. When asked if you want to “remain cooperative with any future possible operating systems”, answer YES. Write the changes to the disk using W. Now exit the FDISK editor by pressing Q. Next you will be asked about the “Master Boot Record”. Since you are adding a disk to an already running system, choose None. The next dialog will say that the operation was successful. Press [enter]. Type Q to quit FDISK.

Using disklable

Next, you need to exit sysinstall and start it again. Restart sysinstall by typing sysinstall:
# sysinstall
Select Configure and press [enter]. Select Label and press [enter]. A dialog asking you to select the drive will appear. Select the appropriate drive and press [enter].

This is where you will create the traditional BSD partitions:

  1. A disk can have up to eight partitions, labeled a-h.
  2. The a partition is used for the root partition (/). Thus only your system disk (e.g, the disk you boot from) should have an a partition.
  3. The b partition is used for swap partitions, and you may have many disks with swap partitions.
  4. The c partition addresses the entire disk in dedicated mode, or the entire FreeBSD slice in slice mode.
  5. The other partitions are for general use.

Now press C to create a partition.

  • Set partition size, to use the whole drive, press [enter].
  • Next, choose fs and press [enter].
  • Type /disk2 as mount point and press [enter] (don’t use the name of a directory that already exists because sysinstall will mount the new partition on top of it)
  • To finalize the changes, press W, select yes and press [enter].

Update /etc/fstab

The last step is to edit /etc/fstab to add an entry for your new disk, enter:
# vi /etc/fstab
Append entry like as follows (make sure you replace parition name with actual values):

/dev/ad6s1d     /disk2       ufs     rw           2       2

Here is my sample /etc/fstab file:

/dev/ad4s1a    520M    393M     85M    82%    /
devfs          1.0k    1.0k      0B   100%    /dev
/dev/ad6s1d    243G     75G    148G    34%    /disk2
/dev/ad4s1d    520M     22M    456M     5%    /tmp
/dev/ad4s1f    230G    4.6G    207G     2%    /usr
/dev/ad4s1e     10G    130M    9.4G     1%    /var
devfs          1.0k    1.0k      0B   100%    /var/named/dev
devfs          1.0k    1.0k      0B   100%    /usr/home/jail/

Save and close the file. The new drive should mount automatically at /disk2 after reboot. To mount it immediately, enter:
# mount -a
# df -H

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

Share this on (or read 15 comments/add one below):

15 comment

  1. Hey thanks for this write up, all went exactly as you have explained. I am left with one question. I would like to be able to access my new drive /disk2 via ftp. I tried to symbolically link a directory I created on new drive to my home folder. Error said too many levels of symbolic links. Should I just change mount mount to a new directory within my home directory. Ex. Home2. Sorry for newb question but thank you for this tutorial.

  2. Thank you!!!! I just started changing my servers to run FreeBSD and tutorials like these are the reason why. This was awesome.

  3. Great info. Now I want to move an existing partition like /usr to the new drive. I could copy everything from the existing /usr to the new partition, then delete it and create a symbolic link to the new location. But is there a better way?

  4. Loved this article, actually used it to for a local computer meeting dealing with this exact issue. Worked out like a charm.

  5. Joe Poniatowsk, To move /usr to another partition.

    First thing to do is put the new disk in the system, once this is completed boot from the installation cd (any of them) use sysinstall to create a directory called /usr0 on that disk. dont use ‘q’ use ‘w’ at every stage, then reboot the system do not install.

    when the system reboots choose to go to single usermode, do the following:

    mount -w /
    mount -r /usr
    mkdir /usr0
    mount -w /dev/ /usr0

    Now you just need to copy your /usr to /usr0 preserving partitions!

    cp -rpP /usr/* /usr0/

    now just alter fstab to use the new drive for /usr (the one that is currently mounted as /usr0) and wallah. reboot

  6. install FBSD 8.2 release, try sysinstall, but something prevent me from formating 2nd harddisk. better address this issue.

  7. Thanks for this.. You are a life saver! FreeBSD has a steep learning curve when most of your experience is with RedHat.

  8. Great article, everything worked completely as described for me, first time. Couldn’t do a write up for this better myself! (thanks!).

  9. Hi, can i check why am i unable to detect my second hard drive when i’ve already added it. I’m using Hyper-V, Added a second SCSI Controller, and added a hard drive, but i can’t seem to detect it.

  10. I am trying to automate setting the geometry and partition of the disk added. Is there a way to do it using XenServer VM? Let me know the details.

Comments are closed.