XFS in AWS EC2 for MongoDB. The easy way

Changing the filesystem on AWS EC2 is a difficult task. The easy way to use XFS filesystem on AWS EC2 for hosting MongoDB is to add an extra block storage and format it as XFS

  • First create a Block Storage and attach.
  • Provisioned IOPS SSD is a suitable one for high volume data flow.
  • Once the block storage is attached, then use the command prompt or terminal to format the disk as XFS and mount
    1. apt-get update
    2. apt-get upgrade
    3. lsblk —- to view the attached block device and confirm
    4. file -s /dev/nvme1n1 — to check if there is a filesystem already there or not. if there is no filesystem then it will return “device” . Else it will show something like this “/dev/nvme1n1: SGI XFS filesystem data (blksz 4096, inosz 512, v2 dirs)”.
    5. mkfs -t xfs /dev/nvme1n1 —– command to format the disk with XFS filesystem
    6. apt-get install xfsprogs –— command to install xfs tools
    7. mkdir /mongodata
    8. mount /dev/nvme1n1 /data
    9. mount /dev/nvme1n1 /mongodatabases/
    10. cp /etc/fstab /etc/fstab.orig
    11. blkid —– to check the UUID of the block device added
    12. nano /etc/fstab —– and add the device like this UUID=7xxf03xx-6xxx-4xxx-9xxx-exxxxff2xxxxf /mongodatabases xfs defaults,nofail 0 2
    13. umount /mongodatabases/ —– unmount and mount -a to check fstab entry
    14. mount -a
    15. reboot — I did a double check by rebooting and checked if the disk is still attched and the mounted
    16. df -h
    17. lsblk
    18. mount

Leave a Reply