21

According to AWS I got 850 GB storage with the Medium EC2 server. But when i create an Amazon Linux AMI, I am unable to use the 850 GB provided.

While creating it does show in Storage Device Configuration in Instance Store Volumes that its device will be located at /dev/sdb , but when I start the VM , I just find /dev/sda1.

Can you please help me in mounting this storage? Thank You

Also, when Amazon claims that instance storage is not safe for long term use and should prefer using EBS, then what is the point of those 850 GB?

Thanks

rahulg
  • 407
  • 1
  • 4
  • 10
  • What specific instance type are you trying to run? c1.medium? m1.medium? something else? – Eric Hammond Oct 01 '12 at 23:34
  • 1
    Here are two great resources for learning about instance storage on EC2: http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/InstanceStorage.html and http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/instance-types.html – Eric Hammond Oct 01 '12 at 23:56

4 Answers4

32

If it's not already mounted under e.g. /mnt and if it doesn't have a filesystem created already then do:

  1. Check the device name

    sudo fdisk -l

  2. Make directory to where you want to mount the volume

    sudo mkdir /mnt

  3. Create filesystem on your volume (make sure you choose the correct volume because this creates a new file system on the volume)

    sudo mkfs.ext4 /dev/xvdj

  4. Mount volume

    sudo mount -t ext4 /dev/xvdj /mnt

  5. If you want to preserve the mount after e.g. a restart, open /etc/fstab and add the mount to it

    echo "/dev/xvdj /mnt auto noatime 0 0" | sudo tee -a /etc/fstab

  6. Make sure nothing is wrong with fstab by mounting all

    mount -a

horte
  • 471
  • 1
  • 3
  • 3
  • 5
    Depending on the instance type, you first need to attach the instance store volumes to the instance by using the block-device-mapping options. If you don't do this, you may not even see the devices under /dev – Eric Hammond Oct 01 '12 at 23:32
  • @EricHammond's comment was really the answer to my quest - I didn't see them anywhere - even in `fdisk -l` – Peter V. Mørch Nov 24 '14 at 23:45
  • If you don't see the device try using `lsblk`. – volker238 Oct 17 '16 at 17:55
  • These instructions mount the volume for me, but trying to write a new file to the volume gives "access denied". I can't sort out what's wrong with the permissions. Any ideas? – MikeB Dec 22 '18 at 15:38
  • 1
    `lsblk -f` is the best way to find disk volumes - any volumes that are mounted will be shown with the mount path, and it shows the labels for volumes (recommended to use UUIDs or labels when mounting filesystems on Linux). – RichVel Feb 19 '19 at 06:05
11

The use of instance-local storage that is not persistent when an instance is stopped is pretty simple: It's a very large chunk of space useful for transient things. They're the perfect target for mounting to /tmp, and is extremely useful if your server handles very large files transiently.

For example, if you were building a group of instances to do voice-to-text translation of uploaded video-files, instance-local storage would be just the thing you want to put the in-process files on. It may be there for a few hours while the file is processed, but once it's done it can be deleted and another one taken up. You don't need EBS for that, and it's a lot cheaper to run that kind of storage out of instance-local rather than EBS.

Instance-local storage is meant to be used as scratch-space for running processing, not long-term storage. If your workload doesn't use scratch-space for anything, or what it needs is so small as to not be significant, then it isn't a good fit for you.

Gray
  • 569
  • 1
  • 5
  • 17
sysadmin1138
  • 131,083
  • 18
  • 173
  • 296
  • 20
    Ephemeral storage or instance-store DOES persist across reboots of an instance! It does not persist across a stop/start, nor a termination, nor some instance hardware failures. Here's an article I wrote on the difference between reboot and stop/start: http://alestic.com/2011/09/ec2-reboot-stop-start – Eric Hammond Oct 01 '12 at 23:29
1

I created a script for Ubuntu that can be run at boot and after a start/stop cycle since in the world of AWS those are two very different things. When you reboot you still have the same ephemeral disk and all you have to do is mount (/etc/fstab should handle this automatically) but when an instance is stopped and then restarted you get a new unformatted ephemeral disk which needs more love to get ready for use. As long as you have the /etc/fstab entry correct you can run this at any time and it will mount/format the device as needed. it will take a parameter of the mount point but if not provided it will assume /mnt You can call the script mount_ephemeral.sh and run as root in a startup service.

#!/bin/sh
set -e
mountPoint=${1:-'/mnt'}
rawDevice=$(grep "\s$mountPoint\s" /etc/fstab |cut -f1)
#echo checking $mountPoint on $rawDevice
[ "$rawDevice" = "" ] && { echo -e "$mountPoint not in /etc/fstab"; exit 1; }
mountpoint -q $mountPoint
[  "$?" = "0" ] && { echo -e "$mountPoint mounted"; exit; }
hasFS=$(blkid |grep $rawDevice)
[ ! "$hasFS" = "" ] && { echo -e "$mountPoint has FS:$hasFS"; mount $mountPoint; exit; }
echo initializing $mountPoint on $rawDevice
mkdir -p $mountPoint
mkfs.ext4 $rawDevice
mount $mountPoint
chmod 777 $mountPoint
exit 0
DanJGer
  • 111
  • 2
  • I prefer not to use `/mnt` as a mount point for volumes, because the convention is that `/mnt/foo` is used for each volume. If you have to mount another volume at some point as say `/mnt/bar`, that would mean that unmounting `/mnt` volume can't be done while `/mnt/bar` is mounted. The `grep` is dangerous if you are using `/mnt` and there are mount points such as `/mnt/foo`, since `/mnt` could match several lines - so the script might in some cases mount or mkfs the wrong disk. – RichVel Feb 19 '19 at 06:10
  • It won't find other similar mounts since it has to match exactly. The issue is that the whitespace used in your fstab needs to match the quoted value in the grep. I've updated to use `\b` but YMMV. The `/mnt` is just a default you can change yourself and is only an example. Additionally, you can pass in a parameter to the script and it will use that mount point instead. I am going to add in the `set -e` so that any failure terminates the whole script – DanJGer Feb 20 '19 at 18:08
  • correction: changed from `\b` to `\s` – DanJGer Feb 20 '19 at 18:15
0

The instance store mounting also depends of image:

http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/add-instance-store-volumes.html

When you launch an instance, the default block device mapping is provided by the specified AMI. If you need additional instance store volumes, you must add them to the instance as you launch it. Note that you can also omit devices specified in the AMI block device mapping.

Some images will use all available resources.

Zulu
  • 109
  • 7