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:
# 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:
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:
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:
Step 3 – Commit changes
After step #2, you should see something as follows:
You should see progress as follows before returning to the shell prompt:
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
- Share on Twitter • Facebook • 15 comments... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
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.
Thank you!!!! I just started changing my servers to run FreeBSD and tutorials like these are the reason why. This was awesome.
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?
There is no easy solution to your problem. Vinum could have saved your time, if it was implemented in first place.
Loved this article, actually used it to for a local computer meeting dealing with this exact issue. Worked out like a charm.
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
make that ‘cp -RpP /usr/* /usr0/’
Thanks for the great article. Worked fine with FreeBSD 8.0.
You could do:
cp -a /usr/* /usr0/
This would be the same as defining -RpP.
install FBSD 8.2 release, try sysinstall, but something prevent me from formating 2nd harddisk. better address this issue.
Thanks for this.. You are a life saver! FreeBSD has a steep learning curve when most of your experience is with RedHat.
Worked great
Thanks
Great article, everything worked completely as described for me, first time. Couldn’t do a write up for this better myself! (thanks!).
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.
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.