將磁碟連接至使用 Linux OS 的虛擬機器 (VM) 時,Google Cloud 會自動為磁碟建立符號連結 (symlink)。如要在 Linux VM 中存取永久磁碟磁碟區或本機 SSD 磁碟,請使用符號連結。這些符號連結可預測,且在重新啟動後仍保持一致。Google Cloud 會為 /dev/disk/by-id 中連結至 VM 的所有磁碟建立符號連結。
本文說明如何找出附加至 VM 的磁碟正確符號連結。
符號連結格式
磁碟連接至 VM 時 (無論是在 VM 建立期間或之後),系統會在 /dev/disk/by-id 中建立符號連結。符號連結名稱的建立方式如下:
Persistent Disk 和 Google Cloud Hyperdisk
系統會依據下列規則建立符號連結:
如果您在建立磁碟時指定了自訂裝置名稱:
google-DEVICE_NAME
如果您在建立磁碟時未指定自訂裝置名稱:
開機磁碟:
google-VM_NAME
非開機磁碟:
google-DISK_NAME
格式化磁碟後,符號連結會附加 -partN,其中 N 是分割區號碼,例如 google-data-disk-part1。
本機 SSD 磁碟
本機 SSD 符號連結的格式會因磁碟介面而異。
SCSI:
如果您在建立磁碟時指定了自訂裝置名稱:
google-DEVICE_NAME
如果您在建立磁碟時未指定自訂裝置名稱:google-local-ssd-N,其中 N 是本機 SSD 磁碟編號,從 0 開始。
NVMe:符號連結的名稱為 google-local-nvme-ssd-N,其中 N 是 SSD 編號,從 0 開始。
格式化本機 SSD 磁碟後,符號連結會附加 -partN,其中 N 是分割區編號,例如 google-local-nvme-ssd-0-part1。
在本範例中,Persistent Disk 開機磁碟符號連結為 google-instance-2,這是以 VM 名稱為準。開機磁碟已格式化,並安裝了 OS 映像檔。開機磁碟有 3 個分區:part1、part14 和 part 15。
第一個本機 SSD 磁碟也會分割成單一分區,因此會為該磁碟分區建立額外的符號連結。新增至 VM 的額外永久磁碟具有符號連結 google-extra-scsi-disk,這是以磁碟名稱為依據。額外的永久磁碟和第二個本機 SSD 磁碟未格式化,因此這些磁碟只會列出單一符號連結。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-04 (世界標準時間)。"],[[["\u003cp\u003eGoogle Cloud automatically generates symbolic links (symlinks) in \u003ccode\u003e/dev/disk/by-id\u003c/code\u003e for all disks attached to a Linux virtual machine (VM), ensuring consistent access across reboots.\u003c/p\u003e\n"],["\u003cp\u003eSymlinks for Persistent Disks use the format \u003ccode\u003egoogle-DEVICE_NAME\u003c/code\u003e, \u003ccode\u003egoogle-VM_NAME\u003c/code\u003e (boot disk), or \u003ccode\u003egoogle-DISK_NAME\u003c/code\u003e (non-boot disk), while Local SSD symlinks are named \u003ccode\u003egoogle-local-ssd-N\u003c/code\u003e (SCSI) or \u003ccode\u003egoogle-local-nvme-ssd-N\u003c/code\u003e (NVMe), where N is the disk number.\u003c/p\u003e\n"],["\u003cp\u003eAfter formatting, a \u003ccode\u003e-partN\u003c/code\u003e suffix is added to the symlink name to represent the partition number of the disk.\u003c/p\u003e\n"],["\u003cp\u003eSpecific Linux images like SLES 15 SP4/SP5 and SLES 12 SP4 on C3/C3D VMs might require extra steps to create user-friendly symlinks for Local SSD disks.\u003c/p\u003e\n"],["\u003cp\u003eYou can use device names like \u003ccode\u003e/dev/nvme0n1\u003c/code\u003e as an alternative to using symlinks to access Local SSD disks.\u003c/p\u003e\n"]]],[],null,["# Use symbolic links to access disks attached to a Linux VM\n\nLinux\n\n*** ** * ** ***\n\nWhen you attach a disk to a virtual machine (VM) that uses a Linux OS,\nGoogle Cloud automatically creates a symbolic link (symlink) for the disk. To\naccess Persistent Disk volumes or Local SSD disks in your Linux VM, use the\nsymlinks. These symlinks are predictable and remain consistent across reboots.\nGoogle Cloud creates symlinks for all disks attached to a VM in\n`/dev/disk/by-id`.\n\nThis document explains how to identify the correct symlinks for the disks\nattached to a VM.\n\nFormat of symbolic links\n------------------------\n\nSymlinks are created in `/dev/disk/by-id` when a disk is attached to the VM,\neither during or after VM creation. The symlink names are created as follows:\n\n**Persistent Disk and Google Cloud Hyperdisk**\n\nThe symlinks are created using the following rules:\n\n- If you specified a custom device name when you created the disk: `google-`\u003cvar translate=\"no\"\u003eDEVICE_NAME\u003c/var\u003e\n- If you didn't specify a custom device name when you created the disk:\n - Boot disk: `google-`\u003cvar translate=\"no\"\u003eVM_NAME\u003c/var\u003e\n - Non-boot disk: `google-`\u003cvar translate=\"no\"\u003eDISK_NAME\u003c/var\u003e\n\nAfter you format the disk, the symlink is appended with\n`-part`\u003cvar translate=\"no\"\u003eN\u003c/var\u003e, where \u003cvar translate=\"no\"\u003eN\u003c/var\u003e is the partition number,\nfor example `google-data-disk-part1`.\n\n**Local SSD disks**\n\nLocal SSD symlinks have different formats depending on the disk interface.\n\n- SCSI:\n - If you specified a custom device name when you created the disk: `google-`\u003cvar translate=\"no\"\u003eDEVICE_NAME\u003c/var\u003e\n - If you didn't specify a custom device name when you created the disk: `google-local-ssd-`\u003cvar translate=\"no\"\u003eN\u003c/var\u003e, where \u003cvar translate=\"no\"\u003eN\u003c/var\u003e is the Local SSD disk number, starting from 0.\n- NVMe: The symlinks are named `google-local-nvme-ssd-`\u003cvar translate=\"no\"\u003eN\u003c/var\u003e, where \u003cvar translate=\"no\"\u003eN\u003c/var\u003e is the SSD number, starting from 0.\n\nAfter you format a Local SSD disk, the symlink is appended with\n`-part`\u003cvar translate=\"no\"\u003eN\u003c/var\u003e, where \u003cvar translate=\"no\"\u003eN\u003c/var\u003e is the partition number,\nfor example, `google-local-nvme-ssd-0-part1`.\n\n**Device symlinks**\n\nCompute Engine creates additional symlinks in the directory based on the disk\ntype and interface, for example `scsi-0Google_PersistentDisk_`\u003cvar translate=\"no\"\u003eDEVICE_NAME\u003c/var\u003e.\nThese links perform the same function as the symlinks mentioned previously.\n\n**Example 1: C3 VM with attached Local SSD**\n\nAssume you created a VM with the following properties:\n\n- VM name: `instance-1`\n- Machine series: C3\n- Disk interface type: NVMe for both Persistent Disk and Local SSD\n- Additional disks: none\n- Attached Local SSD disks: 2\n- Custom device names used: none\n\nCompute Engine creates the following symlinks for that VM: \n\n ls -l /dev/disk/by-id/google-*\n\n google-instance-1 -\u003e ../../nvme2n1\n google-instance-1-part1 -\u003e ../../nvme2n1p1\n google-instance-1-part14 -\u003e ../../nvme2n1p14\n google-instance-1-part15 -\u003e ../../nvme2n1p15\n google-local-nvme-ssd-0 -\u003e ../../nvme0n1\n google-local-nvme-ssd-1 -\u003e ../../nvme1n1\n\nIn this example, the Persistent Disk boot disk symlink is `google-instance-1`, which\nis based on the VM name. The boot disk is formatted and has the operating system\ninstalled on it. The boot disk has 3 partitions: part1, part14, and part 15.\nThe attached Local SSD disks are not formatted, so\nonly a single symlink was created for each Local SSD disk.\n\n**Example 2: N2 VM with attached NVMe Local SSD and extra Persistent Disk**\n\nAssume you created a VM with the following properties:\n\n- VM name: `instance-2`\n- Machine series: N2\n- Disk interface type: SCSI for Persistent Disk and NVMe for Local SSD\n- Additional disks: 1 Persistent Disk named `extra-scsi-disk`\n- Attached Local SSD disks: 2\n- Custom device names used: none\n\nThe following symlinks are created for that VM: \n\n ls -l /dev/disk/by-id/google-*\n\n google-extra-scsi-disk -\u003e ../../sdb\n google-instance-2 -\u003e ../../sda\n google-instance-2-part1 -\u003e ../../sda1\n google-instance-2-part14 -\u003e ../../sda14\n google-instance-2-part15 -\u003e ../../sda15\n google-local-nvme-ssd-0 -\u003e ../../nvme0n1\n google-local-nvme-ssd-0-part1 -\u003e ../../nvme0n1p1\n google-local-nvme-ssd-1 -\u003e ../../nvme0n2\n\nIn this example, the Persistent Disk boot disk symlink is `google-instance-2`, which\nis based on the VM name. The boot disk is formatted and has the OS image\ninstalled on it. The boot disk has 3 partitions: part1, part14, and part 15.\nThe first Local SSD disk is also partitioned, with a single partition, so\nthere is an additional symlink created for that disk partition.\nThe additional Persistent Disk added to the VM has the\nsymlink `google-extra-scsi-disk`, which is based the disk name. The extra\nPersistent Disk and second Local SSD disk are not formatted,\nso only a single symlink is listed for those disks.\n\nWhat's next\n-----------\n\n- Learn how to [use persistent device names](/compute/docs/disks/set-persistent-device-name-in-linux-vm).\n- Format and mount your new disks on [Linux](/compute/docs/disks/format-mount-disk-linux) or [Windows](/compute/docs/disks/format-mount-disk-windows) VMs.\n- Learn how to [benchmark Persistent Disk performance](/compute/docs/disks/benchmarking-pd-performance)."]]