Add new volume to EC2

With this tutorial, you will be able to add a new drive to your existing EC2 instance.

Volume identification

Before adding the volume we have to identify block device. For this setup I’ve choose the device name to be /dev/xvdh. To identify what block device we have to setup we do the following as root:

[root@server ~]# lsblk
NAME    MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda    202:0    0  20G  0 disk 
└─xvda1 202:1    0  20G  0 part /
xvdf    202:80   0   8G  0 disk <-- this is the SWAP volume
xvdh    202:112  0  50G  0 disk 

Creating the file system

Do not use this command if you’re mounting a volume that already has data on it (for example, a volume that was restored from a snapshot). Otherwise, you’ll format the volume and delete the existing data.

The file system will be created as follows:

[root@server ~]# mkfs -t xfs /dev/xvdh
meta-data=/dev/xvdh              isize=512    agcount=4, agsize=3276800 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=13107200, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=6400, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

Create the volume folder

In this case the volume folder will be named /data and it will be created on the top level:

 
[root@server]# mkdir /data

Manually check

Before doing anything on the /etc/fstab file, it’s best to check the volume by mounting it to the volume folder.

 
[root@server]# mount /dev/xvdh /data

If we didn’t get any error than is fine. We can check what we’ve done by checking the mount points:

 
[root@server]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda1       20G  1.1G   19G   6% /
devtmpfs        1.9G     0  1.9G   0% /dev
tmpfs           1.9G     0  1.9G   0% /dev/shm
tmpfs           1.9G   17M  1.9G   1% /run
tmpfs           1.9G     0  1.9G   0% /sys/fs/cgroup
tmpfs           379M     0  379M   0% /run/user/1000
tmpfs           379M     0  379M   0% /run/user/0
/dev/xvdh        50G   33M   50G   1% /data < -- this is our volume

Make changes persistent over reboots

For this we need to change the /etc/fstab file, but before that we need to get the volume ID:

 
[root@server]#  blkid
/dev/xvda1: UUID="8c1540fa-e2b4-407d-bcd1-59848a73e463" TYPE="xfs" <-- root volume 
/dev/xvdf: UUID="115a4adc-bcbf-4dc5-a911-782cc25be2b3" TYPE="swap" <-- swap volume
/dev/xvdh: UUID="ccb74f7c-ff32-45a1-ab69-779c6aa363a9" TYPE="xfs" <-- Data volume

Since we’ve identify what is our UUID we move forward to change the /etc/fstab file with the following content:

 
UUID=ccb74f7c-ff32-45a1-ab69-779c6aa363a9  /data  xfs  defaults,nofail  0  2

Test the setup

Since we mounted the volume all ready we need to unmount the volume and execute the instructions from file /etc/fstab. So, first umount the volume:

 
[root@server]# umount /data/

And now we do the following:

 
[root@server]# mount -a

Doing this the file /etc/fstab will be read and execute.