通过 UUID 查找卷

发布于 2024-08-22 13:24:41 字数 140 浏览 6 评论 0原文

我知道卷的 UUID - 可在“磁盘工具”中找到。

如何获取有关该卷的更多信息? 最重要的是,我想知道它的挂载点。

查看 /etc/fstab 并不能解决问题。这不会列出根卷。我至少需要找出根卷的 UUID 来验证我已知的 UUID。

I know the UUID of a volume - as found in Disk Utility.

How can I get additional information on the volume?
Most importantly, I want to know its mount point.

Looking at /etc/fstab doesn't do the trick. This does not list the root volume. I would at least need to figure out the UUID of the root volume to verify my known UUID against it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱的十字路口 2024-08-29 13:24:41

您可以使用 diskutil通过 UUID 查找磁盘,并使用 -plist 选项以机器可解析的格式获取输出:

% diskutil info /Volumes/RAM\ Disk | grep -F UUID
   Volume UUID:              EA20BE94-5F3C-3C02-901D-A213B5AB6831

% diskutil info -plist EA20BE94-5F3C-3C02-901D-A213B5AB6831
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <!--snip-->
    <key>MountPoint</key>
    <string>/Volumes/RAM Disk</string>
    <!--snip-->
</dict>
</plist>

您可以使用 NSTask 和 NSPipe 从程序中运行 diskutil 并捕获输出。

附录:并非所有卷都有 UUID。我的相机有一个内置的只读 MS-DOS 格式卷,根据磁盘工具和 diskutil,该卷没有 UUID。因此,请确保您的程序可以处理上述 diskutil info 的空输出... | grep 管道。

You can use diskutil to look up the disk by its UUID, and the -plist option to get the output in a machine-parseable format:

% diskutil info /Volumes/RAM\ Disk | grep -F UUID
   Volume UUID:              EA20BE94-5F3C-3C02-901D-A213B5AB6831

% diskutil info -plist EA20BE94-5F3C-3C02-901D-A213B5AB6831
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <!--snip-->
    <key>MountPoint</key>
    <string>/Volumes/RAM Disk</string>
    <!--snip-->
</dict>
</plist>

You can use NSTask and NSPipe to run diskutil from within your program and capture the output.

Addendum: Not all volumes have UUIDs. My camera has a built-in read-only MS-DOS-formatted volume that has no UUID according to Disk Utility and diskutil. So, make sure your program can handle empty output from the above diskutil info … | grep pipeline.

稀香 2024-08-29 13:24:41

有几种方法可以做到这一点。如果您想要系统中所有 UUID 的列表,通常可以查看 /dev/disk/by-uuid/ 。

此文件夹包含将 uuid 映射到设备位置的符号链接。在我的系统上,它映射如下:

[sean@vladimir ~]$ ls -al /dev/disk/by-uuid/
total 0
drwxr-xr-x 2 root root 300 2010-02-02 22:42 .
drwxr-xr-x 6 root root 120 2010-02-02 22:42 ..
lrwxrwxrwx 1 root root  10 2010-02-02 22:42 02123883-6538-4c74-bc74-362eb2588d2b -> ../../sdc4
lrwxrwxrwx 1 root root  10 2010-02-02 22:42 1ce37cd8-52b0-4442-98b5-3702194644f2 -> ../../dm-5
lrwxrwxrwx 1 root root  10 2010-02-02 22:42 1d718419-8175-446c-a01b-51e895d59467 -> ../../sdc7
lrwxrwxrwx 1 root root  10 2010-02-02 22:42 382a64d7-68fe-45a3-87d3-ae7b7a861067 -> ../../dm-1
lrwxrwxrwx 1 root root  10 2010-02-02 22:42 47ab8e51-4023-4bec-a888-576879fba2dd -> ../../sdc1
lrwxrwxrwx 1 root root  10 2010-02-02 22:42 5b4e6b94-f7c7-40c1-a4ee-ca555efc97df -> ../../dm-4
lrwxrwxrwx 1 root root  10 2010-02-02 22:42 6d1df3de-b408-4942-a2e3-78244a68cece -> ../../dm-0
lrwxrwxrwx 1 root root  10 2010-02-02 22:42 c7f841db-8b38-403e-9bcc-926c18deadfc -> ../../sdc6
lrwxrwxrwx 1 root root  10 2010-02-02 22:42 db3f2c47-e29d-4b33-a462-6230ed2bcea8 -> ../../dm-2
lrwxrwxrwx 1 root root  10 2010-02-02 22:42 e5bd9df3-65f7-4815-839f-8b5fad82bc50 -> ../../sdc5
lrwxrwxrwx 1 root root  10 2010-02-02 22:42 ea28833b-fa7b-465d-992b-c333b288233b -> ../../sda1
lrwxrwxrwx 1 root root  10 2010-02-02 22:42 ebb72c56-8776-4e7d-ace9-fc727239f999 -> ../../sda2
lrwxrwxrwx 1 root root  10 2010-02-02 22:42 fd75f53b-6058-467b-9e0f-0a725e7bc83e -> ../../dm-3

或者,您可以为每个设备运行“blkid /path/to/dev”,以查找您要查找的设备。同样,在我的系统上它显示为:

[sean@vladimir ~]$ blkid /dev/sda1
/dev/sda1: LABEL="restore" UUID="ea28833b-fa7b-465d-992b-c333b288233b" TYPE="ext4" 

希望有帮助。

There are a couple of ways you can do it. If you want a list of all the UUIDs in your system you can typically look at /dev/disk/by-uuid/ .

This folder contains a symbolic link mapping uuids to device locations. On my system it maps as the following:

[sean@vladimir ~]$ ls -al /dev/disk/by-uuid/
total 0
drwxr-xr-x 2 root root 300 2010-02-02 22:42 .
drwxr-xr-x 6 root root 120 2010-02-02 22:42 ..
lrwxrwxrwx 1 root root  10 2010-02-02 22:42 02123883-6538-4c74-bc74-362eb2588d2b -> ../../sdc4
lrwxrwxrwx 1 root root  10 2010-02-02 22:42 1ce37cd8-52b0-4442-98b5-3702194644f2 -> ../../dm-5
lrwxrwxrwx 1 root root  10 2010-02-02 22:42 1d718419-8175-446c-a01b-51e895d59467 -> ../../sdc7
lrwxrwxrwx 1 root root  10 2010-02-02 22:42 382a64d7-68fe-45a3-87d3-ae7b7a861067 -> ../../dm-1
lrwxrwxrwx 1 root root  10 2010-02-02 22:42 47ab8e51-4023-4bec-a888-576879fba2dd -> ../../sdc1
lrwxrwxrwx 1 root root  10 2010-02-02 22:42 5b4e6b94-f7c7-40c1-a4ee-ca555efc97df -> ../../dm-4
lrwxrwxrwx 1 root root  10 2010-02-02 22:42 6d1df3de-b408-4942-a2e3-78244a68cece -> ../../dm-0
lrwxrwxrwx 1 root root  10 2010-02-02 22:42 c7f841db-8b38-403e-9bcc-926c18deadfc -> ../../sdc6
lrwxrwxrwx 1 root root  10 2010-02-02 22:42 db3f2c47-e29d-4b33-a462-6230ed2bcea8 -> ../../dm-2
lrwxrwxrwx 1 root root  10 2010-02-02 22:42 e5bd9df3-65f7-4815-839f-8b5fad82bc50 -> ../../sdc5
lrwxrwxrwx 1 root root  10 2010-02-02 22:42 ea28833b-fa7b-465d-992b-c333b288233b -> ../../sda1
lrwxrwxrwx 1 root root  10 2010-02-02 22:42 ebb72c56-8776-4e7d-ace9-fc727239f999 -> ../../sda2
lrwxrwxrwx 1 root root  10 2010-02-02 22:42 fd75f53b-6058-467b-9e0f-0a725e7bc83e -> ../../dm-3

Alternatively, you can run 'blkid /path/to/dev ' for each of your devices to find which is the one you are looking for. Likewise, on my system it appears as such:

[sean@vladimir ~]$ blkid /dev/sda1
/dev/sda1: LABEL="restore" UUID="ea28833b-fa7b-465d-992b-c333b288233b" TYPE="ext4" 

Hope that helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文