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
:Get the UUID of the volume:
sudo blkid /dev/xvdf
Edit
/etc/fstab
:sudo nano /etc/fstab
Add the following line:
UUID=<your-uuid> /data ext4 defaults,nofail 0 2
Test the configuration:
sudo mount -a
5. Adding Storage to an EBS Volume
Attach the Volume
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
Check the new size:
lsblk
Resize the partition:
sudo growpart /dev/xvdf 1
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 IOPSio1
, 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:
Unmount the volume:
sudo umount /data
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
Task | Command |
Check filesystem type | sudo file -s /dev/xvdf |
Format EBS volume | sudo mkfs.ext4 /dev/xvdf |
Mount volume | sudo mount /dev/xvdf /data |
Automount at boot | Edit /etc/fstab |
Check device info | lsblk -f |
Resize filesystem | sudo resize2fs /dev/xvdf |