# How are disks and their partitions detected in FreeBSD?



## decuser (Apr 21, 2019)

Hi,

I have seen several different ways to view attached disks in FreeBSD including :

`camcontrol devlist`
`geom disk list`
`sysctl kern.disks`
`dmesg`

I've never really understood how disks are detected by FreeBSD and now I'm curious. I have a few questions that I'm hoping somebody will be willing to answer. I'm not a newb, but I am embarrassed to admit that I often go through these methods using trial and error, rather than logic, now I wanna be logical and efficient using a systematic, knowledge driven approach. Here are my questions:

1. At a process level, in a nutshell, how are disks detected by FreeBSD?
2. What is the canonical set of utilities for getting disk information in FreeBSD (if there is a canonical set, otherwise the most useful)?
3. Which utilities are active (query hardware at time of request) vs passive (report information obtained during initialization)?

I appreciate y'alls expertise and time.

Thanks,

Will


----------



## Phishfry (Apr 21, 2019)

#1) I assume it is what the BIOS passes through as the boot disk. FreeBSD begins by looking for the MBR on BIOS installs.




__





						boot0 stage
					





					docs.freebsd.org
				



Then at a later point in kernel booting the disks are 'detected' by FreeBSD

#2) depends on what kind of drives. nvmecontrol, camcontrol are what I use. Smartmontools is the best if your drive supports SMART.

#3) Only dmesg is 'passive', to an extent, the rest are active.


----------



## Phishfry (Apr 21, 2019)

The cam(4) layer is involved with disk device detection.

Here is a good primer on booting.
https://ericmccorkleblog.wordpress.com/2016/05/15/freebsd-efi-bootloader-refactor/


----------

