Often times, we may have to add additional disks to store application or other data. To make the newly added volume usuable, a filesystem and a partition (if needed) needs to be created from the OS level. In this blog, we will explore the steps to create a partition and a filesystem once a new volume is attached to an EC2 Linux instance.
Execute the following command to check if a filesystem exists on a volume:
Note: the device label could be different in your case if a different label name was selected while attaching the volume.
If the output of the above command is /dev/xvdf: data, then there is no file system on the device.
Refer to the following link for the steps to create a filesystem on a raw volume (without partition).
- Check the filesystem on the root volume using lsblk -f or df -hT command.
- Switch to the root user - sudo su -
- parted /dev/xvdf
- print
- mklabel gpt
- mkpart primary ext4 1MB 18GB
- mkfs.ext4 /dev/xvdf1
- mount /dev/xvdf1 /mnt
- Check the UUID of the new disk with the lsblk -f command.
- Update the fstab file located in /etc directory.
- vi /etc/fstab
- UUID= /mountpoint ext4 defaults,nofail 0 0
- Note - Append the UUID of the new disk retrieved from step 6 after the = sign and update the mountpoint based on the mountpoint set on step 5.
- mount -a
- partprobe
Once the above commands are executed, a persistent parition on a new volume with a filesystem is created.