FreeBSD Find Out All Installed Hard Disk Size Information

How do I find out all installed hard disk drive names under a FreeBSD operating system without rebooting the server? How do I use the equivalent of fdisk -l in Linux, with FreeBSD to list all hard disks drives? How can I find hard disk size in FreeBSD?

The easiest way to find out detected hardware information under FreeBSD is go through /var/run/dmesg.boot file. This file is usually a snapshot of the buffer contents taken soon after file systems are mounted at startup time. It is not modified till system is rebooted. Just like Linux, FreeBSD follows some sort of physical disk naming conventions:
Tutorial details
Difficulty Easy (rss)
Root privileges Yes
Requirements FreeBSD
Time 2m

ADVERTISEMENTS

  1. IDE Hard disk names starts with ad – /dev/ad0 first IDE hard disk, /dev/ad1 second hard disk and so on
  2. SATA/SSD (ATA Direct Access device driver) disk names starts with ad – /dev/ada, /dev/sdb and so on.
  3. SCSI Hard disk names starts with da – /dev/da*
  4. IDE CDROM/RW/DVD names starts with acd – /dev/acd*
  5. SCSI CDROM/RW/DVD names starts with cd – /dev/cd*

List all detected hard disk / cdroms / SSDs in FreeBSD

Type the following grep command, enter:
# egrep 'da[0-9]|cd[0-9]' /var/run/dmesg.boot
OR
# egrep 'ad[0-9]|cd[0-9]' /var/run/dmesg.boot
Sample outputs:

acd0: DVDROM  at ata0-slave UDMA33
ad4: 239372MB  at ata2-master SATA150
ad6: 239372MB  at ata3-master SATA150
Trying to mount root from ufs:/dev/ad4s1a

From above output it is clear that I’ve the following storage installed on my FreeBSD server:

  1. ad4 : My First hard disk connected to ATA channel 2
  2. ad6: My Second hard disk connected to ATA channel 3
  3. acd0 : My DVD ROM

geom utility

Try to show detailed information about disks using geom:
# geom disk list
# geom disk list ada5
# geom disk list ada2

Sample outputs:

Geom name: ada2
Providers:
1. Name: ada2
   Mediasize: 64023257088 (60G)
   Sectorsize: 512
   Stripesize: 4096
   Stripeoffset: 0
   Mode: r0w0e0
   descr: SanDisk SD6SB1M064G1022I
   lunid: 5001b44e71f4a5a6
   ident: 152041400742
   rotationrate: 0
   fwsectors: 63
   fwheads: 16

You can filter out info using the egrep command/grep command:
# geom disk list ada3 | grep Mediasize
Sample outputs

Mediasize: 6001175126016 (5.5T)

atacontrol command (for older version of FreeBSD)

The atacontrol utility is a control program that provides the user access and control to the FreeBSD ata (IDE / SATA hard disk) subsystem.

WARNING! These examples may crash your computer and loss of data if executed improperly. Please exercise caution when using atacontrol command!

The list option can list all hard disk, enter:
# atacontrol list
Output:

ATA channel 0:
    Master:      no device present
    Slave:  acd0  ATA/ATAPI revision 7
ATA channel 1:
    Master:      no device present
    Slave:       no device present
ATA channel 2:
    Master:  ad4  Serial ATA II
    Slave:       no device present
ATA channel 3:
    Master:  ad6  Serial ATA II
    Slave:       no device present

Say hello to camcontrol command

The CAM subsystem provides a uniform and modular system for the implementation of drivers to control various SCSI and ATA devices, and to utilize different SCSI and ATA host adapters through host adapter drivers. Use the camcontrol utility to access the CAM subsystem.

List all physical devices

Type the following command:
# camcontrol devlist
Sample outputs:

Fig.01: FreeBSD device list using CAM

Fig.01: FreeBSD device list using CAM

How do I list current partition information?

Use the following command:
# gpart show
Sample outputs:

=>      34  31277165  ada3  GPT  (14G)
        34      1024     1  bios-boot  (512k)
      1058         6        - free -  (3.0k)
      1064  31275184     2  freebsd-zfs  (14G)
  31276248       951        - free -  (475k)
 
=>         34  11721045101  ada0  GPT  (5.5T)
           34           94        - free -  (47k)
          128      4194304     1  freebsd-swap  (2.0G)
      4194432  11716850696     2  freebsd-zfs  (5.5T)
  11721045128            7        - free -  (3.5k)
 
=>         34  11721045101  ada1  GPT  (5.5T)
           34           94        - free -  (47k)
          128      4194304     1  freebsd-swap  (2.0G)
      4194432  11716850696     2  freebsd-zfs  (5.5T)
  11721045128            7        - free -  (3.5k)
 
=>         34  11721045101  ada5  GPT  (5.5T)
           34           94        - free -  (47k)
          128      4194304     1  freebsd-swap  (2.0G)
      4194432  11716850696     2  freebsd-zfs  (5.5T)
  11721045128            7        - free -  (3.5k)
 
=>         34  11721045101  ada6  GPT  (5.5T)
           34           94        - free -  (47k)
          128      4194304     1  freebsd-swap  (2.0G)
      4194432  11716850696     2  freebsd-zfs  (5.5T)
  11721045128            7        - free -  (3.5k)
 
=>       34  234441581  ada4  GPT  (111G)
         34         94        - free -  (47k)
        128  234441480     1  freebsd-zfs  (111G)
  234441608          7        - free -  (3.5k)
 
=>       34  125045357  ada2  GPT  (59G)
         34         94        - free -  (47k)
        128  125045256     1  freebsd-zfs  (59G)
  125045384          7        - free -  (3.5k)

Using GEOM to probes disks

Type the following command (source):

## this run script using sh ##
 
sh -c '. /usr/share/bsdconfig/device.subr;f_device_menu "" "" "" DISK'

Sample outputs:

Fig.02: GEOM probe for installed disk on FreeBSD

Fig.02: GEOM probe for installed disk on FreeBSD

A shell script to list and detect FreeBSD server disks

Create a shell script named showdisk as follows:

#!/bin/sh
# Name: showdisk
# Author: FrauBSD
#-----------------------------------------
. /usr/share/bsdconfig/device.subr || exit
[ "$( id -u )" -eq 0 ] && WITH_CAMCONTROL=1
while :; do
	info="gpart(8) show %s:\n%s\n\n" disk= gpart= inquiry= identify=
        device=$( msg_cancel=Done f_device_menu "$DIALOG_TITLE" \
		"Select a disk device" "$hline_arrows_tab_enter" \
                $DEVICE_TYPE_DISK 2>&1 ) || break
        $device get name disk
	gpart=$( gpart show $disk 2>&1 )
	if [ "$WITH_CAMCONTROL" ]; then
		inquiry=$( camcontrol inquiry $disk 2>&1 )
		identify=$( camcontrol identify $disk 2>&1 )
	else
		info="${info}WARNING! Must be root to use camcontrol(8)!\n"
	fi
	[ "$inquiry" ] && info="${info}camcontrol(8) inquiry $disk:\n%s\n\n"
	[ "$identify" ] && info="${info}camcontrol(8) identify $disk:\n%s\n"
	f_show_msg "$info" "$disk" "$gpart" \
		${inquiry:+"$inquiry"} ${identify:+"$identify"}
done

Next, execute the shell script in FreeBSD:
chmod +x showdisk
./showdisk

FreeBSD show disk information demo

List all connected SSD and hard drive devices in FreeBSD

FreeBSD print the attached disk size

Run diskinfo command:
diskinfo -v disk_name
diskinfo -v ada4
diskinfo -v ada1

Sample outputs:

ada1
	512         	# sectorsize
	6001175126016	# mediasize in bytes (5.5T)
	11721045168 	# mediasize in sectors
	4096        	# stripesize
	0           	# stripeoffset
	11628021    	# Cylinders according to firmware.
	16          	# Heads according to firmware.
	63          	# Sectors according to firmware.
	HGST HDN726060ALE614	# Disk descr.
	K1JVDUGD    	# Disk ident.
	No          	# TRIM/UNMAP support
	7200        	# Rotation rate in RPM
	Not_Zoned   	# Zone Mode

So my disk size is 6TB. Another outputs from SanDisk SSD installed on FreeBSD 12.x server:
FreeBSD Find Hard Disk Size and Name Information Using Command

lsblk command

Let us install the lsblk command as follows:
sudo pkg install lsblk
Sample outputs:

Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
The following 1 package(s) will be affected (of 0 checked):

New packages to be INSTALLED:
	lsblk: 1.0

Number of packages to be installed: 1

5 KiB to be downloaded.

Proceed with this action? [y/N]: y
[1/1] Fetching lsblk-1.0.txz: 100%    5 KiB   4.9kB/s    00:01    
Checking integrity... done (0 conflicting)
[1/1] Installing lsblk-1.0...
[1/1] Extracting lsblk-1.0: 100%

Run it as follows:
lsblk
## get a list of actual disks ##
sysctl kern.disks
## find info about the ada0 disk ##
lsblk da0

FreeBSD lsblk command outputs

Conclusion

You learned how to find information about the installed hard drive and disk size in FreeBSD using command line options. See camcontrol man page here and gpart man page too.

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig 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 jobs killall kill pidof pstree pwdx time
Searchinggrep 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

ADVERTISEMENTS
7 comments… add one
  • Dmitriy Jul 11, 2009 @ 11:33

    Hi, i am from Russia, thanks.

  • Fabrice A. Marie Jan 28, 2010 @ 14:16

    I found that gpart is more accurate. For example on my machine there
    are other discs which names do not start with ad
    # gpart show
    => 63 156310371 ad2 MBR (75G)
    63 156309489 1 freebsd [active] (75G)
    156309552 882 – free – (441K)

    => 63 488394963 ad4 MBR (233G)
    63 472005702 1 !131 (225G)
    472005765 16386300 2 !130 (7.8G)
    488392065 2961 – free – (1.4M)

    => 63 398292804 twed0 MBR (190G)
    63 163846872 1 !7 (78G)
    163846935 234436545 2 !131 (112G)
    398283480 9387 – free – (4.6M)

    => 0 156309489 ad2s1 BSD (75G)
    0 1048576 1 freebsd-ufs (512M)
    1048576 8315952 2 freebsd-swap (4.0G)
    9364528 6254592 4 freebsd-ufs (3.0G)
    15619120 1048576 5 freebsd-ufs (512M)
    16667696 139641793 6 freebsd-ufs (67G)

  • Rumantic Aug 20, 2010 @ 2:59

    really nice topic.
    and what about RAID info?

  • Olav May 19, 2012 @ 12:05

    With FreeBSD 8 and 9 you can use
    # camcontrol devlist

    • NIckolas Nolan Mar 12, 2014 @ 16:29

      Works on FreeBSD10 as well.

      It was also able to retrieve info for 4tb disks without partition tables.
      gpart show omitted these for some reason; perhaps i’m missing something.

      # camcontrol	devlist
        at scbus1 target 0 lun 0 (ada0,pass0)
        at scbus2 target 0 lun 0 (ada1,pass1)
        at scbus4 target 0 lun 0 (ada2,pass2)
        at scbus5 target 0 lun 0 (ada3,pass3)
      
  • Hongk Sep 4, 2013 @ 6:06

    Hi, can i check why I am unable to detect my second hard drive when i’hve 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.

    • 🐧 Vivek Gite Aug 30, 2017 @ 10:53

      What about? This should work on Linode/DigitialOcean/AWS/Hyper-V,/azure/Google cloud:

      sh -c '. /usr/share/bsdconfig/device.subr;f_device_menu "" "" "" DISK'

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.