From owner-freebsd-questions@FreeBSD.ORG Thu Nov 20 03:20:26 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 B936DA12 for ; Thu, 20 Nov 2014 03:20:26 +0000 (UTC) Received: from mx01.qsc.de (mx01.qsc.de [213.148.129.14]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 7B4A0C3 for ; Thu, 20 Nov 2014 03:20:26 +0000 (UTC) Received: from r56.edvax.de (port-92-195-158-193.dynamic.qsc.de [92.195.158.193]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx01.qsc.de (Postfix) with ESMTPS id DD0173CEB3; Thu, 20 Nov 2014 04:20:17 +0100 (CET) Received: from r56.edvax.de (localhost [127.0.0.1]) by r56.edvax.de (8.14.5/8.14.5) with SMTP id sAK3KGCC002010; Thu, 20 Nov 2014 04:20:16 +0100 (CET) (envelope-from freebsd@edvax.de) Date: Thu, 20 Nov 2014 04:20:16 +0100 From: Polytropon To: "Ivailo A. Tanusheff" 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> Reply-To: Polytropon Organization: EDVAX X-Mailer: Sylpheed 3.1.1 (GTK+ 2.24.5; i386-portbld-freebsd8.2) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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 03:20:26 -0000 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, ...