EBS volumes and file systems

1. Instance Root Volume Default Format Type

  • Default Format Type:

    • Amazon EC2 root volumes are typically formatted with ext4 for Linux-based instances and NTFS for Windows instances.
  • How to Check:

      lsblk -f
    

    This command displays the block devices and their filesystem types.


2. Checking the Filesystem Type of an EBS Volume

  • Use the following command to check the filesystem type:

      sudo file -s /dev/xvdf
    
    • If it shows something like "data," it means the volume is not yet formatted.

    • If it shows a filesystem type (e.g., ext4), the volume is already formatted.


3. Formatting an EBS Volume

  • To format a new EBS volume:

      sudo mkfs.ext4 /dev/xvdf
    

    Replace /dev/xvdf with your volume's device name.


4. Mounting and Automounting an EBS Volume

Mounting

  • Create a directory to mount the volume:

      sudo mkdir /data
    
  • Mount the volume:

      sudo mount /dev/xvdf /data
    
  • Verify:

      df -h
    

Automounting at Boot

  • Add an entry in /etc/fstab:

    1. Get the UUID of the volume:

       sudo blkid /dev/xvdf
      
    2. Edit /etc/fstab:

       sudo nano /etc/fstab
      

      Add the following line:

       UUID=<your-uuid> /data ext4 defaults,nofail 0 2
      
    3. Test the configuration:

       sudo mount -a
      

5. Adding Storage to an EBS Volume

Attach the Volume

  1. Attach the volume to the instance from the AWS Management Console or CLI:

     aws ec2 attach-volume --volume-id vol-xxxxxxxx --instance-id i-xxxxxxxx --device /dev/xvdf
    

Resizing the Filesystem

  1. Check the new size:

     lsblk
    
  2. Resize the partition:

     sudo growpart /dev/xvdf 1
    
  3. Resize the filesystem:

     sudo resize2fs /dev/xvdf
    

6. Modifying EBS Volume Type

  • You can modify the EBS volume type (e.g., General Purpose SSD gp3, gp2, Provisioned IOPS io1, etc.) using the AWS Management Console or CLI:

      aws ec2 modify-volume --volume-id vol-xxxxxxxx --volume-type gp3
    

7. File System Types in EBS Volumes

  • Common Linux file systems:

    • ext4: Most common for general-purpose use.

    • xfs: High-performance and scalable.

    • btrfs: Advanced features like snapshotting.

    • ntfs: Used mainly for Windows systems.

To change the filesystem:

  1. Unmount the volume:

     sudo umount /data
    
  2. Reformat the volume with the desired filesystem:

     sudo mkfs.xfs /dev/xvdf
    

8. Block-Level Formatting

  • Format the entire block device before creating partitions:

      sudo dd if=/dev/zero of=/dev/xvdf bs=1M count=1
    

    Note: Be cautious as this erases all data.


Quick Summary Commands

TaskCommand
Check filesystem typesudo file -s /dev/xvdf
Format EBS volumesudo mkfs.ext4 /dev/xvdf
Mount volumesudo mount /dev/xvdf /data
Automount at bootEdit /etc/fstab
Check device infolsblk -f
Resize filesystemsudo resize2fs /dev/xvdf