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

next in thread | previous in thread | raw e-mail | index | archive | help
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 it=
s serial number, than it has no glabel disked. If the disks reports its seri=
al, then:
diskid/DISK-VB0726485b-41a19b54     N/A  ada3 

So glabel status is perfect solution to find out when some disk is in real u=
sage (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 s=
ituation da3 (glabel status has no entry about da3):

root@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 i=
nformation about that.
Anyone knows something on this?

Regards,
Ivailo Tanusheff

-----Original Message-----
From: Polytropon [mailto:freebsd@edvax.de] 
Sent: Thursday, November 20, 2014 5:20 AM
To: Ivailo A. Tanusheff
Cc: freebsd-questions@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 out=
put 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 wil=
l 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 woul=
d be of course incorrect.

If it is about having data on it, you could examine if there are UFS partiti=
ons on the disks in question, using the "gpart show" command. This works bes=
t 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 M=
BR 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 th=
e 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, y=
ou are hereby notified that any disclosure, copying, distribution or taking=
 any action in reliance on the contents of this information is strictly proh=
ibited and may be unlawful. If you have received this communication by mista=
ke, 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, reco=
mmendation, conclusion, solicitation, offer or agreement or any information=
 contained in this communication.
Eurobank Bulgaria AD cannot accept any responsibility for the accuracy or co=
mpleteness of this message as it has been transmitted over a public network.=
 If you suspect that the message may have been intercepted or amended, pleas=
e call the sender.



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