FreeBSD Find Out All Installed Hard Disk Size Information

fdisk -l

Tutorial details Difficulty Easy (rss) Root privileges Yes Requirements FreeBSD Time 2m

ADVERTISEMENTS



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

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 ofin 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 throughfile. 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:

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.

WARNING! These examples may crash your computer and loss of data if executed improperly. Please exercise caution when using atacontrol command! 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:



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:



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:

%s



" 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)!

" fi [ " $inquiry " ] && info = " ${info} camcontrol(8) inquiry $disk :

%s



" [ " $identify " ] && info = " ${info} camcontrol(8) identify $disk :

%s

" f_show_msg " $info " " $disk " " $gpart " \ ${inquiry:+"$inquiry"} ${identify:+"$identify"} done #!/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:

%s



" 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)!

" fi [ "$inquiry" ] && info="${info}camcontrol(8) inquiry $disk:

%s



" [ "$identify" ] && info="${info}camcontrol(8) identify $disk:

%s

" f_show_msg "$info" "$disk" "$gpart" \ ${inquiry:+"$inquiry"} ${identify:+"$identify"} done

Next, execute the shell script in FreeBSD:

chmod +x showdisk

./showdisk



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.