{"id":472,"date":"2022-12-02T01:54:00","date_gmt":"2022-12-02T01:54:00","guid":{"rendered":"https:\/\/blog.ngocha.biz\/?p=472"},"modified":"2022-12-02T01:54:00","modified_gmt":"2022-12-02T01:54:00","slug":"mount-ebs-volume-ec2-instance","status":"publish","type":"post","link":"https:\/\/blog.ngocha.biz\/?p=472","title":{"rendered":"How to Attach and Mount an EBS volume to EC2 Linux Instance"},"content":{"rendered":"<p>AWS allows you to create new EBS volumes, and you can attach them to instances for extra storage. However, to make EBS volume usable as storage inside the instance, you need to mount it to a specific folder.<\/p>\n<h2 id=\"mount-an-ebs-volume-to-ec2-linux\">Mount an EBS Volume to EC2 Linux<\/h2>\n<p>This tutorial will teach you how to attach and mount an EBS volume to ec2 Linux instances.<\/p>\n<p>Follow the steps given below carefully for the setup.<\/p>\n<p><strong>Step 1:<\/strong> Head over to EC2 &#8211;&gt; Volumes and create a new volume of your preferred size and type.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-14-45.png\" class=\"kg-image\" alt=\"Create EBS volume to attach to ec2 instance\" loading=\"lazy\" width=\"596\" height=\"416\"><\/figure>\n<div class=\"kg-card kg-callout-card kg-callout-card-grey\">\n<div class=\"kg-callout-text\"><b><strong style=\"white-space: pre-wrap;\">Note<\/strong><\/b>: Make sure the EBS volume and the instance are in the same zone.<\/div>\n<\/div>\n<p><strong>Step 2:<\/strong> Select the created volume, right-click and select the &#8220;<code>attach volume<\/code>&#8221; option.<\/p>\n<p><strong>Step 3: <\/strong>Select the ec2 instance from the instance text box as shown below.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/ebs-volume-1.jpg\" class=\"kg-image\" alt=\"attach ebs volume\" loading=\"lazy\" width=\"809\" height=\"300\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/ebs-volume-1.jpg 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/ebs-volume-1.jpg 809w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p><strong>Step 4:<\/strong> Now, login to your ec2 instance and list the available disks using the following command.<\/p>\n<pre><code>lsblk<\/code><\/pre>\n<p>The above command will list the disk you attached to your instance.<\/p>\n<p><strong>Step 5:<\/strong> Check if the volume has any data using the following command.<\/p>\n<pre><code>sudo file -s \/dev\/xvdf<\/code><\/pre>\n<p>If the above command output shows &#8220;<code>\/dev\/xvdf: data<\/code>&#8220;, it means your volume is empty.<\/p>\n<p><strong>Step 6:<\/strong> Format the volume to the <code>ext4<\/code> filesystem using the following command.<\/p>\n<pre><code>sudo mkfs -t ext4 \/dev\/xvdf<\/code><\/pre>\n<p>Alternatively, you can also use the <strong><code>xfs<\/code><\/strong> format. You have to use either ext4 or xfs.<\/p>\n<pre><code> sudo mkfs -t xfs \/dev\/xvdf<\/code><\/pre>\n<p><strong>Step 7:<\/strong> Create a directory of your choice to mount our new ext4 volume. I am using the name &#8220;<code>newvolume<\/code>&#8220;. You can name it something meaningful to you.<\/p>\n<pre><code>sudo mkdir \/newvolume<\/code><\/pre>\n<p><strong>Step 8:<\/strong> Mount the volume to &#8220;<strong><code>newvolume<\/code><\/strong>&#8221; directory using the following command.<\/p>\n<pre><code>sudo mount \/dev\/xvdf \/newvolume\/<\/code><\/pre>\n<p><strong>Step 9:<\/strong> <code>cd<\/code> into <code>newvolume<\/code> directory and check the disk space to validate the volume mount.<\/p>\n<pre><code>cd \/newvolume df -h .<\/code><\/pre>\n<p>The above command should show the free space in the <code>newvolume<\/code> directory.<\/p>\n<p>To unmount the volume, use the <code>unmount<\/code> command as shown below..<\/p>\n<pre><code>sudo umount \/dev\/xvdf<\/code><\/pre>\n<h2 id=\"automount-ebs-volume-on-reboot\">Automount EBS Volume on Reboot<\/h2>\n<p>By default on every reboot, the EBS volumes other than the root volume will get unmounted. To enable automount, you need to make an entry in the <code>\/etc\/fstab<\/code> file.<\/p>\n<p>Follow the steps given below to automount the EBS volume to the ec2 instance.<\/p>\n<p><strong>Step 1:<\/strong> Back up the <strong><code>\/etc\/fstab<\/code><\/strong> file.<\/p>\n<pre><code>sudo cp \/etc\/fstab \/etc\/fstab.bak<\/code><\/pre>\n<p><strong>Step 2:<\/strong> Open<strong><code> \/etc\/fstab<\/code><\/strong> file and make an entry in the following format.<\/p>\n<pre><code>device_name mount_point file_system_type fs_mntops fs_freq fs_passno<\/code><\/pre>\n<p>For example,<\/p>\n<pre><code>\/dev\/xvdf       \/newvolume   ext4    defaults,nofail        0       0<\/code><\/pre>\n<p><strong>Step 3:<\/strong> Execute the following command to check if the <strong><code>fstab<\/code><\/strong> file has any errors.<\/p>\n<pre><code>sudo mount -a<\/code><\/pre>\n<p>If the above command shows no error, it means your <strong>fstab<\/strong> entry is valid.<\/p>\n<p>Now, on every reboot, the extra EBS volumes will get mounted automatically.<\/p>\n<h2 id=\"add-multiple-ebs-volumes-to-ec2-instance\">Add Multiple EBS Volumes To EC2 Instance<\/h2>\n<p>You can add more than one EBS volume to an ec2 instance as an additional disk. You can follow the same steps explained above and the only difference will be the disk name that you get from the <code>lsblk<\/code> command.<\/p>\n<p>Here is an example output having two EBS volumes attached to an instance.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-318.png\" class=\"kg-image\" alt=\"Multiple EBS volumes on ec2 instance\" loading=\"lazy\" width=\"595\" height=\"116\"><\/figure>\n<h2 id=\"mount-one-ebs-volume-to-multiple-ec2-instances\">Mount one EBS volume to Multiple EC2 Instances<\/h2>\n<p>If you have any use case to <strong>mount an EBS volume to multiple ec2 instances<\/strong>, you can do it via EBS multi-attach functionality.<\/p>\n<p>This option only serves specific use cases where multiple machines need to read\/write to the same storage location concurrently.<\/p>\n<p>The EBS multi-attach option is available only for Provisioned IOPS (PIOPS) EBS volume types.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-13-32.png\" class=\"kg-image\" alt=\"Attaching EBS volume to multiple ec2 instances.\" loading=\"lazy\" width=\"560\" height=\"322\"><\/figure>\n<div class=\"kg-card kg-callout-card kg-callout-card-grey\">\n<div class=\"kg-callout-text\"><b><strong style=\"white-space: pre-wrap;\">Note:<\/strong><\/b> EBS multi-attach does not support <code spellcheck=\"false\" style=\"white-space: pre-wrap;\">XFS<\/code>, <code spellcheck=\"false\" style=\"white-space: pre-wrap;\">EXT2<\/code>, <code spellcheck=\"false\" style=\"white-space: pre-wrap;\">EXT4<\/code>, and <code spellcheck=\"false\" style=\"white-space: pre-wrap;\">NTFS<\/code> file systems. It supports only cluster-aware file systems.<\/div>\n<\/div>\n<h2 id=\"how-many-ebs-volumes-can-i-attach-to-an-instance\">How Many EBS volumes can I attach to an Instance?<\/h2>\n<p>You can attach a <strong>maximum of 27 EBS volumes<\/strong> to an ec2 instance. Also, this count changes for a few instance types. Please check the <a href=\"https:\/\/docs.aws.amazon.com\/AWSEC2\/latest\/UserGuide\/volume_limits.html?ref=devopscube.com\" rel=\"noreferrer noopener\">Volume limits document<\/a> to know more.<\/p>\n<p>Also, limit the number of EBS maximum volumes attached to ec2 instances to have optimal performance. Also, plan your instance capacity based on the workload you are trying to run.<\/p>\n<p>For example, databases require high IOPS for high read-write rates. IOPS depends on the disk size. Higher the size, the higher the IOPS.<\/p>\n<p>It is recommended to take snapshots of EBS volumes for high data high availability and restore options. Check out the <a href=\"https:\/\/devopscube.com\/automate-ebs-snapshot-creation-deletion\/\" rel=\"noreferrer noopener\">EBS snapshot automation<\/a> article for strategies and restore options.<\/p>\n<h2 id=\"conclusion\">Conclusion<\/h2>\n<p>In this article, you have learned how to mount an EBS volume to the ec2 instance.<\/p>\n<p>As a <a href=\"https:\/\/devopscube.com\/become-devops-engineer\/\">DevOps Engineer<\/a>, it is very important to understand all the EBS attach options when working on real-time projects.<\/p>\n<p>If you get any errors during the setup, please feel free to contact us in the comment section.<\/p>\n<p>If you are also working with s3 object storage, check our guide on <a href=\"https:\/\/devopscube.com\/mount-aws-s3-bucket-to-ec2-instance\/\" rel=\"noreferrer\">mounting s3 bucket to ec2<\/a><\/p>\n<hr>\n<p><strong>Ngu\u1ed3n:<\/strong> <a href=\"https:\/\/devopscube.com\/mount-ebs-volume-ec2-instance\/\" target=\"_blank\" rel=\"noopener noreferrer\">How to Attach and Mount an EBS volume to EC2 Linux Instance \u2014 DevOpsCube<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Source: https:\/\/devopscube.com\/mount-ebs-volume-ec2-instance\/<\/p>\n","protected":false},"author":1,"featured_media":473,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-472","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops"],"_links":{"self":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts\/472","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=472"}],"version-history":[{"count":0,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts\/472\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/media\/473"}],"wp:attachment":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=472"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=472"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=472"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}