38

I just attached another ebs volume to running instance. But how do I access the volume? I can't find the /dev/sda directory anywhere. Where should I look?

Maca
  • 1,043
  • 2
  • 19
  • 30

2 Answers2

42

When you attach an EBS volume, you specify the device to attach it as. Under linux, these devices are /dev/xvd* - and are symlinked to /dev/sd*

In the AWS console, you can see your EBS volumes, what instances they are attached to, and the device each volume is attached as:

AWS Console

You can achieve the same thing from the CLI tools. Set the necessary environment variables:

export EC2_PRIVATE_KEY=/root/pk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.pem 
export EC2_CERT=/root/cert-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.pem

Run the command on your current instance (otherwise, just specify the instance-id):

ec2-describe-instances `curl -s http://169.254.169.254/latest/meta-data/instance-id` | grep BLOCKDEVICE

BLOCKDEVICE     /dev/sda1       vol-xxxxxxxx    2011-11-13T21:09:53.000Z
BLOCKDEVICE     /dev/sdf        vol-xxxxxxxx    2011-11-13T21:09:53.000Z
BLOCKDEVICE     /dev/sdg        vol-xxxxxxxx    2011-11-13T21:09:53.000Z

It is worth noting that in both cases above - the CLI and the AWS Console - the devices are described as being attached at /dev/sd* - this is not actually the case, however.

Look at the contents of /dev:

ls -l /dev/sd* /dev/xv*
lrwxrwxrwx 1 root root       5 Dec 12 18:32 /dev/sda1 -> xvda1
lrwxrwxrwx 1 root root       4 Dec 12 18:32 /dev/sdf -> xvdf
lrwxrwxrwx 1 root root       4 Dec 12 18:32 /dev/sdg -> xvdg
brw-rw---- 1 root disk 202,  1 Dec 12 18:32 /dev/xvda1
brw-rw---- 1 root disk 202, 80 Dec 12 18:32 /dev/xvdf
brw-rw---- 1 root disk 202, 96 Dec 12 18:32 /dev/xvdg

The devices are actually /dev/xvd* - and the /dev/sd* paths are symlinks.

Another approach to check for the currently available devices is to use fdisk -l, or for a simpler output:

cat /proc/partitions
major minor  #blocks  name

 202        1    4194304 xvda1
 202       80    6291456 xvdf
 202       96    1048576 xvdg

If you need to determine which devices have been mounted use mount and df - and check /etc/fstab to change the mount options.

cyberx86
  • 20,620
  • 1
  • 60
  • 80
  • 1
    Saved my butt. They really need to update those docs. – MBHNYC Dec 16 '13 at 19:54
  • 9
    FWIW, on recent releases of Xen virtualized Ubuntu instances, the xvd* devices are not symlinked to sd* – cbare Jun 02 '14 at 23:09
  • 1
    @cbare Can you confirm. When I go into my console I see it a 15 gig volume attached as /dev/sda1. But when I go into my server, the only thing I see is /dev/xvda1. There is no /dev/sd* at all! Also /dev/xvda1 is shown to be 32 gigs with 25 gigs used up. Can I be certain that these 2 are the same volumes? – CMCDragonkai Jan 30 '15 at 12:42
  • @CMCDragonkai, Not sure why you'd see different sizes but the xvd_ devices (Xen Virtual Device, I'm guessing) are mapped through the virtualization layer to the equivalently named sd_ device. See: http://askubuntu.com/questions/166083/what-is-the-dev-xvda1-device – cbare Feb 06 '15 at 22:09
  • @CMCDragonkai, This [page](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/block-device-mapping-concepts.html) says, "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)." – cbare Feb 06 '15 at 22:14
  • 4
    How come in my server the symlink doesn't exist? Could I create my own symlink to make sure sda1 links to xvda1? The EC2 interface says sda1, but the actual device is xvda1, but with no symlink currently. – CMCDragonkai Mar 01 '15 at 12:27
  • This needs updating. The device you choose when attaching a volume is no longer the device to which the volume is attached. – Kevin Buchs Mar 28 '18 at 13:41
15

To use a EBS volume attached in the EC2, you need first mount the volume.

  1. Connect to your instance using SSH.
  2. Use the lsblk command to view your available disk devices and their mount points.

[ec2-user@ip-172-31-86-46 ~]$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda 202:0 0 8G 0 disk
└─xvda1 202:1 0 8G 0 part /
xvdb 202:16 0 8G 0 disk
xvdf 202:80 0 100G 0 disk

  1. create a file system on the volume, example -> sudo mkfs -t ext4 /dev/xvdf
  2. create a mount point directoty for the volume ->sudo mkdir mount_point
  3. To mount this EBS volume at the location you just created -> sudo mount /dev/xvdf mount_point
  4. To check you can perform ls mount_point

    https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-using-volumes.html
Renato Coutinho
  • 251
  • 2
  • 3