Showing posts with label ebs. Show all posts
Showing posts with label ebs. Show all posts

Saturday, July 4, 2015

EBS expand file system to recognize volume size in Ubuntu

A common scenario when dealing using EC2 is expanding EBS/volume sizes. You may be doing a new AMI or just expanding an existing volume. This article is about how to make your file system (ex. xfs, ext) to recognize the size of your new volumes.

After you expand your volume, ssh into the instance.

Show the instance's volumes and their sizes.

> sudo lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL

NAME    FSTYPE              SIZE MOUNTPOINT        LABEL
xvda1   ext4                128G /                 /
xvdb    ext3                840G /media/ephemeral0
xvdm    linux_raid_member    10G                   ip-10-188-5-211:0
└─md127 xfs                  60G /mnt/data
xvdn    linux_raid_member    10G                   ip-10-188-5-211:0
└─md127 xfs                  60G /mnt/data
xvdo    linux_raid_member    10G                   ip-10-188-5-211:0
└─md127 xfs                  60G /mnt/data
xvdl    linux_raid_member    10G                   ip-10-188-5-211:0
└─md127 xfs                  60G /mnt/data
xvdj    linux_raid_member    10G                   ip-10-188-5-211:0
└─md127 xfs                  60G /mnt/data
xvdk    linux_raid_member    10G                   ip-10-188-5-211:0
└─md127 xfs                  60G /mnt/data
xvdf    ext4                 30G /mnt/shared

In the example above, we see /dev/xvda1 has 128G and is using file system ext4.

If you want more details on the file system types of each volume, you can use the file command:

> sudo file -s /dev/xvd*

/dev/xvda1: Linux rev 1.0 ext4 filesystem data, UUID=ebbf1b1c-fb71-40aa-93a3-056b455e5127 (needs journal recovery) (extents) (large files) (huge files)
/dev/xvdb:  Linux rev 1.0 ext3 filesystem data, UUID=07b9bb55-97cc-47e8-b968-6f158e66ff60 (needs journal recovery) (large files)
/dev/xvdf:  Linux rev 1.0 ext4 filesystem data, UUID=bff77q92-806c-44a5-a260-5a50025283ba (needs journal recovery) (extents) (large files) (huge files)
/dev/xvdj:  data
/dev/xvdk:  data
/dev/xvdl:  data
/dev/xvdm:  data
/dev/xvdn:  data
/dev/xvdo:  data

> lsblk

NAME    MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
xvda1   202:1    0   128G  0 disk  /
xvdb    202:16   0   840G  0 disk  /media/ephemeral0
xvdm    202:192  0    10G  0 disk
└─md127   9:127  0    60G  0 raid0 /mnt/data
xvdn    202:208  0    10G  0 disk
└─md127   9:127  0    60G  0 raid0 /mnt/data
xvdo    202:224  0    10G  0 disk
└─md127   9:127  0    60G  0 raid0 /mnt/data
xvdl    202:176  0    10G  0 disk
└─md127   9:127  0    60G  0 raid0 /mnt/data
xvdj    202:144  0    10G  0 disk
└─md127   9:127  0    60G  0 raid0 /mnt/data
xvdk    202:160  0    10G  0 disk
└─md127   9:127  0    60G  0 raid0 /mnt/data
xvdf    202:80   0    30G  0 disk  /mnt/shared

> df -h

Filesystem            Size  Used Avail Use% Mounted on
/dev/xvda1            7.9G  4.0G  3.9G  52% /
tmpfs                  17G     0   17G   0% /dev/shm
/dev/xvdb             827G  201M  785G   1% /media/ephemeral0
/dev/xvdf              30G  8.0G   21G  29% /mnt/shared
/dev/md127             60G   15G   46G  25% /mnt/data

For ext2, ext3, ext4, you can use the resize2fs command.

Resize /dev/xvda1

> sudo resize2fs /dev/xvda1

For xfs, you can do

> sudo xfs_growfs -d /mnt

Tuesday, December 11, 2012

Amazon EC2 - Mounting a EBS drive


This post applies to

  • mounting a new EBS volume
  • mounting an existing EBS volume or snapshot

Specs:
  • Ubuntu Server 12.04.1 LTS 64-bit
  • XFS

1.) Creating a EBS volume (skip this if you have a volume already)

  • Login to your Amazon EC2 Admin Console
  • In the left sidebar menu, expand Elastic Block Volume and click on Volumes
  • Click on Create Volume
  • Specify a size (Ex. 8 Gib)
  • Set Availability Zone to the region that your instance is in (Note that it is very important that the EBS and the instance are in the same region.)
  • Click "Yes, Create"
  • Wait till the console says the EBS is available (blue circle).


2.) Attaching a EBS volume to an instance



3.) Mounting the EBS volume

ssh into your instance  (ex. ssh -i {key} {user}@{ec2_address})


sudo apt-get update && sudo apt-get upgrade -y


Check if the drive is available by
sudo fdisk -l
Sample output:
Disk /dev/xvdf: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders, total 16777216 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000 
Disk /dev/xvdf doesn't contain a valid partition table
Install xfs tools.
sudo apt-get install -y xfsprogs xfs
sudo mkfs.xfs /dev/xvdf 
Add the new volume to the file system configuration file.
sudo vi /etc/fstab
Add the following to the end of the file.
/dev/xvdf /vol xfs noatime 0 0
Save the file.

/vol is the mount point for the partition /dev/xvdf.

Note that xvd[f-p] are partitions for EBS. You can choose which letter to use when creating the EBS in the EC2 admin console.


sudo mkdir -m 000 /vol

sudo mount /vol

cd into /vol to see if it's accessible.