Free disks enumeration needed

Ivailo A. Tanusheff ITanusheff at postbank.bg
Thu Nov 20 09:19:01 UTC 2014


Thank you for the answer, although it was not exactly what I am aiming to.
Digging into the problem I have found out, that is a disk does not report its serial number, than it has no glabel disked. If the disks reports its serial, then:
diskid/DISK-VB0726485b-41a19b54     N/A  ada3 

So glabel status is perfect solution to find out when some disk is in real usage (both zfs or mounted fs), but only works if his serial is known.
The dmesg command is not so good way to find installed disks on the system, as I can always use: sysctl -n kern.disks

So far I have found one more thing, when I issue for unlisted in the above situation da3 (glabel status has no entry about da3):

root at FreeBSD:~ # geom disk list da3
Geom name: da3
Providers:
1. Name: da3
   Mediasize: 536870912 (512M)
   Sectorsize: 512
   Mode: r1w1e1
   descr: VBOX HARDDISK
   ident: (null)
   fwsectors: 32
   fwheads: 64

As far as I digged so far if Mode is r0w0e0 the disk can be considered "free".
But I am not sure what exactly this mode represents, as there is almost no information about that.
Anyone knows something on this?

Regards,
Ivailo Tanusheff

-----Original Message-----
From: Polytropon [mailto:freebsd at edvax.de] 
Sent: Thursday, November 20, 2014 5:20 AM
To: Ivailo A. Tanusheff
Cc: freebsd-questions at freebsd.org
Subject: Re: Free disks enumeration needed

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, ...

Disclaimer:

This communication is confidential. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution or taking any action in reliance on the contents of this information is strictly prohibited and may be unlawful. If you have received this communication by mistake, please notify us immediately by responding to this email and then delete it from your system.
Eurobank Bulgaria AD is not responsible for, nor endorses, any opinion, recommendation, conclusion, solicitation, offer or agreement or any information contained in this communication.
Eurobank Bulgaria AD cannot accept any responsibility for the accuracy or completeness of this message as it has been transmitted over a public network. If you suspect that the message may have been intercepted or amended, please call the sender.


More information about the freebsd-questions mailing list