140

I'm having problem connecting EBS volume to my Ubuntu EC2 Instance.

Here's what I did:

  1. From the Amazon AWS Console, I created a EBS 150GB volume and attached it to an Ubuntu 11.10 EC2 instance. Under the EBS volume properties, "Attachment" shows: "[my Ubuntu instance id]:/dev/sdf (attached)"

  2. Tried mounting the drive on the Ubuntu box, and it told me "mount: /dev/sdf is not a block device"

    sudo mount /dev/sdf /vol

  3. So I checked with fdisk and tried to mount from the new location and it told me it wasn't the right file system.

    sudo fdisk -l

    sudo mount -v -t ext4 /dev/xvdf /vol

    the error:

    mount: wrong fs type, bad option, bad superblock on /dev/xvdf, missing codepage or helper program, or other error In some cases useful info is found in syslog - try dmesg | tail or so

    "dmesg | tail" told me it gave the following error:

    EXT4-fs (sda1): VFS: Can't find ext4 filesystem

I also tried putting the configurations into /etc/fstab file as instructed on http://www.webmastersessions.com/how-to-attach-ebs-volume-to-amazon-ec2-instance, but still gave same not the right file system error.

Questions:

Q1: Based on point 1 (above), why was the volume mapped to 'dev/sdf' when it's really mapped to '/dev/xvdf'?

Q2: What else do I need to do to get the EBS volume loaded? I thought it'll just take care of everything for me when I attach it to a instance.

Steffen Opel
  • 61,065
  • 11
  • 183
  • 208
JackDev
  • 10,244
  • 11
  • 45
  • 66
  • This may belong on a sysadmin-oriented StackExchange site. Nevertheless exactly what I needed to find. Thank you for asking this! – pcurry Aug 08 '14 at 01:09

2 Answers2

326

Since this is a new volume, you need to format the EBS volume (block device) with a file system between step 1 and step 2. So the entire process with your sample mount point is:

  1. Create EBS volume.

  2. Attach EBS volume to /dev/sdf (EC2's external name for this particular device number).

  3. Format file system /dev/xvdf (Ubuntu's internal name for this particular device number):

    sudo mkfs.ext4 /dev/xvdf
    

    Only format the file system if this is a new volume with no data on it. Formatting will make it difficult or impossible to retrieve any data that was on this volume previously.

  4. Mount file system (with update to /etc/fstab so it stays mounted on reboot):

    sudo mkdir -m 000 /vol
    echo "/dev/xvdf /vol auto noatime 0 0" | sudo tee -a /etc/fstab
    sudo mount /vol
    
Eric Hammond
  • 21,255
  • 5
  • 62
  • 72
  • 3
    Just to be explicit, /dev/xvdf doesn't exist prior to your mounting /dev/sdf. – Dror Oct 21 '12 at 19:22
  • @Dror: "mount" is a specific technical term that relates to step 4 and is only done with /dev/xvdf, the internal Ubuntu name for the device. The /dev/sdf name is EC2's external name for this device and you must "attach" the EBS volume at that location (step 2) before you can format and mount it. – Eric Hammond Oct 21 '12 at 20:33
  • You're correct. The EBS attach is done externally, by AWS and is equivalent to attaching a USB device to a computer. The mount command is a linux/unix command that only works on formated file systems and connects the device /dev/xxx with the location in the file system e.g. /mnt. – Dror Oct 22 '12 at 20:01
  • 2
    Thanks a lot for this! I was totally confused by the /mnt directory and wrongly assumed that my extra EBS volume (/dev/xvdf) that I told AWS to attach at instance creation was already mounted. Also, the mapping between what AWS shows (/dev/sdf) and (/dev/xvdf) that exists on ubuntu tripped me up. – ankimal Nov 08 '12 at 19:19
  • @Dror @ankimal or @EricHammond - I followed the exact instructions here. However when I `cd` into `/vol` (or whatever I named it) I'm not getting the full size of the partition, and there is a strange folder called `lost+found` in there. Know how I can get around this? – Brandon Dec 23 '12 at 09:42
  • 1
    @Brandon: Please ask this as a new question on serverfault.com providing all the details of what you did instead of tacking it in a comment. – Eric Hammond Dec 24 '12 at 00:13
  • Unfortunately these are definitely not the right steps. EBS I have mounted actually has a public dataset on it and mkfs.ext4 will go and erase it. These things make sense if EBS was empty. – Prashant Sharma Dec 28 '12 at 11:25
  • 7
    @scrapcodes: Fortunately, these are definitely the right steps for the original poster's question (new, unformatted EBS volume). They certainly may not be the right steps if you have a completely different situation (EBS volume created from snapshot containing existing filesystem). – Eric Hammond Jan 09 '13 at 02:58
  • I agree, There is no solution actually, if filesystem is not detected automatically. Original question does not say anything about new drive. – Prashant Sharma Jan 15 '13 at 09:57
  • 10
    Why does step four include the flag `-m 000`? – Joe Mornin Mar 11 '13 at 02:55
  • 25
    @JosephMornin Turning off all bits in the mode is a simple indicator that nobody should be allowed to do anything in this directory until a new file system is mounted here. It's a message that this directory has been created as a mount point. It is not required for functionality, but sometimes avoids the mistakes of creating files when the desired volume is not mounted. – Eric Hammond Mar 12 '13 at 15:40
  • I have stopped an ec2 instance and after restart it the attached ebs volume is empty. I am facing the same problem for mounting it. Any idea? – Alexandre Rademaker Mar 15 '13 at 13:12
  • @AlexandreRademaker: Comment threads are not the best place for new questions. Try creating a new question with all the details on serverfault.com – Eric Hammond Mar 15 '13 at 16:29
  • @EricHammond: just connect this answer to this blog: http://alestic.com/2010/02/ec2-resize-running-ebs-root. thanks man! – Dmitry Minkovsky May 10 '13 at 20:17
-4

Step 1: create volume
step 2: attach to your instance root volume
step 3: run sudo resize 2fs -p /dev/xvde
step 4: restart apache2 sudo service apache2 restart
step 4: run df -h

You can see total volume attached to your instance.

Ramesh Sinha
  • 63
  • 1
  • 1