Here We are going to see how to add volumes on the instance using Elastic Block Storage(EBS)
- Create a EC2 Instance with Ubuntu OS and with instance type as t2.nano and selected the existing key pair and security group to launch the instance.
- Go to Elastic Block store select volumes
- Create a Volume and set 10 GB as additional storage
- Once volume is created attach the volume on the instance which we created
- login to the instance via ssh and view the attached volume using list block "lsblk"and formate the file system type to "ext4"
kannan@kannan-PC:~$ ssh -i apache.pem ubuntu@3.110.83.63
ubuntu@ip-172-31-47-222:~$ df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/root ext4 7.6G 1.6G 6.0G 21% /
tmpfs tmpfs 224M 0 224M 0% /dev/shm
tmpfs tmpfs 90M 832K 89M 1% /run
tmpfs tmpfs 5.0M 0 5.0M 0% /run/lock
/dev/xvda15 vfat 105M 6.1M 99M 6% /boot/efi
tmpfs tmpfs 45M 4.0K 45M 1% /run/user/1000
ubuntu@ip-172-31-47-222:~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
loop0 7:0 0 24.6M 1 loop /snap/amazon-ssm-agent/7528
loop1 7:1 0 55.7M 1 loop /snap/core18/2790
loop2 7:2 0 63.5M 1 loop /snap/core20/2015
loop3 7:3 0 111.9M 1 loop /snap/lxd/24322
loop4 7:4 0 40.8M 1 loop /snap/snapd/20092
xvda 202:0 0 8G 0 disk
├─xvda1 202:1 0 7.9G 0 part /
├─xvda14 202:14 0 4M 0 part
└─xvda15 202:15 0 106M 0 part /boot/efi
xvdf 202:80 0 10G 0 disk
ubuntu@ip-172-31-47-222:~$ sudo file -s /dev/xvdf
/dev/xvdf: data
ubuntu@ip-172-31-47-222:~$ sudo mkfs -t ext4 /dev/xvdf
mke2fs 1.46.5 (30-Dec-2021)
Creating filesystem with 2621440 4k blocks and 655360 inodes
Filesystem UUID: adc5036f-9501-4b72-951e-1cf30aa4bf72
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
- To mount the formatted volume we need to create a directory we can mount the volume with file name or UUID
ubuntu@ip-172-31-47-222:~$ sudo mkdir /data
ubuntu@ip-172-31-47-222:~$ sudo file -s /dev/xvdf
/dev/xvdf: Linux rev 1.0 ext4 filesystem data, UUID=adc5036f-9501-4b72-951e-1cf30aa4bf72 (extents) (64bit) (large files) (huge files)
ubuntu@ip-172-31-47-222:~$ sudo mount UUID=adc5036f-9501-4b72-951e-1cf30aa4bf72 /data
ubuntu@ip-172-31-47-222:~$ df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/root ext4 7.6G 1.6G 6.0G 21% /
tmpfs tmpfs 224M 0 224M 0% /dev/shm
tmpfs tmpfs 90M 844K 89M 1% /run
tmpfs tmpfs 5.0M 0 5.0M 0% /run/lock
/dev/xvda15 vfat 105M 6.1M 99M 6% /boot/efi
tmpfs tmpfs 45M 4.0K 45M 1% /run/user/1000
/dev/xvdf ext4 9.8G 24K 9.3G 1% /data
- If we reboot the instance the attached volume will not detected to keep detect after reboot or restart the instance we need to backup the volume file.
ubuntu@ip-172-31-47-222:~$ sudo cp /etc/fstab /etc/fstab.backup
ubuntu@ip-172-31-47-222:~$ sudo vi /etc/fstab
- make an volume file entry on the "sudo vim /etc/fstab"
on the above path we can use either path or UUID of the volume.
Mount the Volume file
ubuntu@ip-172-31-47-222:~$ sudo mount -a
ubuntu@ip-172-31-47-222:~$ df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/root ext4 7.6G 1.6G 6.0G 21% /
tmpfs tmpfs 224M 0 224M 0% /dev/shm
tmpfs tmpfs 90M 844K 89M 1% /run
tmpfs tmpfs 5.0M 0 5.0M 0% /run/lock
/dev/xvda15 vfat 105M 6.1M 99M 6% /boot/efi
tmpfs tmpfs 45M 4.0K 45M 1% /run/user/1000
/dev/xvdf ext4 9.8G 24K 9.3G 1% /data
Now the Volume file were mounted permanently.
Top comments (0)