LINUX系统获取UUID的方式

2021-08-31   


LINUX系统获取UUID的方式

UUID 是系统的唯一识别码,永远不会重复,比较有用。

1、生成随机UUID码

Linux 内核本身具有生成随机 UUID 的功能,该命令每执行一次,就可以输出一个随机的UUID

cat /proc/sys/kernel/random/uuid

2、dmidecode命令

获取 Linux 系统的 uuid,命令如下:

dmidecode -t system | less
dmidecode -s system-uuid

dmidecode 命令 可以让你在 Linux 系统下获取有关硬件方面的信息。dmidecode的作用是将 DMI 数据库中的信息解码,以可读的文本方式显示。由于DMI信息可以人为修改,因此里面的信息不一定是系统准确的信息。dmidecode遵循SMBIOS/DMI 标准,其输出的信息包括BIOS、系统、主板、处理器、内存、缓存等等

DMI(Desktop Management Interface,DMI)就是帮助收集电脑系统信息的管理系统,DMI 信息的收集必须在严格遵照 SMBIOS 规范的前提下进行。SMBIOS(System Management BIOS)是主板或系统制造者以标准格式显示产品管理信息所需遵循的统一规范。SMBIOS 和 DMI 是由行业指导机构 Desktop Management Task Force(DMTF)起草的开放性的技术标准,其中 DMI 设计适用于任何的平台和操作系统

DMI 充当了管理工具和系统层之间接口的角色。它建立了标准的可管理系统更加方便了电脑厂商和用户对系统的了解。DMI 的主要组成部分是 Management Information Format(MIF)数据库。这个数据库包括了所有有关电脑系统和配件的信息。通过 DMI,用户可以获取序列号、电脑厂商、串口信息以及其它系统配件信息

语法

dmidecode [选项]

选项

-d:(default:/dev/mem)从设备文件读取信息,输出内容与不加参数标准输出相同
-h:显示帮助信息
-s:只显示指定 DMI 字符串的信息(string)
-t:只显示指定条目的信息(type)
-u:显示未解码的原始条目内容
-q:显示更少的简化信息
-V:显示版本信息
--dump-bin file:将 DMI 数据转储到一个二进制文件中
--from-dump FILE:从一个二进制文件读取 DMI 数据

dmidecode参数string及type列表:

(1)Valid string keywords are:(2)Valid type keywords are:(3)type 全部编码列表:
bios-vendorbiosBIOS
bios-versionsystemSystem
bios-release-datebaseboardBase Board
system-manufacturerchassisChassis
system-product-nameprocessorProcessor
system-versionmemoryMemory Controller
system-serial-numberCacheMemory Module
system-uuidconnectorCache
baseboard-manufacturerslotPort Connector
baseboard-product-name System Slots
baseboard-version On Board Devices
baseboard-serial-number OEM Strings
baseboard-asset-tag System Configuration Options
chassis-manufacturer BIOS Language
chassis-type Group Associations
chassis-version System Event Log
chassis-serial-number Physical Memory Array
chassis-asset-tag Memory Device
processor-family 32-bit Memory Error
processor-manufacturer Memory Array Mapped Address
processor-version Memory Device Mapped Address
processor-frequency Built-in Pointing Device
Portable Battery
System Reset
Hardware Security
System Power Controls
Voltage Probe
Cooling Device
Temperature Probe
Electrical Current Probe
Out-of-band Remote Access
Boot Integrity Services
System Boot
64-bit Memory Error
Management Device
Management Device Component
Management Device Threshold Data
Memory Channel
IPMI Device
Power Supply
Additional Information
Onboard Device

实例

#查看服务器型号
dmidecode | grep 'Product Name'
#查看主板的序列号
dmidecode |grep 'Serial Number'
#查看系统序列号
dmidecode -s system-serial-number
#查看BIOS相关的硬件信息
dmidecode -t bios
#查看系统相关的硬件信息
dmidecode -t system
#查看主板相关的硬件信息
dmidecode -t baseboard
#查看机箱相关的硬件信息
dmidecode -t chassis
#查看处理器相关的硬件信息
dmidecode -t processor
#查看内存信息
dmidecode -t memory
#最大支持内存容量
dmidecode | grep "Maximum Capacity" |sed  "s/^[ \t]*//"
#现有内存数量和内存大小
dmidecode | grep -A16 "Memory Device" | grep "Size" |sed 's/^[ \t]*//'
#查询内存条数
dmidecode -t 17 | grep "Size.*MB" | wc -l
#查看OEM信息
dmidecode -t 11
#查看厂商产品
dmidecode -t 1

不带选项执行 dmidecode 命令通常会输出所有的硬件信息。dmidecode 命令有个很有用的选项-t,可以按指定类型输出相关信息,假如要获得处理器方面的信息,则可以执行:

[root@localhost ~]# dmidecode -t processor
# dmidecode 2.11
SMBIOS 2.5 present. 

Handle 0x0001, DMI type 4, 40 bytes
Processor Information
     Socket Designation: Node 1 Socket 1
     Type: Central Processor
     Family: Xeon MP   
     Manufacturer:Intel(R) Corporation
     id: C2 06 02 00 FF FB EB BF
     Signature: Type 0, Family 6, Model 44, Stepping 2
     Flags: 
         FPU (Floating-point unit on-chip)
         VME (Virtual mode extension)
         DE (Debugging extension)
         PSE (Page size extension)
         TSC (time stamp counter)
         MSR (Model specific registers)
         PAE (Physical address extension)
         MCE (Machine check exception)
         CX8 (CMPXCHG8 instruction supported)
         APIC (On-chip APIC hardware supported)
         SEP (Fast system call)
         MTRR (Memory type range registers)
         PGE (Page global enable)
         MCA (Machine check architecture)
         CMOV (Conditional move instruction supported)
         PAT (Page attribute table)
         PSE-36 (36-bit page size extension)
         CLFSH (CLFLUSH instruction supported)
         DS (Debug store)
         ACPI (ACPI supported)
         MMX (MMX technology supported)
         FXSR (FXSAVE and FXSTOR instructions supported)
         SSE (Streaming SIMD extensions)
         SSE2 (Streaming SIMD extensions 2)
         ss (Self-snoop)
         HTT (Multi-threading)
         TM (Thermal monitor supported)
         PBE (Pending break enabled)
     Version: Intel(R) Xeon(R) CPU E5620 @ 2.40GHz
     Voltage: 1.2 V
     External Clock: 5866 MHz
     Max Speed: 4400 MHz
     Current Speed: 2400 MHz
     Status: Populated, Enabled
     Upgrade: ZIF Socket
     L1 Cache Handle: 0x0002
     L2 Cache Handle: 0x0003
     L3 Cache Handle: 0x0004
     Serial Number: Not Specified
     Asset Tag: Not Specified
     Part Number: Not Specified
     Core Count: 4
     Core Enabled: 4
     Thread Count: 8
     Characteristics: 
          64-bit capable

Handle 0x0055, DMI type 4, 40 bytes
Processor Information
     Socket Designation: Node 1 Socket 2
     Type: Central Processor
     Family: Xeon MP
     Manufacturer: Not Specified
     ID: 00 00 00 00 00 00 00 00
     Signature: Type 0, Family 0, Model 0, Stepping 0
     Flags: None
     Version: Not Specified
     Voltage: 1.2 V External
     Clock: 5866 MHz
     Max Speed: 4400 MHz
     Current Speed: Unknown
     Status: Unpopulated
     Upgrade: ZIF Socket
     L1 Cache Handle: Not Provided
     L2 Cache Handle: Not Provided
     L3 Cache Handle: Not Provided
     Serial Number: Not Specified
     Asset Tag: Not Specified
     Part Number: Not Specified
     Characteristics: None

下载

Dmidecode源码包下载地址
Windows版本下载地址

Q.E.D.