FreeBSD: How To Add A Second Hard Disk

by on August 27, 2008 · 14 comments· LAST UPDATED August 27, 2008

in , ,

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/www.example.com/dev

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

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 14 comments… read them below or add one }

1 James November 21, 2008 at 4:19 am

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.

Reply

2 Roland January 6, 2009 at 1:55 am

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

Reply

3 Joe Poniatowski February 3, 2009 at 1:01 pm

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?

Reply

4 nixCraft February 3, 2009 at 1:27 pm

There is no easy solution to your problem. Vinum could have saved your time, if it was implemented in first place.

Reply

5 nexus March 3, 2009 at 3:37 am

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

Reply

6 Paul Webster March 31, 2009 at 12:50 pm

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

Reply

7 Paul Webster March 31, 2009 at 1:09 pm

make that ‘cp -RpP /usr/* /usr0/’

Reply

8 Olli Kaven November 19, 2010 at 12:43 pm

Thanks for the great article. Worked fine with FreeBSD 8.0.

Reply

9 Marius van Witzenburg February 20, 2011 at 7:42 pm

You could do:

cp -a /usr/* /usr0/

This would be the same as defining -RpP.

Reply

10 musang March 12, 2011 at 1:24 am

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

Reply

11 Franklin January 12, 2012 at 7:01 pm

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

Reply

12 sathish February 29, 2012 at 6:13 pm

Worked great

Thanks

Reply

13 James Pearce November 8, 2012 at 7:43 am

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

Reply

14 Hongk September 4, 2013 at 6:05 am

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.

Reply

Leave a Comment

Tagged as: , , , , , , , , , ,

Previous Faq:

Next Faq: