Skip to content

Instantly share code, notes, and snippets.

@sfate
Created June 2, 2019 17:40
Show Gist options
  • Save sfate/51fcf0e4df5abc819f7e3823bbace1c6 to your computer and use it in GitHub Desktop.
Save sfate/51fcf0e4df5abc819f7e3823bbace1c6 to your computer and use it in GitHub Desktop.
Attach and mount an EBS volume to EC2 instance

Attach volume to EC2

1. Head over to EC2 –> Volumes and create a new volume of your preferred size and type.

2. Select the created volume, right click and select the “attach volume” option.

3. Select the instance from the instance text box.

4. Now, login to your ec2 instance and list the available disks:

lsblk

5. Check if the volume has any data using the following command.

sudo file -s /dev/xvdf

If the above command output shows /dev/xvdf: data, it means your volume is empty.

6. Format the volume to ext4 filesystem.

sudo mkfs -t ext4 /dev/xvdf

7. Create a directory of your choice to mount our new ext4 volume.

sudo mkdir /newvolume

8. Mount the volume to directory.

sudo mount /dev/xvdf /newvolume/

9. To unmount the volume.

umount /dev/xvdf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment