FreeBSD

FreeBSD List Disks

Welcome to another tutorial on FreeBSD. In this tutorial, you’ll see how disk drive names in a FreeBSD system can be listed. We’ll also get into the nitty-gritty and discuss how to find out exactly how much space a disk drive has and how other information relating to disk drives is acquired, all without rebooting the server every time that information is needed.

How to get disk drive information in FreeBSD

To acquire the information related to disk drives and cd ROMs, etc., the most straightforward path we can take is to head over to /var/run/dmesg.boot file and accessing the file. This is where the required information is kept in a snapshot, taken right after the system mounts the disk drives.

Listing disk drives with egrep

To find out the exact number of hdds/ssds are working under the server, use the grep command as under:

$ egrep 'da[0-9]|cd[0-9]' /var/run/dmesg.boot

Alternatively, you may put:

$ egrep 'ad[0-9]|cd[0-9]' /var/run/dmesg.boot

The output you’ll get should list all of the disk drives, including cd/DVD ROMs being read by your system.

Using geom utility to list disk-drive information:

You can use the geom command line to show disk drive information as well:

$ geom disk list

$ geom disk list ada0

This listing can be made more specific when combined with the grep command.

$ geom disk list ada0 | grep Mediasize

Using atacontrol command to list disk drives

Using the atacontrol command-line utility, we can list the disk drives working within our system. The atacontrol command is used to gain permission to work with the FreeBSD ata subsystems and should be used with caution. If executed improperly, it can cause the CPU to crash, leading to some unrecoverable data loss.

$ atacontrol list

Disk drive information with camcontrol command

You can also use the camcontrol command to access the CAM subsystem and see the working drives on your system. This is made possible by the CAM subsystem, a modular system that drivers for ATA and SCSI devices use to implement. The CAM system also accommodates host adapter drivers for the SCSI and ATA host controllers.

To present a list of disk-drives on your system, type in:

$ camcontrol devlist

To see details on each partition:

$ gpart show

Find out the disk sizes with the diskinfo command

Use the diskinfo command to acquire information on the disk sizes

$ diskinfo -v disk_name
$ diskinfo -v ada1
$ diskinfo -v ada0

Installing and using the lsblk command

Enter the line below to install the lsblk command for use later:

$ sudo pkg install lsblk

Then run the lsblk command:

$ lsblk

To list all of the detectable disks on your FreeBSD

$ sysctl kern.disks

To display info on a specific disk, use a similar syntax to the command below, which is requesting info for ada0 disks:

$ lsblk ada0

Wrapping up

This tutorial presents different ways to obtain information on disk-drives in a FreeBSD system. We’ve presented commands and methods that are very different from each other, as they have wildly different intended applications.

About the author

Younis Said

I am a freelancing software project developer, a software engineering graduate and a content writer. I love working with Linux and open-source software.