How To Add A Second Hard Disk on FreeBSD

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
# 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
$ sudo sade
Sample outputs:

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:

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:

Fig.03: Adding a new partition

Step 3 – Commit changes

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

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:

Fig.05: Confirm changes to disk

You should see progress as follows before returning to the shell prompt:

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

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 15 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
15 comments… add one
  • James Nov 21, 2008 @ 4:19

    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.

  • Roland Jan 6, 2009 @ 1:55

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

  • Joe Poniatowski Feb 3, 2009 @ 13:01

    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?

  • 🐧 nixCraft Feb 3, 2009 @ 13:27

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

  • nexus Mar 3, 2009 @ 3:37

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

  • Paul Webster Mar 31, 2009 @ 12:50

    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

  • Paul Webster Mar 31, 2009 @ 13:09

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

  • Olli Kaven Nov 19, 2010 @ 12:43

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

  • Marius van Witzenburg Feb 20, 2011 @ 19:42

    You could do:

    cp -a /usr/* /usr0/

    This would be the same as defining -RpP.

  • musang Mar 12, 2011 @ 1:24

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

  • Franklin Jan 12, 2012 @ 19:01

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

  • sathish Feb 29, 2012 @ 18:13

    Worked great


  • James Pearce Nov 8, 2012 @ 7:43

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

  • Hongk Sep 4, 2013 @ 6:05

    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.

  • Ram Shukla May 5, 2015 @ 10:33

    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.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum