To create new EBS volume navigate to EC2, Elastic Block Store, Volumes then click Create volume.
-choose the desired volume type and size, make sure the EBS volume is in the same AZ as the EC2 instance it will be attached to. Then click Create.
-choose the EBS volume you created, Actions then Attach volume
-select the EC2 instance you want to attach the EBS volume to it. EBS volume name will be /dev/sdf or /dev/xvdf by default
-EBS volume is successfully attached
-connect to your EC2 instance (to use EC2 instance connect you must allow SSH in the inbound rules of attached security group).
sudo lsblk
view your available disk devices and their mount points.
the EBS volume we attached is xvdf (1G) and it has no mount point.
sudo lsblk -f
get information about all of the devices attached to the instance.
sudo file -s /dev/xvdf
show file system for disk xvdf
sudo mkfs -t xfs /dev/xvdf
create a file system xfs on the volume xdvf
If you get an error that mkfs.xfs is not found, use the following command to install the XFS tools and then repeat the previous command: sudo yum install xfsprogs
sudo mkdir /ebs
create directory ebs, we will use this directory to mount our EBS volume
sudo mount /dev/xvdf /ebs
mount the volume at the directory you created
**To mount an attached EBS volume on every system reboot, add an entry for the device to the /etc/fstab file.
You can use the device name, such as /dev/xvdf, in /etc/fstab, but it is recommended to use the device's 128-bit universally unique identifier (UUID) instead. Device names can change, but the UUID persists throughout the life of the partition.**
sudo cp /etc/fstab /etc/fstab.orig
Create a backup of your /etc/fstab to restore it in case of any problems
sudo blkid
find the UUID of the device
EBS volume UUID is 0bce0506-dd1d-4ee7-9aef-642eac6501bb
sudo vim /etc/fstab
edit the fstab file
press i to enter insert mode
Add the following entry to /etc/fstab
UUID=0bce0506-dd1d-4ee7-9aef-642eac6501bb /ebs xfs defaults,nofail 0 2
0 to prevent the file system from being dumped, and we specify 2 to indicate that it is a non-root device.
esc
:wq
w stands for write (save) and q stands for quit.
to check unmout the device then mount all file systems in /etc/fstab
sudo umount /ebs
sudo mount -a
Errors in the /etc/fstab file can render a system unbootable. Do not shut down a system that has errors in the /etc/fstab file
restore fstab backup in case of error
sudo mv /etc/fstab.orig /etc/fstab
Top comments (2)
Great insights
Nice Job