博客 > Linux命令知識:Linux lsscsi命令詳解
瀏覽量:1287次評論:0次
作者:銳成網(wǎng)絡(luò)整理時間:2024-05-31 15:56:05
Linux作為一款廣泛應(yīng)用于服務(wù)器和工作站的操作系統(tǒng),擁有豐富的命令工具來進(jìn)行系統(tǒng)管理和配置。其中,lsscsi命令是Linux的常用命令,今天我們將深入介紹lsscsi命令相關(guān)知識。不過,在弄明白lsscsi命令之前,我們需要搞清楚什么是SCSI,以及常見的硬盤接口,常用的硬盤參數(shù)。
一、什么是scsi?
SCSI(Small Computer System Interface)是一套完整的數(shù)據(jù)傳輸協(xié)議,其主要功能是在主機(jī)和存儲設(shè)備之間傳送命令、狀態(tài)和塊數(shù)據(jù)。在各類存儲技術(shù)中,SCSI技術(shù)可謂是最重要的脊梁。
SCSI協(xié)議位于操作系統(tǒng)和外部資源之間,它具有一系列的功能組件,操作系統(tǒng)對外部設(shè)備(如磁盤、磁帶、光盤、打印機(jī)等)的I/O操作均可以通過SCSI協(xié)議來實現(xiàn),一般情況下,SCSI協(xié)議都嵌入到設(shè)備驅(qū)動器或者主機(jī)適配器的板載邏輯中。
二、常見硬盤接口
1. IDE接口的硬盤
其英文名稱:Integrated Drive Electronics,常見的2.5英寸IDE硬盤接口它的本意是指把“硬盤控制器”與“盤體”集成在一起的硬盤驅(qū)動器。
IDE代表著硬盤的一種類型,但在實際的應(yīng)用中,人們也習(xí)慣用IDE來稱呼最早出現(xiàn)IDE類型硬盤ATA-1,這種類型的接口隨著接口技術(shù)的發(fā)展已經(jīng)被淘汰了,而其后發(fā)展分支出更多類型的硬盤接口,比如ATA、Ultra ATA、DMA、Ultra DMA等接口都屬于IDE硬盤。
其特點為:價格低廉,兼容性強(qiáng),性價比高,數(shù)據(jù)傳輸慢,不支持熱插拔等等。
2. SCSI接口硬盤
SCSI并不是專門為硬盤設(shè)計的接口,是一種廣泛應(yīng)用于小型機(jī)上的高速數(shù)據(jù)傳輸技術(shù)。
SCSI接口具有應(yīng)用范圍廣、多任務(wù)、帶寬大、CPU占用率低,以及熱插拔等優(yōu)點,但較高的價格使得它很難如IDE硬盤般普及,因此SCSI硬盤主要應(yīng)用于中、高端服務(wù)器和高檔工作站中。
其特點為:傳輸速率高、讀寫性能好、可連接多個設(shè)備、可支持熱插拔,但是價格相對來說比較貴。
3. SATA接口類型
其英文名稱為:Serial Advanced Technology Attachment。使用SATA(Serial ATA)口的硬盤又叫串口硬盤,是未來PC機(jī)硬盤的趨勢。
Serial ATA采用串行連接方式,串行ATA總線使用嵌入式時鐘信號,具備了更強(qiáng)的糾錯能力,與以往相比其最大的區(qū)別在于能對傳輸指令(不僅僅是數(shù)據(jù))進(jìn)行檢查,如果發(fā)現(xiàn)錯誤會自動矯正,這在很大程度上提高了數(shù)據(jù)傳輸?shù)目煽啃浴?/span>
串行接口還具有結(jié)構(gòu)簡單、支持熱插拔的優(yōu)點。
三、 lsscsi命令
lsscsi列出scsi/sata設(shè)備信息,比如硬盤驅(qū)動器,光盤驅(qū)動器。
1. lsscsi 命令安裝
-bash: lsscsi command not found
#Debian
apt-get install lsscsi
#Ubuntu
apt-get install lsscsi
#Alpine
apk add lsscsi
#Arch Linux
pacman -S lsscsi
#Kali Linux
apt-get install lsscsi
#CentOS
yum install lsscsi
#Fedora
dnf install lsscsi
#Raspbian
apt-get install lsscsi
#Docker
docker run cmd.cat/lsscsi lsscsi
2. lsscsi命令英文手冊
1)詳細(xì)命令說明地址
https://sg.danny.cz/scsi/lsscsi.html
2)命令格式
lsscsi 命令語法:
lsscsi [選項] [H:C:T:L]
lsscsi 命令選項:
選項 |
含義 |
-g |
顯示SCSI通用設(shè)備文件名稱 |
-k |
顯示內(nèi)核名稱而不是設(shè)備節(jié)點名 |
-d |
顯示設(shè)備節(jié)點的主要號碼和次要號碼 |
-H |
列出當(dāng)前連接到系統(tǒng)的SCSI主機(jī)而不是SCSI設(shè)備 |
-l |
顯示每一個SCSI設(shè)備(主機(jī))的附加信息 |
-c |
相對于執(zhí)行 cat /proc/scsi/scsi 命令的輸出 |
-p |
顯示額外的數(shù)據(jù)完整性(保護(hù))的信息 |
-t |
顯示傳輸信息 |
-L |
以“屬性名=值”的方式顯示附加信息 |
-v |
當(dāng)信息找到時輸出目錄名 |
-y<路徑> |
假設(shè)sysfs掛載在指定路徑而不是默認(rèn)的 “/sys” |
-s |
顯示容量大小。 |
-c |
用全稱顯示默認(rèn)的信息。 |
-d |
顯示設(shè)備主,次設(shè)備號。 |
-g |
顯示對應(yīng)的sg設(shè)備名。 |
-H |
顯示主機(jī)控制器列表,-Hl,-Hlv。 |
-l |
顯示相關(guān)屬性,-ll,-lll=-L。 |
-v |
顯示設(shè)備屬性所在目錄。 |
-x |
以16進(jìn)制顯示lun號。 |
-p |
輸出DIF,DIX 保護(hù)類型。 |
-P |
輸出有效的保護(hù)模式信息。 |
-i |
顯示udev相關(guān)的屬性 |
-w |
顯示W(wǎng)WN |
-t |
顯示相應(yīng)傳輸信息(ATA,FC,SBP,ISCSI,SPI,SAS,SATA,USB),-Ht,-tl.(包括sas地址) |
3. 結(jié)果含義
四、命令舉例
lsscsi 列出所有 SCSI 設(shè)備:
peng@ubuntu:~$ lsscsi
[3:0:0:0] cd/dvd NECVMWar VMware SATA CD01 1.00 /dev/sr0
[32:0:0:0] disk VMware, VMware Virtual S 1.0 /dev/sda
lsscsi -L列出所有具有詳細(xì)屬性的 SCSI 設(shè)備:
peng@ubuntu:~$ lsscsi -L
[3:0:0:0] cd/dvd NECVMWar VMware SATA CD01 1.00 /dev/sr0
device_blocked=0
iocounterbits=32
iodone_cnt=0x229
ioerr_cnt=0x4
iorequest_cnt=0x23a
queue_depth=1
queue_type=none
scsi_level=6
state=running
timeout=30
type=5
[32:0:0:0] disk VMware, VMware Virtual S 1.0 /dev/sda
device_blocked=0
iocounterbits=32
iodone_cnt=0x37370
ioerr_cnt=0x3
iorequest_cnt=0x37370
queue_depth=32
queue_type=simple
scsi_level=3
state=running
timeout=180
type=0
lsscsi -s列出所有具有人類可讀磁盤容量的 SCSI 設(shè)備:
peng@ubuntu:~$ lsscsi -s
[3:0:0:0] cd/dvd NECVMWar VMware SATA CD01 1.00 /dev/sr0 -
[32:0:0:0] disk VMware, VMware Virtual S 1.0 /dev/sda 536GB
五、其他
1. Linux下scsi相關(guān)文件節(jié)點
/proc/scsi/
peng@ubuntu:~$ cd /proc/scsi/
peng@ubuntu:/proc/scsi$ ls
device_info mptspi scsi sg
peng@ubuntu:/proc/scsi$ cat scsi
Attached devices:
Host: scsi32 Channel: 00 Id: 00 Lun: 00
Vendor: VMware, Model: VMware Virtual S Rev: 1.0
Type: Direct-Access ANSI SCSI revision: 02
Host: scsi3 Channel: 00 Id: 00 Lun: 00
Vendor: NECVMWar Model: VMware SATA CD01 Rev: 1.00
Type: CD-ROM ANSI SCSI revision: 05
/sys/class/scsi_host
peng@ubuntu:/sys/class/scsi_host$ ls
host0 host12 host16 host2 host23 host27 host30 host5 host9
host1 host13 host17 host20 host24 host28 host31 host6
host10 host14 host18 host21 host25 host29 host32 host7
host11 host15 host19 host22 host26 host3 host4 host8
/sys/class/scsi_device
peng@ubuntu:/sys/class/scsi_device$ ls
3:0:0:0 32:0:0:0
/sys/class/scsi_disk
peng@ubuntu:/sys/class/scsi_disk$ ls
32:0:0:0
/sys/class/scsi_generic
peng@ubuntu:/sys/class/scsi_generic$ ls
sg0 sg1
/sys/bus/scsi
peng@ubuntu:/sys/bus/scsi$ ls
devices drivers drivers_autoprobe drivers_probe uevent
peng@ubuntu:/sys/bus/scsi/devices$ ls
3:0:0:0 host11 host16 host20 host25 host3 host5 target3:0:0
32:0:0:0 host12 host17 host21 host26 host30 host6 target32:0:0
host0 host13 host18 host22 host27 host31 host7
host1 host14 host19 host23 host28 host32 host8
host10 host15 host2 host24 host29 host4 host9
其中target3:0:0
對應(yīng)
host:bus:id:lun
2. Linux 開啟 SCSI 日志調(diào)試功能
1)編譯選項中需開啟 CONFIG_SCSI_LOGGING
2)該編譯選項說明
drivers/scsi/Kconfig:213
config SCSI_LOGGING
bool "SCSI logging facility"
depends on SCSI
---help---
This turns on a logging facility that can be used to debug a number
of SCSI related problems.
If you say Y here, no logging output will appear by default, but you
can enable logging by saying Y to "/proc file system support" and
"Sysctl support" below and executing the command
echo <bitmask> > /proc/sys/dev/scsi/logging_level
where <bitmask> is a four byte value representing the logging type
and logging level for each type of logging selected.
There are a number of logging types and you can find them in the
source at <file:drivers/scsi/scsi_logging.h>. The logging levels
are also described in that file and they determine the verbosity of
the logging for each logging type.
If you say N here, it may be harder to track down some types of SCSI
problems. If you say Y here your kernel will be somewhat larger, but
there should be no noticeable performance impact as long as you have
logging turned off.
3)logging 類型源碼文件位置(有說明)
-> drivers\scsi\scsi_logging.h
4)使用說明
/*
* Note - the initial logging level can be set here to log events at boot time.
* After the system is up, you may enable logging via the /proc interface.
*/
unsigned int scsi_logging_level;
#if defined(CONFIG_SCSI_LOGGING)
EXPORT_SYMBOL(scsi_logging_level);
#endif
scsi_logging_level 被定義成int類型(32bit),該機(jī)制使用了30個bit,從低位到高位每3bit為一個logging level從SCSI_LOG_ERROR_SHIFT到SCSI_LOG_IOCTL_SHIFT(SCSI_LOG_XXX_SHIFT為不同level的移位數(shù)),每個level使用的bit數(shù)都是3,所以 SCSI_LOG_XXX_BITS 均為3
5)scsi_logging_level 值可以在 boot 命令行設(shè)置也可以開啟設(shè)備后在 /proc 文件系統(tǒng)中設(shè)置:
-1 - Enable scsi events to syslog. // 開啟所有scsi log
0 - Disable scsi events to syslog. // 關(guān)閉所有scsi log
命令:
echo 0/-1 > /proc/sys/dev/scsi/logging_level
以上就是關(guān)于Linux lsscsi命令的全部介紹了,通過對lsscsi命令的相關(guān)知識,以及格式、示例的相關(guān)介紹,能夠幫助您更好地理解和使用lsscsi命令。
重要聲明:本文來自一口Linux,經(jīng)授權(quán)轉(zhuǎn)載,版權(quán)歸原作者所有,不代表銳成觀點,轉(zhuǎn)載的目的在于傳遞更多知識和信息。
相關(guān)文章推薦
2025-05-27 11:53:22
2024-08-20 17:58:16
2024-08-19 17:49:29
2024-08-19 10:23:28
2024-08-16 17:06:33
熱門工具
標(biāo)簽選擇
閱讀排行
我的評論
還未登錄?點擊登錄