Ticker

6/recent/ticker-posts

Play with EBS volume in EC2 instance

 





A file system is in charge of arranging and handling data on storage devices like hard drives and solid-state drives (SSDs).

Check whether disk is HDD or HDD

$lsblk -o name, rota | tail
$cat /sys/block/sda/queue/rotational


Most of the time we use either ext4 or xfs filesystem however as per the requirement you could create different filesystem.

To see the the filesystem type run the following command:

$df -Th


Most of the time we use either ext4 or xfs filesystem, To create a disk filesystem run the following command.

$ sudo mkfs -t ext4 /dev/sda
$ sudo mkfs -t xfs /dev/sda

To see the mount point use lsblk command:





How to create LVM on AWS?

LVM is useful when you don't want your system to go in maintainence windows and dynamically you want to extend the filesystem size irrespective for disks.

To install LVM on EC2, run the following command:

$yum install lvm2

Let's say the device you attached to EC2 are /dev/sda, /dev/sdb and /dev/sdc

Use pvcreate command that initialize the disk or essentially partitions so that it can be used by LVM

$sudo pvcreate /dev/sda /dev/sdb /dev/sdc

To see the created physical volume you could run the following command:

$pvdisplay

Now create the LVM volume group:

$sudo vgcreate <volume-name> <device-1> <device-2> <device-3>
$sudo vgcreate xyz /dev/sda /dev/sdb /dev/sdc


Now create logical volumes

$sudo lvcreate --name <logical-volume-name> --size <size-of-volume> <lvm-volume-name>

$sudo lvcreate --name data --size 5GB xyz
$
sudo lvcreate --name backup --size 15GB xyz
See the status of Logical volumes
$sudo lvdisplay


Format the Logical volumes with ext4 or xfs
$mkfs.ext4 /dev/xyz/data 
$mkfs.ext4 /dev/xyz/backup

Mount the Logical volumes
$sudo mkdir /data
$sudo mkdir /backup


$sudo mount /dev/xyz/data /data
$sudo mount /dev/xyz/backup /backup
Mount to be available even after reboot you could add the mount entry in /etc/fstab file



How to increase the root volume of EC2 instance


Just restart the instance or running the following command if you don't want to stop the instance:

$sudo yum install cloud-utils-growpart

$sudo growpart /dev/xvda 1

$
sudo xfs_growfs -d /


Add New EBS volume to EC2 instance:

$lsblk
$df -hT
$mkdir /data
$sudo mkfs -t xfs -f /dev/xvdb
$sudo mount /dev/xvdb /data


Create partition:

# Start fdisk on /dev/xvdb
$sudo fdisk /dev/xvdb
n
p
1
+1G

n
p
2
+1G

n
p
3

w
q

# Verify partitions
$lsblk

# Format the partitions with ext4 filesystem
$sudo mkfs.ext4 /dev/xvdb1
$sudo mkfs.ext4 /dev/xvdb2
$sudo mkfs.ext4 /dev/xvdb3


# Create mount points
$sudo mkdir -p /mnt/partition1 /mnt/partition2 /mnt/partition3


# Mount the partitions
$sudo mount /dev/xvdb1 /mnt/partition1
$sudo mount /dev/xvdb2 /mnt/partition2
$sudo mount /dev/xvdb3 /mnt/partition3



References:





Post a Comment

0 Comments