Automatically Mount an EBS Volume Upon Starting an Amazon EC2 Linux Instance
Brief note to create an EBS volume then mount it while CentOS 6.3 on EC2 at boot.
Show the space available on that filesystem before we mount the volume:
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvde1 7.9G 4.0G 3.5G 54% /
tmpfs 296M 0 296M 0% /dev/shm
After we attach
the EBS volume to an EC2 instance:
# fdisk -l
Disk /dev/xvde: 9663 MB, 9663676416 bytes
255 heads, 63 sectors/track, 1174 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00076be1
Device Boot Start End Blocks Id System
/dev/xvde1 * 1 1045 8387584 83 Linux
/dev/xvde2 1045 1175 1048576 82 Linux swap / Solaris
Disk /dev/xvdt: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Create an ext4 filesystem for device /dev/xvdt
:
# mkfs.ext4 /dev/xvdt
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
6553600 inodes, 26214400 blocks
1310720 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
800 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 30 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
There are three ways to mount this volume in /etc/fstab
: (1) through blkid
to get the Block ID with UUID
parameter (2) Disk Device, i.e., /dev/xvdt (3) Filesystem Label
or Volume Name. Here we take (2) to mount this volume to /mnt/ebs
directory by adding the following parameter in /etc/fstab
:
/dev/xvdt /mnt/ebs ext4 defaults 0 0
Confirm the mount status:
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvde1 7.9G 4.0G 3.5G 54% /
tmpfs 296M 0 296M 0% /dev/shm
/dev/xvdt 99G 188M 94G 1% /mnt/ebs
If you found that the volume size mismatch between AWS and device attached, remember to execute resize2fs
to resize it.