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 |
- IDE Hard disk names starts with ad – /dev/ad0 first IDE hard disk, /dev/ad1 second hard disk and so on
- SATA/SSD (ATA Direct Access device driver) disk names starts with ad – /dev/ada, /dev/sdb and so on.
- SCSI Hard disk names starts with da – /dev/da*
- IDE CDROM/RW/DVD names starts with acd – /dev/acd*
- 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:
- ad4 : My First hard disk connected to ATA channel 2
- ad6: My Second hard disk connected to ATA channel 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.
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:
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:
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
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:
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
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 Linux, Open Source & DevOps via:
- RSS feed or Weekly email newsletter
- Share on Twitter • Facebook • 8 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 |
Hi, i am from Russia, thanks.
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)
really nice topic.
and what about RAID info?
With FreeBSD 8 and 9 you can use
# camcontrol devlist
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.
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.
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'
With CentOS 8 going out of business in 2021, I installed FreeBSD 12.2 and I was looking to see how we can dig information about installed disks. This saves so much time.