How To Add A Second Hard Disk on FreeBSD

last updated in Categories , , ,

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 operating system for backup or to store additional data?

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

FreeBSD add new disk using bsdinstall/sade (method # 1)

The bsdinstall utility is used for installing and configuring FreeBSD systems including hard disks. bsdinstall offers options to partition and label a new disk using its easy to use menus. Login as root user. Run bsdinstall and enter the Configure menu:

WARNING! These examples may result in 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) as per your setup. Please note that any existing data on the 2nd hard drive will get wiped out. Make sure you have a backup of all critical data and config files.

# bsdinstall partedit
OR
# sade
The sade utility is used for various disk administration tasks on FreeBSD systems. The goal is to provide the same text interface for disk management in bsdinstall in the post-installation environment. Alternatively, use sudo command (if configured) to run bsdinstall or sade command:
$ sudo bsdinstall partedit
OR
$ sudo sade
Sample outputs:

FreeBSD add a new disk using sade or bsdinstall command
Fig.01: bsdinstall/sade in action

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 da0. Use [Tab] key, [Up]/[Down]/[Left]/[Right] arrow keys to move. Press [Enter] to select desired option. The procedure to add a new hard disk on FreeBSD is as follows:

Step 1 – Add a new partition scheme

Make sure da0 selected. Select Create button and press [Enter] key. You must select a partition scheme for da0. I am going to select GPT and Select Ok:

FreeBSD select a partition scheme for da0
Fig.02: Setting up a partition scheme to GPT

Step 2 – Add a new partition

The GPT partition table has been successfully created. To create partition, select da0, and press Create button again. Make sure you type Mountpoint and label too and finally select Ok button:

FreeBSD add a new partition with partition editor
Fig.03: Adding a new partition

Step 3 – Commit changes

After step #2, you should see something as follows:

FreeBSD finish sade
Fig.04: My partition are ready for formatting

Select the Finish button to bring confirmation dialog box on screen. Select the Commit button to confirm changes:
FreeBSD confirmation box
Fig.05: Confirm changes to disk

You should see progress as follows before returning to the shell prompt:
FreeBSD initializing disk and writing partition tables for da0p1
Fig.06: sade initializing my disk

Step 4 – Mount disk

The sade command will also update your /etc/fstab file as follows:
# cat /etc/fstab
Sample outputs:

# Device	Mountpoint	FStype	Options	Dump	Pass#
/dev/vtbd0p2	/		ufs	rw	1	1
/dev/vtbd0p3	none		swap	sw	0	0
/dev/da0p1	/data/		ufs	rw	2	2

Use mkdir command to create /data/ directory:
# mkdir /data/
Mount it by typing the following mount command:
# mount -a
Verify it with df command:
# df
Sample outputs:

Filesystem   1K-blocks    Used    Avail Capacity  Mounted on
/dev/vtbd0p2  77175164 2944484 68056668     4%    /
devfs                1       1        0   100%    /dev
/dev/da0p1     5061584   32836  4623824     1%    /data

Adding disk using the FreeBSD cli (method # 2)

Use the following command to find out your the new disk name:
$ dmesg | grep -i disk
OR use grep command:
$ grep -i disk /var/run/dmesg.boot
See “How to Find Out All Installed Hard Disk Information on FreeBSD” for more info.
Create a new partitioning scheme on a da0. The -s GPT option determines the scheme to use:
# gpart create -s GPT da0
da0 created

Verify it:
# gpart show da0
Sample outputs:

=>      40  10485680  da0  GPT  (5.0G)
        40  10485680       - free -  (5.0G)

Make sure the partition is aligned to one megabyte boundaries for performance reasons and add a new partition:
# gpart add -t freebsd-ufs -a 1M da0
da0p1 added

Verify it:
# gpart show da0
Sample outputs:

=>      40  10485680  da0  GPT  (5.0G)
        40      2008       - free -  (1.0M)
      2048  10481664    1  freebsd-ufs  (5.0G)
  10483712      2008       - free -  (1.0M)

Format /dev/da0p1 partition by typing the following command:k:
# newfs -U /dev/da0p1
Sample outputs:

/dev/da0p1: 5118.0MB (10481664 sectors) block size 32768, fragment size 4096
	using 9 cylinder groups of 626.09MB, 20035 blks, 80256 inodes.
	with soft updates
super-block backups (for fsck_ffs -b #) at:
 192, 1282432, 2564672, 3846912, 5129152, 6411392, 7693632, 8975872, 10258112

Finally create a new directory to mount file system:
# mkdir /data/
# mount /dev/da0p1 /data/
# df

Update the /etc/fstab:
# vi /etc/fstab
Append the following line:

/dev/da0p1	/data/		ufs	rw	2	2

Save and close the file. For info see the following man pages:
$ man newfs
$ man gpart
$ man sade

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

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. There is no easy solution to your problem. Vinum could have saved your time, if it was implemented in first place.

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

  6. 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

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

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

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

  10. 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.

  11. 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.

    Have a question? Post it on our forum!