FreeBSD Find Out All Installed Hard Disk 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?

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 Linux, FreeBSD follows some sort of physical disk naming conventions:[donotprint][/donotprint]

a] IDE Hard disk names starts with ad – /dev/ad0 first IDE hard disk, /dev/ad1 second hard disk and so on

b] SCSI Hard disk names starts with da – /dev/da*

c] IDE CDROM/RW/DVD names starts with acd – /dev/acd*

d] SCSI CDROM/RW/DVD names starts with cd – /dev/cd*

List all detected hard disk / cdroms

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 outpust:

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

atacontrol command

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

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)

=> 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'

## 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

Posted by: SXI ADMIN

The author is the creator of SXI LLC 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.