15
votes

I have EC2 instance with EBS volume attached, so that describe-instances command prints:

     "DeviceName": "/dev/sdf",
     "Ebs": {   "Status": "attached",
                "DeleteOnTermination": false,
                "VolumeId": "vol-04bfa2fab8e57a3dc",
                "AttachTime": "2016-09-26T09:39:08.000Z"   }

As per documentation:

Depending on the block device driver of the kernel, the device might be attached with a different name than what you specify

In my case actual name of this volume is /dev/xvdf.

Is it possible from within an instance to know which name was specified for a volume in Amazon console?

Or vice versa - to know which actual name will be used by linux for a volume outside an instance?

6

6 Answers

6
votes

This has been driving me nuts with Nitro-based instances, where the device names on the instance may not be ordered in the same sequence as shown in the AWS console. Luckily, per the AWS documentation, the serial number of the device on the instance is set to the EBS volume ID. So just run

lsblk -o +SERIAL

and it will give you the volume ID as shown in the console.

5
votes

It is being responded here

You are on a Xen VPS(or virtual machine); xvd* are simply the Xen disk storage devices (Xen Virtual block Device). They appear instead of sda, etc. when you are using the more efficient paravirtualized Xen disk drivers instead of straight-up SCSI disk emulation. If you list the installed modules (drivers) on a Xen HVM, this driver will show as blkfront (or xen_blk if you are running on a very old Xen version--pretty rare).

In short, treat xvda1 exactly as you would sda1 on a regular PC

Also mentioned in AWS docs

Depending on the block device driver of the kernel, the device might be attached with a different name than what you specify. For example, if you specify a device name of /dev/sdh, your device might be renamed /dev/xvdh or /dev/hdh by the kernel; in most cases, the trailing letter remains the same. In some versions of Red Hat Enterprise Linux (and its variants, such as CentOS), even the trailing letter might also change (where /dev/sda could become /dev/xvde). In these cases, each device name trailing letter is incremented the same number of times. For example, /dev/sdb would become /dev/xvdf and /dev/sdc would become /dev/xvdg. Amazon Linux AMIs create a symbolic link with the name you specify at launch that points to the renamed device path, but other AMIs might behave differently.

2
votes

From the AWS console you would never be able to know because this mapping is done by the OS. In Amazon AMI, it might have a different device but there is always a link from the original device you requested to the actual device on the system, So you can always use the DeviceName as an actual device. In RedHat it is different, but it is logical the order will be maintained.

1
votes

As defined in the aws documentation and hinted by @YairCarel the device driver mapping is OS specific.

But for one specific distribution it will always be the same. So if you know the linux distribution you are working on, you can calculate it back.

For example Amazon Linux will keep the name on the AWS console (or at least create a symlink to it). Ubuntu will use a different prefix /dev/xvd? instead of /dev/sd?. And the Redhat family will typically increment the trailing letter with a fixed offset, so /dev/xvdf is mapped on /dev/sdb.

1
votes

Use the Amazon-provided command to do just that:

$ sudo /sbin/ebsnvme-id /dev/nvme1n1
Volume ID: vol-031dbe1a58ac242cc
/dev/sdg

Looks like Windows also has it.

More details: https://medium.com/@ripon.banik/how-to-find-ebs-volume-id-for-nvme-volume-1148d7499dc

0
votes

Here is my bash script for creating proper symlinks for the EBS volumes on Ubuntu-18.04. It can be run inside UserData at startup time, so already presented in multiline format.

echo "--- Create symlinks ---"
disks=$(lsblk | grep "^nvme" | cut -d" " -f1)
for disk in $disks; \
do name=$(nvme id-ctrl --output binary /dev/$disk | cut -c3073-3104 | tr -d '\0'); \
    if [ -z "$name" ]; then name="xvdz"; fi; \
    ln -s /dev/$disk /dev/$name; \
done

echo "--- Mount SSD disk ---"
echo "/dev/sdz1 /opt/ephemeral ext4 errors=remount-ro 1 2" >> /etc/fstab
mkfs.ext4 /dev/xvdz

echo "--- Mount EBS disk created as xvdf ---"
echo "/dev/xvdf /opt/persist ext4 errors=remount-ro 1 2" >> /etc/fstab
mkfs.ext4 /dev/xvdf

mount -a

You have to install nvme-cli tool in order to work. Please pay attention to the special case of SSD type instance. There is no alias in nvme memory, so we define it as xvdz manually.

For all other EBS volumes it can be used an alias name defined in AWS console/CloudFormation/Terraform such as xvdf in this case

Reference