FreeBSD查找所有已安装的硬盘大小信息

时间:2020-01-09 10:38:32  来源:igfitidea点击:

如何在FreeBSD操作系统下找到所有已安装的硬盘驱动器名称,而无需重新启动服务器?
在FreeBSD中,如何在Linux中使用等同于fdisk -l的硬盘来列出所有硬盘驱动器?
如何在FreeBSD中找到硬盘大小?
在FreeBSD下查找检测到的硬件信息的最简单方法是通过/var/run/dmesg.boot文件。
此文件通常是在启动时挂载文件系统后不久获取的缓冲区内容的快照。
直到系统重启,它才被修改。
与Linux一样,FreeBSD遵循某种物理磁盘命名约定:

  • IDE硬盘名称以" ad" /第一个IDE硬盘/dev/ad0开头,第二个/dev/ad1硬盘开头,依此类推。
  • SATA/SSD(ATA直接访问设备驱动程序)磁盘名称以" ad"/dev/ada,/dev/sdb等开头。
  • SCSI硬盘名称以da开头 /dev/da*
  • IDE CDROM/RW/DVD名称以acd开头 /dev/acd*
  • SCSI CDROM/RW/DVD名称以cd开头 /dev/cd*

列出FreeBSD中所有检测到的硬盘/cdrom/SSD

输入以下grep命令,执行:

# egrep 'da[0-9]|cd[0-9]' /var/run/dmesg.boot

或者

# egrep 'ad[0-9]|cd[0-9]' /var/run/dmesg.boot

输出示例:

acd0: DVDROM  at ata0-slave UDMA33
ad4: 239372MB  at ata2-master SATA150
ad6: 239372MB  at ata3-master SATA150
Trying to mount root from ufs:/dev/ad4s1a

从上面的输出中可以明显看出,我的FreeBSD服务器上安装了以下存储:

  • ad4:我的第一个硬盘连接到ATA通道2
  • ad6:我的第二块硬盘连接到ATA通道3
  • acd0:我的DVD ROM

geom实用程序

尝试显示有关使用geom的磁盘的详细信息:

# geom disk list
# geom disk list ada5
# geom disk list ada2

输出示例:

Geom name: ada2
Providers:
1. Name: ada2
   Mediasize: 64023257088 (60G)
   Sectorsize: 512
   Stripesize: 4096
   Stripeoffset: 0
   Mode: r0w0e0
   descr: SanDisk SD6SB1M064G1022I
   lunid: 5001b44e71f4a5a6
   ident: 152041400742
   rotationrate: 0
   fwsectors: 63
   fwheads: 16

您可以使用egrep命令/grep命令过滤掉信息:

# geom disk list ada3 | grep Mediasize

输出示例

Mediasize: 6001175126016 (5.5T)

atacontrol命令(对于较旧的FreeBSD版本)

atacontrol实用程序是一个控制程序,可为用户提供对FreeBSD ata(IDE/SATA硬盘)子系统的访问和控制。

使用CAM的FreeBSD设备列表

如何列出当前分区信息?

使用以下命令:

# gpart show

输出示例:

=>      34  31277165  ada3  GPT  (14G)
        34      1024     1  bios-boot  (512k)
      1058         6        - free -  (3.0k)
      1064  31275184     2  freebsd-zfs  (14G)
  31276248       951        - free -  (475k)
 
=>         34  11721045101  ada0  GPT  (5.5T)
           34           94        - free -  (47k)
          128      4194304     1  freebsd-swap  (2.0G)
      4194432  11716850696     2  freebsd-zfs  (5.5T)
  11721045128            7        - free -  (3.5k)
 
=>         34  11721045101  ada1  GPT  (5.5T)
           34           94        - free -  (47k)
          128      4194304     1  freebsd-swap  (2.0G)
      4194432  11716850696     2  freebsd-zfs  (5.5T)
  11721045128            7        - free -  (3.5k)
 
=>         34  11721045101  ada5  GPT  (5.5T)
           34           94        - free -  (47k)
          128      4194304     1  freebsd-swap  (2.0G)
      4194432  11716850696     2  freebsd-zfs  (5.5T)
  11721045128            7        - free -  (3.5k)
 
=>         34  11721045101  ada6  GPT  (5.5T)
           34           94        - free -  (47k)
          128      4194304     1  freebsd-swap  (2.0G)
      4194432  11716850696     2  freebsd-zfs  (5.5T)
  11721045128            7        - free -  (3.5k)
 
=>       34  234441581  ada4  GPT  (111G)
         34         94        - free -  (47k)
        128  234441480     1  freebsd-zfs  (111G)
  234441608          7        - free -  (3.5k)
 
=>       34  125045357  ada2  GPT  (59G)
         34         94        - free -  (47k)
        128  125045256     1  freebsd-zfs  (59G)
  125045384          7        - free -  (3.5k)

使用GEOM探测磁盘

执行以下命令(源):

## this run script using sh ##
 
sh -c '. /usr/share/bsdconfig/device.subr;f_device_menu "" "" "" DISK'

用于列出和检测FreeBSD服务器磁盘的shell脚本

创建一个名为showdisk的shell脚本,如下所示:

#!/bin/sh
# Name: showdisk
# Author: FrauBSD
#----------------------------------------
. /usr/share/bsdconfig/device.subr || exit
[ "$( id -u )" -eq 0 ] && WITH_CAMCONTROL=1
while :; do
	info="gpart(8) show %s:\n%s\n\n" disk= gpart= inquiry= identify=
        device=$( msg_cancel=Done f_device_menu "$DIALOG_TITLE" \
		"Select a disk device" "$hline_arrows_tab_enter" \
                $DEVICE_TYPE_DISK 2>&1 ) || break
        $device get name disk
	gpart=$( gpart show $disk 2>&1 )
	if [ "$WITH_CAMCONTROL" ]; then
		inquiry=$( camcontrol inquiry $disk 2>&1 )
		identify=$( camcontrol identify $disk 2>&1 )
	else
		info="${info}WARNING! Must be root to use camcontrol(8)!\n"
	fi
	[ "$inquiry" ] && info="${info}camcontrol(8) inquiry $disk:\n%s\n\n"
	[ "$identify" ] && info="${info}camcontrol(8) identify $disk:\n%s\n"
	f_show_msg "$info" "$disk" "$gpart" \
		${inquiry:+"$inquiry"} ${identify:+"$identify"}
done

接下来,在FreeBSD中执行shell脚本:

chmod +x showdisk
./showdisk

列出FreeBSD中所有已连接的SSD和硬盘设备

FreeBSD打印附带的磁盘大小

运行diskinfo命令:

diskinfo -v disk_name
diskinfo -v ada4
diskinfo -v ada1

输出示例:

ada1
	512         	# sectorsize
	6001175126016	# mediasize in bytes (5.5T)
	11721045168 	# mediasize in sectors
	4096        	# stripesize
	0           	# stripeoffset
	11628021    	# Cylinders according to firmware.
	16          	# Heads according to firmware.
	63          	# Sectors according to firmware.
	HGST HDN726060ALE614	# Disk descr.
	K1JVDUGD    	# Disk ident.
	No          	# TRIM/UNMAP support
	7200        	# Rotation rate in RPM
	Not_Zoned   	# Zone Mode

lsblk命令

让我们如下安装lsblk命令:

sudo pkg install lsblk

输出示例:

Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
The following 1 package(s) will be affected (of 0 checked):

New packages to be INSTALLED:
	lsblk: 1.0

Number of packages to be installed: 1

5 KiB to be downloaded.

Proceed with this action? [y/N]: y
[1/1] Fetching lsblk-1.0.txz: 100%    5 KiB   4.9kB/s    00:01    
Checking integrity... done (0 conflicting)
[1/1] Installing lsblk-1.0...
[1/1] Extracting lsblk-1.0: 100%

如下运行:

lsblk
## get a list of actual disks ##
sysctl kern.disks
## find info about the ada0 disk ##
lsblk da0