Linux UUIDs: Unlocking the secrets of file system identification.
在Linux系统中,每个文件系统都有一个唯一的标识符,称为UUID。了解UUID的概念和作用对于Linux系统管理者来说是非常重要的。本文将为您详细介绍UUID的基本原理和使用方法,助您更好地管理Linux系统。
有许多可用的实用程序可以查看 UUID。本文我们将会向你展示多种查看 UUID 的方法,并且你可以选择一种适合于你的方法。
何为 UUID?
UUID 意即通用唯一识别码Universally Unique Identifier,它可以帮助 Linux 系统识别一个磁盘分区而不是块设备文件。自内核 2.15.1 起,libuuid 就是 util-linux-ng 包中的一部分,它被默认安装在 Linux 系统中。UUID 由该库生成,可以合理地认为在一个系统中 UUID 是唯一的,并且在所有系统中也是唯一的。这是在计算机系统中用来标识信息的一个 128 位(比特)的数字。UUID 最初被用在阿波罗网络计算机系统Apollo Network Computing System(NCS)中,之后 UUID 被开放软件基金会Open Software Foundation(OSF)标准化,成为分布式计算环境Distributed Computing Environment(DCE)的一部分。
UUID 以 32 个十六进制的数字表示,被连字符分割为 5 组显示,总共的 36 个字符的格式为 8-4-4-4-12(32 个字母或数字和 4 个连字符)。
例如: d92fa769-e00f-4fd7-b6ed-ecf7224af7fa
我的 /etc/fstab 文件示例:
# cat /etc/fstab # /etc/fstab: static file system information. # # Use 'blkid' to print the universally unique identifier for a device; this may # be used with UUID= as a more robust way to name devices that works even if # disks are added and removed. See fstab(5). # # UUID=69d9dd18-36be-4631-9ebb-78f05fe3217f / ext4 defaults,noatime 0 1 UUID=a2092b92-af29-4760-8e68-7a201922573b swap swap defaults,noatime 0 2
我们可以使用下面的 7 个命令来查看。
- blkid 命令:定位或打印块设备的属性。
- lsblk命令:列出所有可用的或指定的块设备的信息。
- hwinfo命令:硬件信息工具,是另外一个很好的实用工具,用于查询系统中已存在硬件。
- udevadm命令:udev 管理工具
- tune2fs命令:调整 ext2/ext3/ext4 文件系统上的可调文件系统参数。
- dumpe2fs 命令:查询 ext2/ext3/ext4 文件系统的信息。
- 使用 by-uuid 路径:该目录下包含有 UUID 和实际的块设备文件,UUID 与实际的块设备文件链接在一起。
Linux 中如何使用 blkid 命令查看磁盘分区或文件系统的 UUID?
blkid 是定位或打印块设备属性的命令行实用工具。它利用 libblkid 库在 Linux 系统中获得到磁盘分区的 UUID。
# blkid /dev/sda1: UUID="d92fa769-e00f-4fd7-b6ed-ecf7224af7fa" TYPE="ext4" PARTUUID="eab59449-01" /dev/sdc1: UUID="d17e3c31-e2c9-4f11-809c-94a549bc43b7" TYPE="ext2" PARTUUID="8cc8f9e5-01" /dev/sdc3: UUID="ca307aa4-0866-49b1-8184-004025789e63" TYPE="ext4" PARTUUID="8cc8f9e5-03" /dev/sdc5: PARTUUID="8cc8f9e5-05"
Linux 中如何使用 lsblk 命令查看磁盘分区或文件系统的 UUID?
lsblk 列出所有有关可用或指定块设备的信息。lsblk 命令读取 sysfs 文件系统和 udev 数据库以收集信息。
如果 udev 数据库不可用或者编译的 lsblk 不支持 udev,它会试图从块设备中读取卷标、UUID 和文件系统类型。这种情况下,必须以 root 身份运行。该命令默认会以类似于树的格式打印出所有的块设备(RAM 盘除外)。
# lsblk -o name,mountpoint,size,uuid NAME MOUNTPOINT SIZE UUID sda 30G └─sda1 / 20G d92fa769-e00f-4fd7-b6ed-ecf7224af7fa sdb 10G sdc 10G ├─sdc1 1G d17e3c31-e2c9-4f11-809c-94a549bc43b7 ├─sdc3 1G ca307aa4-0866-49b1-8184-004025789e63 ├─sdc4 1K └─sdc5 1G sdd 10G sde 10G sr0 1024M
Linux 中如何使用 by-uuid 路径查看磁盘分区或文件系统的 UUID?
该目录包含了 UUID 和实际的块设备文件,UUID 与实际的块设备文件链接在一起。
# ls -lh /dev/disk/by-uuid/ total 0 lrwxrwxrwx 1 root root 10 Jan 29 08:34 ca307aa4-0866-49b1-8184-004025789e63 -> ../../sdc3 lrwxrwxrwx 1 root root 10 Jan 29 08:34 d17e3c31-e2c9-4f11-809c-94a549bc43b7 -> ../../sdc1 lrwxrwxrwx 1 root root 10 Jan 29 08:34 d92fa769-e00f-4fd7-b6ed-ecf7224af7fa -> ../../sda1
Linux 中如何使用 hwinfo 命令查看磁盘分区或文件系统的 UUID?
hwinfo 意即硬件信息工具,是另外一种很好的实用工具。它被用来检测系统中已存在的硬件,并且以可读的格式显示各种硬件组件的细节信息。
# hwinfo --block | grep by-uuid | awk '{print $3,$7}' /dev/sdc1, /dev/disk/by-uuid/d17e3c31-e2c9-4f11-809c-94a549bc43b7 /dev/sdc3, /dev/disk/by-uuid/ca307aa4-0866-49b1-8184-004025789e63 /dev/sda1, /dev/disk/by-uuid/d92fa769-e00f-4fd7-b6ed-ecf7224af7fa
Linux 中如何使用 udevadm 命令查看磁盘分区或文件系统的 UUID?
udevadm 需要命令和命令特定的操作。它控制 systemd-udevd 的运行时行为,请求内核事件、管理事件队列并且提供简单的调试机制。
# udevadm info -q all -n /dev/sdc1 | grep -i by-uuid | head -1 S: disk/by-uuid/d17e3c31-e2c9-4f11-809c-94a549bc43b7
Linux 中如何使用 tune2fs 命令查看磁盘分区或文件系统的 UUID?
tune2fs 允许系统管理员在 Linux 的 ext2、ext3、ext4 文件系统中调整各种可调的文件系统参数。这些选项的当前值可以使用选项 -l 显示。
# tune2fs -l /dev/sdc1 | grep UUID Filesystem UUID: d17e3c31-e2c9-4f11-809c-94a549bc43b7
Linux 中如何使用 dumpe2fs 命令查看磁盘分区或文件系统的 UUID?
dumpe2fs 打印出现在设备文件系统中的超级块和块组的信息。
# dumpe2fs /dev/sdc1 | grep UUID dumpe2fs 1.43.5 (04-Aug-2017) Filesystem UUID: d17e3c31-e2c9-4f11-809c-94a549bc43b7
通过本文的阅读,我们已经了解到什么是UUID以及它在Linux系统中的作用和用途。UUID可以帮助我们更加方便地管理文件系统,而且不受文件系统挂载顺序或设备名称的影响。同时,我们也了解了如何查看和修改UUID,以及UUID与其他标识符的区别。希望本文对您有所帮助,让您更加熟练地管理Linux系统。
The above is the detailed content of Linux UUIDs: Unlocking the secrets of file system identification.. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The main reasons why you cannot log in to MySQL as root are permission problems, configuration file errors, password inconsistent, socket file problems, or firewall interception. The solution includes: check whether the bind-address parameter in the configuration file is configured correctly. Check whether the root user permissions have been modified or deleted and reset. Verify that the password is accurate, including case and special characters. Check socket file permission settings and paths. Check that the firewall blocks connections to the MySQL server.

The solution to MySQL installation error is: 1. Carefully check the system environment to ensure that the MySQL dependency library requirements are met. Different operating systems and version requirements are different; 2. Carefully read the error message and take corresponding measures according to prompts (such as missing library files or insufficient permissions), such as installing dependencies or using sudo commands; 3. If necessary, try to install the source code and carefully check the compilation log, but this requires a certain amount of Linux knowledge and experience. The key to ultimately solving the problem is to carefully check the system environment and error information, and refer to the official documents.

There are many reasons why MySQL startup fails, and it can be diagnosed by checking the error log. Common causes include port conflicts (check port occupancy and modify configuration), permission issues (check service running user permissions), configuration file errors (check parameter settings), data directory corruption (restore data or rebuild table space), InnoDB table space issues (check ibdata1 files), plug-in loading failure (check error log). When solving problems, you should analyze them based on the error log, find the root cause of the problem, and develop the habit of backing up data regularly to prevent and solve problems.

MySQL cannot run directly on Android, but it can be implemented indirectly by using the following methods: using the lightweight database SQLite, which is built on the Android system, does not require a separate server, and has a small resource usage, which is very suitable for mobile device applications. Remotely connect to the MySQL server and connect to the MySQL database on the remote server through the network for data reading and writing, but there are disadvantages such as strong network dependencies, security issues and server costs.

The main reasons for MySQL installation failure are: 1. Permission issues, you need to run as an administrator or use the sudo command; 2. Dependencies are missing, and you need to install relevant development packages; 3. Port conflicts, you need to close the program that occupies port 3306 or modify the configuration file; 4. The installation package is corrupt, you need to download and verify the integrity; 5. The environment variable is incorrectly configured, and the environment variables must be correctly configured according to the operating system. Solve these problems and carefully check each step to successfully install MySQL.

Unable to access MySQL from the terminal may be due to: MySQL service not running; connection command error; insufficient permissions; firewall blocks connection; MySQL configuration file error.

Effective monitoring of MySQL and MariaDB databases is critical to maintaining optimal performance, identifying potential bottlenecks, and ensuring overall system reliability. Prometheus MySQL Exporter is a powerful tool that provides detailed insights into database metrics that are critical for proactive management and troubleshooting.

MySQL installation failure is usually caused by the lack of dependencies. Solution: 1. Use system package manager (such as Linux apt, yum or dnf, Windows VisualC Redistributable) to install the missing dependency libraries, such as sudoaptinstalllibmysqlclient-dev; 2. Carefully check the error information and solve complex dependencies one by one; 3. Ensure that the package manager source is configured correctly and can access the network; 4. For Windows, download and install the necessary runtime libraries. Developing the habit of reading official documents and making good use of search engines can effectively solve problems.
