Best practice: Use persistent device names on a Linux VM

Linux

This document describes how to use persistent device naming on your Linux VM.

For VMs that use a Linux operating system, device names, for example/dev/sda,might change after you perform procedures such as the following:

  • Starting and stopping a VM
  • Detaching and reattaching disks
  • Changing machine types

This device name change occurs because device names are assigned from anavailable range once a VM starts or a device is attached. Detaching a device orstopping the VM frees up the device name. When the device is reattached or theVM restarted a new device name is then assigned from the available range. TheLinux kernel does not guarantee device ordering across reboots.

A device name change might cause any applications or scripts that depend onthe original device name to not work properly or it might cause the VM to notboot after a restart.

It is recommended that you use persistent device naming when referencing disksand partitions on your Linux VMs to avoid this issue. You can also usesymlinks.

Before you begin

Device naming on Linux VMs

The Linux device names for the disks attached to your VM depend on the interfacethat you choose when creating the disks. When you use thelsblk operatingsystem command to view your disk devices, it displays the prefixnvme fordisks attached with the NVMe interface, and the prefixsd for disks attachedwith the SCSI interface.

The ordering of the disk numbers or NVMe controllers is not predictable orconsistent across VMs restarts. On the first boot, a persistent disk might benvme0n1 (orsda for SCSI). On the second boot, the device name for the samepersistent disk might benvme2n1 ornvme0n3 (orsdc for SCSI).

When accessing attached disks, you should use the symbolic links created in/dev/disk/by-id/ instead. These names persist across reboots.For more information about symlinks, seeSymbolic links for disks attached to a VM.

SCSI device names

The format of a SCSI-attached disk device issda for the first attached disk.The disk partitions appear assda1. Each additional diskuses a sequential letter, such assdb andsdc. Whensdz isreached, the next disks added have the names such assdaa,sdab, andsdac,up tosddx.

NVMe device names

The format of a NVMe-attached disk device in Linux operating systems isnvmenumbernnamespace. Thenumber represents the NVMe disk controller number andnamespace is an NVMe namespace ID that is assigned by the NVMe diskcontroller. For partitions, pn is appended to the device name,wheren is a number, starting with 1, that denotes thenth partition.

The controller number starts at0. A single NVMe disk attached to your computeinstance has a device name ofnvme0n1. Most machine types use a single NVMedisk controller. The NVMe device names are thennvme0n1,nvme0n2,nvme0n3,and so on.

Local SSD disks attached tothird generation machine seriesor later instances have a separate NVMe controller for each disk. On these VMs,the Local SSD NVMe-attached device names look likenvme0n1,nvme1n1, andnvme2n1. The number of attached Local SSD disks depends on the machine typeof your VM.

Compute instances based on third generation machine series or later use NVMe forboth Persistent Disk and Google Cloud Hyperdisk, and also Local SSD disks. Each VMhas 1 NVMe controller for Persistent Disk and Hyperdisk and 1 NVMecontroller for each Local SSD disk. The Persistent Disk and HyperdiskNVMe controller has a single NVMe namespace for all attached disks. So, a thirdgeneration machine series instance with one Persistent Disk and oneHyperdisk (each with 2 partitions), and 2 unformatted Local SSDdisks uses the following device names:

  • nvme0n1 - Persistent Disk
  • nvme0n1p1
  • nvme0n1p2
  • nvme0n2 - Hyperdisk
  • nvme0n2p1
  • nvme0n2p2
  • nvme1n1 - first Local SSD
  • nvme2n1 - second Local SSD

Use persistent device naming

To configure a persistent device name, you assign a mount point name for thedisk device in thefstab file. There are three ways to configure a persistentdevice name.

  • By using alabel.This option requires that the file system supports labels and that you add alabel to the disk partitions.
  • By using a partition or diskUUID.A UUID is generated when a disk is created with a partition table, and theUUID is unique per partition.
  • By using a persistent disk ID (/dev/disk/by-id) for Persistent Disk orGoogle Cloud Hyperdisk, or asymlink, thatis based on the disk resource name.

We recommend using the partition UUID or the symlink for Linux VMs.

Partition UUID

To find the UUID for a disk, perform the following steps:

  1. Connect to your VM.
  2. If you don't know the device name for the disk, you can find thedisk device name using the symlink.

    ls -l /dev/disk/by-id/google-*

    The output is similar to the following:

      lrwxrwxrwx 1 root root  9 Oct 23 15:58 /dev/disk/by-id/google-my-vm -> ../../sda  lrwxrwxrwx 1 root root 10 Oct 23 15:58 /dev/disk/by-id/google-my-vm-part1 -> ../../sda1  lrwxrwxrwx 1 root root 11 Oct 23 15:58 /dev/disk/by-id/google-my-vm-part15 -> ../../sda15  lrwxrwxrwx 1 root root  9 Oct 23 15:58 /dev/disk/by-id/google-my-vm-app-data -> ../../nvme0n1

  3. Retrieve the UUID of the partition for the disk by running one of thefollowing commands:

    • blkid

      sudo  blkid -s UUID

      The output is similar to the following:

      /dev/sda1: UUID="4f570f2d-fffe-4c7d-8d8f-af347af7612a"/dev/sda15: UUID="E0B2-DFAF"/dev/nvme0n1: UUID="9e617251-6a92-45ff-ba40-700a9bdeb03e"
    • ls -l

      sudo ls -l /dev/disk/by-uuid/

      The output is similar to the following:

      lrwxrwxrwx 1 root root 10 Sep 22 18:12 4f570f2d-fffe-4c7d-8d8f-af347af7612a -> ../../sda1lrwxrwxrwx 1 root root 13 Sep 22 18:15 9e617251-6a92-45ff-ba40-700a9bdeb03e -> ../../nvme0n1lrwxrwxrwx 1 root root 11 Sep 22 18:12 E0B2-DFAF -> ../../sda15
  4. Add an entry for the UUID for your device in the/etc/fstab file.

    UUID=9e617251-6a92-45ff-ba40-700a9bdeb03e /data ext4 defaults 0 0

    In this example,/data is the mount point andext4 is the file system type.

  5. Validate that the device is mounted properly by runningmount -av.

    sudo mount -av

    If the device is successfully mounted, the output is similar to thefollowing:

    /                           : ignored/boot/efi                : already mountedmount: /data does not contain SELinux labels.You just mounted an file system that supports labels which does notcontain labels, onto an SELinux box. It is likely that confineapplications will generate AVC messages and not be allowed access tothis filesystem.  For more details see restorecon(8) and mount(8)./data                    : successfully mounted

Persistent disk ID

To find the disk device name by using the persistent disk ID, or symlink,complete the following steps:

  1. Connect to your VM.
  2. Retrieve the ID on the disk by running the following command:

    sudo  ls -lh /dev/disk/by-id/google-*

    The output is similar to the following:

    lrwxrwxrwx. 1 root root  9 May 16 17:34 google-disk-2 -> ../../sdblrwxrwxrwx. 1 root root  9 May 16 09:09 google-persistent-disk-0 -> ../../sdalrwxrwxrwx. 1 root root 10 May 16 09:09 google-persistent-disk-0-part1 -> ../../sda1lrwxrwxrwx. 1 root root 10 May 16 09:09 google-persistent-disk-0-part2 -> ../../sda2

    ForNVME disks, the output is similar to the following:

    lrwxrwxrwx 1 root root 13 Jun  1 10:27 google-disk-3 -> ../../nvme0n2lrwxrwxrwx 1 root root 13 Jun  1 10:25 google-t2a -> ../../nvme0n1lrwxrwxrwx 1 root root 15 Jun  1 10:25 google-t2a-part1 -> ../../nvme0n1p1lrwxrwxrwx 1 root root 16 Jun  1 10:25 google-t2a-part15 -> ../../nvme0n1p15
  3. Add the symlink to the/etc/fstab file.

    /dev/disk/by-id/google-disk-2 /data ext4 defaults 0 0
    Note: In this example,/datais the mount point andext4 is the file system type.
  4. Validate that the device is mounted properly by runningmount -av.

    sudo mount -av

    If the device is successfully mounted, the output is similar to thefollowing:

    /                           : ignored/boot/efi                : already mountedmount: /data does not contain SELinux labels.You just mounted an file system that supports labels which doesnot contain labels, onto an SELinux box. It is likely that confineapplications will generate AVC messages and not be allowed access to thisfile system.  For more details see restorecon(8) and mount(8)./data                    : successfully mounted

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-07-09 UTC.