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:
sudo file -s /dev/xvdf
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):
The steps described below creates a partition on the newly added volume and configures an ext4 file system.
- Check the filesystem on the root volume using
lsblk -f
ordf -hT
command. - Switch to the root user -
sudo su -
- Execute the following commands to set the label as gpt and create a filesystem.
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.
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.vi /etc/fstab UUID= /mountpoint ext4 defaults,nofail 0 0 mount -a partprobe
Once the above commands are executed, a persistent parition on a new volume with a filesystem is created.