[ec2-user ~]$ df -h
For a micro instance, your output should look something like this.Filesystem Size Used Avail Use% Mounted on /dev/xvda1 8.0G 1.1G 6.9G 14% / tmpfs 298M 0 298M 0% /dev/shmThe
/dev/xvda1
volume is the root device volume. It contains the image used to boot the instance.
Notice that there's some room to install additional software on your instance. For example, you
can use the yum command to download and install packages.If you need additional storage for your data, a simple solution is to add Amazon EBS volumes to your instance. An Amazon EBS volume serves as network-attached storage for your instance. Let's add a volume to the Linux instance that you've launched. First we'll use the EC2 console to create the volume and attach it to the instance, and then we'll mount the volume to make it available.
To create and attach an Amazon EBS volume
- Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
- In the navigation bar, select the region in which you created your instance, and then click Instances in the navigation pane.The console displays the list of current instances in that region. Select your Linux instance. In the Description tab in the bottom pane note the Availability Zone for the instance.
- In the navigation pane, under Elastic Block Store, click Snapshots. Select Public Snapshots from the filter list. Select a snapshot from the list and note its snapshot ID. The Free Usage Tier provides up to 30 GB of Amazon Elastic Block Storage; therefore, to avoid being charged for this tutorial, choose a snapshot that is smaller than 30 GB.Note that this tutorial assumes that you create the volume using a snapshot as described in this step. If you create an empty volume instead, we'll ask you to perform an additional step in the next procedure.
- Click Create Volume.
- The Create Volume dialog box is preconfigured with the snapshot ID and volume size of the snapshot you selected. Configure the following, and then click Create:
- Select the Standard volume type to create a standard EBS volume.
- Select the same Availability Zone that you used when you created your instance. Otherwise, you can't attach the volume to your instance.
- In the navigation pane, under Elastic Block Store, click Volumes. Notice that your newly created volume appears there and the state of the volume is
available
, so it's ready to be attached to an instance. - Right-click the newly created volume and select Attach Volume.
- In the Attach Volume dialog box, configure the following, and then click Attach:
- Start typing in the name or ID of your instance, then select it from the list of suggested options.
- Specify an unused device name for that instance. We'll use
/dev/sdf
in this tutorial. If you select a different device name, be sure to note it as you'll need this information in the next procedure.
in-use
, and the volume is attached to your instance with the
device name /dev/sdf
. However, if you return to your instance and
run the df -h command again, you won't see the volume yet. That's
because we need to mount the volume for df -h to see it. The
lsblk command, however, can see all block devices attached to the instance.
Note
Some Linux distributions do not provide the lsblk command
by default. If the lsblk command does not work, you can use
sudo fdisk -l | grep Disk instead.[ec2-user ~]$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvdf 202:80 0 100G 0 disk
└─xvdf1 202:81 0 10G 0 part
xvda1 202:1 0 8G 0 disk /
In
the above example, lsblk reports that there are two block devices
attached to the instance; xvda1
is mounted as the root file system
(note the MOUNTPOINT
value of /
) and
xvdf
(which contains the disk partition,
xvdf1
) is not mounted at all.
To make a volume available
- Identify the device to mount. In the previous procedure, the new volume was attached to
/dev/sdf
. Depending on the block device drivers on your instance's operating system, the device may appear at a different location (such as/dev/xvdf
in the previous example) than what you specified in the console (/dev/sdf
); in some cases, even the trailing letter may change (for example,/dev/xvdj
). Amazon Linux instances always create links from the device path that you specified in the console to the new device path, but other distributions (such as Ubuntu or Red Hat) are not as predictable.
Use the lsblk command to list the available devices.
NoteSome Linux distributions do not provide the lsblk command by default. If the lsblk command does not work, you can use sudo fdisk -l | grep Disk instead.[ec2-user ~]$
Thelsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT xvdf 202:80 0 100G 0 disk └─xvdf1 202:81 0 10G 0 part xvda1 202:1 0 8G 0 disk /xvdf
device is not mounted, and there is a 10 GB partition atxvdf1
. Sometimes when you create a volume from a snapshot, the data on the volume is contained in a partition such as this instead of the root of the volume. In this case, you mount the/dev/xvdf1
partition (the lsblk command output omits the/dev/
portion of the file path). If there was not a partition onxvdf
, then you would mount/dev/xvdf
. - (Optional) If you created an empty volume instead of creating a volume from a snapshot in
the previous procedure, you need to format the volume using
mkfs before you can mount it. Use the following command
to create an ext4 file system on the volume. Substitute the device name (such as
/dev/xvdf
) fordevice_name
.
CautionThis step assumes that you're mounting an empty volume. If you're mounting a volume that already has data on it (for example, a volume that was restored from a snapshot), don't use mkfs before mounting the volume (skip to the next step instead). Otherwise, you'll format the volume and delete the existing data. For more information, see Making the Volume Available on Linux.NoteSUSE Linux Enterprise Server 11 does not fully support ext4 file systems. If you chose a SLES 11 AMI for your instance, useext3
in the following command instead.[ec2-user ~]$
sudo mkfs -t ext4
device_name
- To mount the device as
/mnt/my-data
, run the following commands.
[ec2-user ~]$
Be sure to specify the device name you identified in Step 1; otherwise, you might receive the following error when you run this mount command: "sudo mkdir /mnt/my-data
[ec2-user ~]$sudo mount /dev/xvdf1 /mnt/my-data
mount: you must specify the filesystem type
". If you see this error, repeat Step 1 and use the correct device path (remember to add the/dev/
to the device name you get from the lsblk command). - Now when you run the df -h command, you'll see output like the
following.
[ec2-user ~]$
df -h
Filesystem Size Used Avail Use% Mounted on /dev/xvda1 7.9G 1.1G 6.8G 14% / tmpfs 298M 0 298M 0% /dev/shm /dev/xvdf1 10G 76M 10G 1% /mnt/my-data - To view the contents of the new volume, run the following command.
[ec2-user ~]$
ls /mnt/my-data
Important
Remember, if you launched an instance in the Free Usage Tier, there are no charges.
Otherwise, as soon as your instance starts to boot,
you're billed for each hour or partial hour that you keep the instance
running, even if the instance is idle. You'll stop incurring charges for a regular
instance as soon as the instance status changes to
shutting down
or
terminated
.Source : http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-add-volume-to-instance.html
No comments:
Post a Comment