From owner-freebsd-questions@FreeBSD.ORG Thu Nov 20 09:19:01 2014 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 1A028D31 for ; Thu, 20 Nov 2014 09:19:01 +0000 (UTC) Received: from mail.postbank.bg (mx.postbank.bg [195.242.126.253]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "mail.postbank.bg", Issuer "GeoTrust DV SSL CA" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4F0A599A for ; Thu, 20 Nov 2014 09:18:59 +0000 (UTC) X-AuditID: ac100166-f79e46d000000c6c-72-546db1fe9116 Received: from sofdc01excv14.postbank.bg ( [10.1.129.37]) (using TLS with cipher AES128-SHA (128/128 bits)) (Client did not present a certificate) by mail.postbank.bg (Eurobank AD BG Outbound mail system) with SMTP id 60.AF.03180.EF1BD645; Thu, 20 Nov 2014 11:18:55 +0200 (EET) From: "Ivailo A. Tanusheff" To: Polytropon Subject: RE: Free disks enumeration needed Thread-Topic: Free disks enumeration needed Thread-Index: AdAECIA1HM7DkQZsSc6CYZFchKYsbAAV6O4AABB1wfA= Date: Thu, 20 Nov 2014 09:18:54 +0000 Message-ID: <1422065A4E115F409E22C1EC9EDAFBA4220DCC53@sofdc01exc02.postbank.bg> References: <1422065A4E115F409E22C1EC9EDAFBA4220D87FE@sofdc01exc02.postbank.bg> <20141120042016.c49dcb83.freebsd@edvax.de> In-Reply-To: <20141120042016.c49dcb83.freebsd@edvax.de> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.1.2.26] Content-Type: text/plain; charset="us-ascii" content-transfer-encoding: quoted-printable MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmplk+LIzCtJLcpLzFFi42LhYmxU1f2/MTfE4NQ5bouXXzexWFy9doHV gcnjZusyJo8Zn+azBDBFNTDaJObl5ZcklqQqpKQWJ9sqRQfkF5ckJeZlxyq4ZBYn5yRm5qYW KSlkptgqGSspFOQkJqfmpuaV2ColFhSk5qUo2XEpYAAboLLMPIXUvOT8lMy8dFslz2B/XQsL U0tdQyU7hKlWasqGxgn/2TMaNu1hKXglU3F+x0HmBsZzYl2MnBwSAiYSjasmMkPYYhIX7q1n 62Lk4hASmM0k8Wn/bLAEG1DRtrl7mEBsEQFFiZlNi1lBbGYBZ4n2Lw/AaoQFtCQWzJ/GDFGj LTF132UWCNtKYv7ft0A2BweLgKrExfvxIGFeAX+Js28msoPYQgI1EovOHwCzOQXMJW582g7W ygh0z/dTa5ggVolL3HoynwniTgGJJXvOQ90sKvHy8T9WCFtW4tG3x1D1OhILdn9ig7C1JZYt fM0MsVdQ4uTMJywTGEVnIRk7C0nLLCQts5C0LGBkWcUoWZyflpJsYBjs615mYKRXAI1FvaT0 TYzA5LBGgDFtB+ObK06HGAU4GJV4eBMsckOEWBPLiitzDzFKcDArifAqLQEK8aYkVlalFuXH F5XmpBYfYlzBCAydicxSosn5wNSVVxJvaGJgYmJmaWpqYWxmQYGwoamJkaGFgZmFKWnCSuK8 1osyQ4QE0oGJNjs1tSC1COZWJg5OqQZGlXWaInJXf99kdZY12XhReuOd934JLOlH+AJiNl0T a3hxQP/q5lyG7ed1YrTLGsQ79x95ebE9Tq/yi9I2sVcuH79LFr77bGTe/9l0hpBfbpCr0u4C vs8nVhlsrwra53l1a/nbAGbNGfK7FSxX8Ej+FMvKr3HKSPv0t2rO3sc/3v9xFfmiF/pSiaU4 I9FQi7moOBEAQcabb5gDAAA= Cc: "freebsd-questions@freebsd.org" X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 20 Nov 2014 09:19:01 -0000 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.