2021SC@SDUSC
设备管理
在计算机系统中,除了CPU和内存之外,其余的大部分硬件设备称为外部设备。外部设备包括常用的I/O(输入/输出)设备、外存设备以及终端设备等。
实验七:设备管理部分
1.实验目的
1)掌握 Ubuntu 系统下文件系统中设备管理部分命令行的原理及使用
2.实验内容
本次实验主要是掌握 Linux 系统下的设备管理部分的使用,主要包括以下内容:
第七部分(设备管理部分):
1.mount 命令 – 文件系统挂载
2.MAKEDEV 命令 – 建立设备
3.setleds 命令 – 设定键盘上方三个 LED 的状态
4.lspci 命令 – 显示当前设备所有 PCI 总线信息
5.sensors 命令 – 检测服务器内部温度及电压
3.实验环境
树莓派 4B,系统为 Ubuntu 21.10 系统 。实验的编程环境为 Terminal 终端程序
4.实验步骤
1.mount 命令 – 文件系统挂载
(1)语法
mount [参数]
(2)功能
mount命令用于加载文件系统到指定的加载点。此命令的最常用于挂载cdrom,使我们可以访问cdrom中的数据,因为你将光盘插入cdrom中,Linux并不会自动挂载,必须使用Linux mount命令来手动完成挂载。
(3)参数
-V:显示程序版本;
-l:显示已加载的文件系统列表;
-h:显示帮助信息并退出;
-v:冗长模式,输出指令执行的详细信息;
-n:加载没有写入文件“/etc/mtab”中的文件系统;
-r:将文件系统加载为只读模式;
-a:加载文件“/etc/fstab”中描述的所有文件系统。
(4)实例
mount -t auto /dev/cdrom /mnt/cdrom
mount: mount point /mnt/cdrom does not exist /mnt/cdrom目录不存在,需要先创建。
cd /mnt -bash: cd: /mnt: No such file or directory mkdir -p /mnt/cdrom 创建/mnt/cdrom目录 ls bin dev home lib media mnt proc sbin srv tmp var boot etc initrd lost+found misc opt root selinux sys usr
mount -t auto /dev/cdrom /mnt/cdrom 挂载cdrom mount: block device /dev/cdrom is write-protected, mounting read-only 挂载成功
ll /mnt/cdrom 查看cdrom里面内容 total 859 dr-xr-xr-x 4 root root 2048 Sep 4 2005 CentOS -r--r--r-- 2 root root 8859 Mar 19 2005 centosdocs-man.css -r--r--r-- 9 root root 18009 Mar 1 2005 GPL dr-xr-xr-x 2 root root 241664 May 7 02:32 headers dr-xr-xr-x 4 root root 2048 May 7 02:23 images dr-xr-xr-x 2 root root 4096 May 7 02:23 isolinux dr-xr-xr-x 2 root root 18432 May 2 18:50 NOTES -r--r--r-- 2 root root 5443 May 7 01:49 RELEASE-NOTES-en.html dr-xr-xr-x 2 root root 2048 May 7 02:34 repodata -r--r--r-- 9 root root 1795 Mar 1 2005 rpm-GPG-KEY -r--r--r-- 2 root root 1795 Mar 1 2005 RPM-GPG-KEY-centos4 -r--r--r-- 1 root root 571730 May 7 01:39 yumgroups.xml
2.MAKEDEV 命令 – 建立设备
(1)语法
MAKEDEV [参数]
(2)功能
MAKEDEV命令用于新增 /dev/ 下的装置档案,多数分区已经将所有的档案都产生,故一般而言不太会需要用到这个命令。
(3)参数
MAKEDEV -V
MAKEDEV [ -n ] [ -v ] update
MAKEDEV [ -n ] [ -v ] [ -d ] device ...
(4)实例
删除设备:
MAKEDEV -d device
3.setleds 命令 – 设定键盘上方三个 LED 的状态
(1)语法
setleds [参数]
(2)功能
setleds命令用来设定键盘上方三个 LED 的状态。在 Linux 中,每一个虚拟主控台都有独立的设定。
(3)参数
-F:预设的选项,设定虚拟主控台的状态。
-D:除了改变虚拟主控台的状态外,还改变预设的状态。
-L:不改变虚拟主控台的状态,但直接改变 LED 显示的状态。这会使得 LDE 显示和目前虚拟主控台的状态不符合。我们可以在稍后用 -L 且不含其它选项的 setleds 命令回复正常状态。
-num +num:将数字键打开或关闭。
-caps +caps:把大小写键打开或关闭。
-scroll +scroll:把选项键打开或关闭。
(4)实例
将数字键打开,其馀二个灯关闭。
# setleds +num -caps -scroll
4.lspci 命令 – 显示当前设备所有 PCI 总线信息
(1)语法
lspci [参数]
(2)功能
lspci命令用于显示当前主机的所有PCI总线信息,以及所有已连接的PCI设备信息。
(3)参数
-n:以数字方式显示PCI厂商和设备代码;
-t:以树状结构显示PCI设备的层次关系,包括所有的总线、桥、设备以及它们之间的联接;
-b:以总线为中心的视图;
-d:仅显示给定厂商和设备的信息;
-s:仅显示指定总线、插槽上的设备和设备上的功能块信息;
-i:指定PCI编号列表文件,而不使用默认的文件;
-m:以机器可读方式显示PCI设备信息。
(4)实例
[root@localhost ~]# lspci
00:00.0 host bridge: Intel Corporation 5500 I/O Hub to ESI Port (rev 22)
00:01.0 PCI bridge: Intel Corporation 5520/5500/X58 I/O Hub PCI Express Root Port 1 (rev 22)
00:02.0 PCI bridge: Intel Corporation 5520/5500/X58 I/O Hub PCI Express Root Port 2 (rev 22)
00:03.0 PCI bridge: Intel Corporation 5520/5500/X58 I/O Hub PCI Express Root Port 3 (rev 22)
00:07.0 PCI bridge: Intel Corporation 5520/5500/X58 I/O Hub PCI Express Root Port 7 (rev 22)
00:08.0 PCI bridge: Intel Corporation 5520/5500/X58 I/O Hub PCI Express Root Port 8 (rev 22)
00:09.0 PCI bridge: Intel Corporation 5520/5500/X58 I/O Hub PCI Express Root Port 9 (rev 22)
00:0a.0 PCI bridge: Intel Corporation 5520/5500/X58 I/O Hub PCI Express Root Port 10 (rev 22)
00:10.0 PIC: Intel Corporation 5520/5500/X58 Physical and Link Layer Registers Port 0 (rev 22)
00:10.1 PIC: Intel Corporation 5520/5500/X58 Routing and Protocol Layer Registers Port 0 (rev 22)
00:11.0 PIC: Intel Corporation 5520/5500 Physical and Link Layer Registers Port 1 (rev 22)
00:11.1 PIC: Intel Corporation 5520/5500 Routing & Protocol Layer Register Port 1 (rev 22)
00:14.0 PIC: Intel Corporation 5520/5500/X58 I/O Hub System Management Registers (rev 22)
00:14.1 PIC: Intel Corporation 5520/5500/X58 I/O Hub GPIO and Scratch Pad Registers (rev 22)
00:14.2 PIC: Intel Corporation 5520/5500/X58 I/O Hub Control Status and RAS Registers (rev 22)
00:14.3 PIC: Intel Corporation 5520/5500/X58 I/O Hub Throttle Registers (rev 22)
00:16.0 System peripheral: Intel Corporation 5520/5500/X58 Chipset QuickData Technology Device (rev 22)
00:16.1 System peripheral: Intel Corporation 5520/5500/X58 Chipset QuickData Technology Device (rev 22)
00:16.2 System peripheral: Intel Corporation 5520/5500/X58 Chipset QuickData Technology Device (rev 22)
00:16.3 System peripheral: Intel Corporation 5520/5500/X58 Chipset QuickData Technology Device (rev 22)
00:16.4 System peripheral: Intel Corporation 5520/5500/X58 Chipset QuickData Technology Device (rev 22)
00:16.5 System peripheral: Intel Corporation 5520/5500/X58 Chipset QuickData Technology Device (rev 22)
00:16.6 System peripheral: Intel Corporation 5520/5500/X58 Chipset QuickData Technology Device (rev 22)
00:16.7 System peripheral: Intel Corporation 5520/5500/X58 Chipset QuickData Technology Device (rev 22)
00:1a.0 USB controller: Intel Corporation 82801JI (ICH10 Family) USB UHCI Controller #4
00:1a.1 USB controller: Intel Corporation 82801JI (ICH10 Family) USB UHCI Controller #5
00:1a.7 USB controller: Intel Corporation 82801JI (ICH10 Family) USB2 EHCI Controller #2
00:1b.0 Audio device: Intel Corporation 82801JI (ICH10 Family) HD Audio Controller
00:1c.0 PCI bridge: Intel Corporation 82801JI (ICH10 Family) PCI Express Root Port 1
00:1c.4 PCI bridge: Intel Corporation 82801JI (ICH10 Family) PCI Express Root Port 5
00:1c.5 PCI bridge: Intel Corporation 82801JI (ICH10 Family) PCI Express Root Port 6
00:1d.0 USB controller: Intel Corporation 82801JI (ICH10 Family) USB UHCI Controller #1
00:1d.1 USB controller: Intel Corporation 82801JI (ICH10 Family) USB UHCI Controller #2
00:1d.2 USB controller: Intel Corporation 82801JI (ICH10 Family) USB UHCI Controller #3
00:1d.3 USB controller: Intel Corporation 82801JI (ICH10 Family) USB UHCI Controller #6
00:1d.7 USB controller: Intel Corporation 82801JI (ICH10 Family) USB2 EHCI Controller #1
00:1e.0 PCI bridge: Intel Corporation 82801 PCI Bridge (rev 90)
00:1f.0 ISA bridge: Intel Corporation 82801JIR (ICH10R) lpc Interface Controller
00:1f.2 IDE interface: Intel Corporation 82801JI (ICH10 Family) 4 port SATA IDE Controller #1
00:1f.3 SMBus: Intel Corporation 82801JI (ICH10 Family) SMBus Controller
00:1f.5 IDE interface: Intel Corporation 82801JI (ICH10 Family) 2 port SATA IDE Controller #2
01:01.0 VGA compatible controller: ASPEED Technology, Inc. ASPEED Graphics Family (rev 10)
02:00.0 Ethernet controller: Intel Corporation 82574L Gigabit Network Connection
03:00.0 Ethernet controller: Intel Corporation 82574L Gigabit Network Connection
04:00.0 Serial Attached SCSI controller: LSI Logic / Symbios Logic SAS2008 PCI-Express Fusion-MPT SAS-2 [Falcon] (rev 03)
5.sensors 命令 – 检测服务器内部温度及电压
(1)语法
sensors [参数]
(2)功能
sensors命令用于检测服务器内部降温系统是否健康,可以监控主板,CPU的工作电压,风扇转速、温度等数据 。
(3)参数
-c, --config-file Specify a config file
-h, --help Display this help text
-s, --set Execute `set' statements (root only)
-f, --fahrenheit Show temperatures in degrees fahrenheit
-A, --no-adapter Do not show adapter for each chip
--bus-list Generate bus statements for sensors.conf
-u Raw output (debugging only)
-v, --version Display the program version
(4)实例
检测cpu工作电压,温度等:
[root@linux265 ~]# sensors coretemp-isa-0000 Core 0: +48.0°C (high = +87.0°C, crit = +97.0°C) Core 1: +46.0°C (high = +87.0°C, crit = +97.0°C) Core 2: +47.0°C (high = +87.0°C, crit = +97.0°C) Core 3: +46.0°C (high = +87.0°C, crit = +97.0°C)
根据sensors,检测到风扇连接的接口,向相应pwm文件输入值进行控制。
例如:
echo "100">/sys/class/hwmon/hwmon0/device/pwm1
例如:
echo "255">/sys/class/hwmon/hwmon0/device/pwm1