Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 20 Nov 2014 04:20:16 +0100
From:      Polytropon <freebsd@edvax.de>
To:        "Ivailo A. Tanusheff" <ITanusheff@postbank.bg>
Cc:        "freebsd-questions@freebsd.org" <freebsd-questions@freebsd.org>
Subject:   Re: Free disks enumeration needed
Message-ID:  <20141120042016.c49dcb83.freebsd@edvax.de>
In-Reply-To: <1422065A4E115F409E22C1EC9EDAFBA4220D87FE@sofdc01exc02.postbank.bg>
References:  <1422065A4E115F409E22C1EC9EDAFBA4220D87FE@sofdc01exc02.postbank.bg>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, 19 Nov 2014 14:52:55 +0000, Ivailo A. Tanusheff wrote:
> I have a FreeBSD server, with attached both SATA and SCSI drives.
> The server uses both ZFS and UFS file systems.
> 
> I want to find a way to find out which drives are available to
> be used in new zfs pool with a script or C program, i.e. which
> drives are not used by zfs or ufs on the system.

I'd say writing a script, calling some commands and
postprocessing their output will be the easier way.
Tools like sed, awk and perl can help.



> For the SATA drives I believe glabel status gives me the
> reasonable information, but I do not see any SCSI drive there.

The usage does not depend on what kind of disk it is.
Actually, both disk types can be used for ZFS and UFS.
SATA disk show up as /dev/ad* or /dev/ada* (preferred),
while SCSI disks will be /dev/da*, the generic naming
for direct access disks and media.

Note that "glabel status" will only work when there are
actually _labels_ on the disks.



> It is easy to enumerate disks installed on the system, but how
> to find out which are "free" for use?

You'll have to define precisely what you mean by "in use":

If it is about being mounted, parsing the "mount" command
would help. But in case a disk has data on it, but is
currently _not_ mounted, the result would be of course
incorrect.

If it is about having data on it, you could examine if
there are UFS partitions on the disks in question, using
the "gpart show" command. This works best for UFS.
The traditional commands "fdisk" and "bsdlabel" could
also be used, but they are typically discouraged in
favour of GPT because it can handle both old MBR and
new GPT partitioning schemes.

It it is about being part of a ZFS pool, query the ZFS
commands, like "zpool list" or "zpool status -v".

If it is about being online, check the following commands:
"atacontrol list" and "camcontrol devlist".

The "dmesg" command will also tell you about which disks
are connected to the system (grep for "^da" and "^ada" lines
and refine the search pattern).

See the corresponding manual pages for details.




-- 
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20141120042016.c49dcb83.freebsd>