{"id":30009,"date":"2026-12-05T22:05:12","date_gmt":"2026-12-05T22:05:12","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=30009"},"modified":"2026-12-05T22:05:12","modified_gmt":"2026-12-05T22:05:12","slug":"aws-tutorial-auto-mount-ebs-volume-to-ec2-linux-instance-on-reboot","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/aws-tutorial-auto-mount-ebs-volume-to-ec2-linux-instance-on-reboot\/","title":{"rendered":"AWS Tutorial: Auto mount EBS Volume to ec2 Linux instance on Reboot"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">To make an extra Amazon EBS volume mount automatically after an EC2 Linux instance reboots, add an entry for it to <code>\/etc\/fstab<\/code>. Refer to the volume by its filesystem UUID and include the <code>nofail<\/code> option. The steps above show the basic idea. This guide adds the missing steps (attaching, formatting, finding the UUID), corrects the device-name example, and explains how to test the entry so a mistake can&#039;t stop the instance from booting.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">By default on every reboot, the EBS volumes other than root volume will get unmounted. To enable automount, you need to make an entry in the \/etc\/fstab file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Follow the steps given below to automount the EBS volume to ec2 instance.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 1: Back up the \/etc\/fstab file.<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">sudo cp \/etc\/fstab \/etc\/fstab.bak<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2: Open \/etc\/fstab file and make an entry in the following format.<\/h2>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">device_name mount_point file_system_type fs_mntops fs_freq fs_passno\n\nFor example,\n\n\/dev\/xvdf       \/newvolume   ext4    defaults,nofail        0       0<\/code><\/span><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Step 3: Execute the following command to check id the fstab file has any error.<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">sudo mount -a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If the above command shows no error, it means your fstab entry is good.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now, on every reboot, the extra EBS volumes will get mounted automatically.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Why the volume is not mounted after a reboot<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">EBS volumes do not unmount themselves. A volume mounted by hand with the <code>mount<\/code> command exists only in the running kernel, so the mount is gone after a restart. The volume is still attached and its data is untouched. At boot, systemd reads <code>\/etc\/fstab<\/code> and mounts every filesystem listed there. A volume that isn&#039;t in that file stays attached but unmounted.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Each line in <code>\/etc\/fstab<\/code> has six fields:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Field<\/th><th>Example<\/th><th>Meaning<\/th><\/tr><\/thead><tbody><tr><td>Device<\/td><td><code>UUID=1b2c...<\/code><\/td><td>Which filesystem to mount. A UUID is safer than a <code>\/dev<\/code> name.<\/td><\/tr><tr><td>Mount point<\/td><td><code>\/data<\/code><\/td><td>An existing, empty directory<\/td><\/tr><tr><td>Type<\/td><td><code>xfs<\/code> or <code>ext4<\/code><\/td><td>Filesystem type created with <code>mkfs<\/code><\/td><\/tr><tr><td>Options<\/td><td><code>defaults,nofail<\/code><\/td><td>Mount options. <code>nofail<\/code> lets the boot continue if the volume is missing.<\/td><\/tr><tr><td>Dump<\/td><td><code>0<\/code><\/td><td>Used by the old <code>dump<\/code> backup tool. Almost always 0.<\/td><\/tr><tr><td>Pass<\/td><td><code>2<\/code><\/td><td>fsck order at boot: 0 = never check, 1 = root, 2 = other filesystems<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A running EC2 Linux instance (Amazon Linux 2023, Amazon Linux 2, Ubuntu, RHEL and similar) and SSH access to it. On Windows, see <a href=\"https:\/\/www.devopsschool.com\/blog\/how-to-login-to-linux-server-using-putty\/\">How to Login to Linux Server using Putty?<\/a>.<\/li>\n\n\n<li>An EBS volume in the <strong>same Availability Zone<\/strong> as the instance, attached through the console or with <code>aws ec2 attach-volume --volume-id vol-0123456789abcdef0 --instance-id i-0123456789abcdef0 --device \/dev\/sdf<\/code>.<\/li>\n\n\n<li>sudo privileges on the instance.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note:<\/strong> The device name you choose in the console (for example <code>\/dev\/sdf<\/code>) is often not the name Linux uses. On Nitro-based instances, EBS volumes appear as NVMe devices such as <code>\/dev\/nvme1n1<\/code>. On older Xen instances they usually appear as <code>\/dev\/xvdf<\/code>. Always check with <code>lsblk<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Complete procedure<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">First, find the new volume. It&#039;s the disk that has no mount point:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">lsblk -f\n\n<span class=\"hljs-comment\"># Example output on a Nitro instance<\/span>\nNAME          FSTYPE LABEL UUID                                 MOUNTPOINTS\nnvme0n1\n\u251c\u2500nvme0n1p1   xfs    \/     <span class=\"hljs-number\">2<\/span>a1f...                              \/\n\u2514\u2500nvme0n1p128 vfat         <span class=\"hljs-number\">7<\/span>B77<span class=\"hljs-number\">-95E7<\/span>                            \/boot\/efi\nnvme1n1<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Check whether the volume already contains a filesystem. If the output is just <code>data<\/code>, the volume is empty. If it shows a filesystem (for example a volume restored from a snapshot), <strong>skip the mkfs step<\/strong>, because formatting erases everything on the volume.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">sudo file -s \/dev\/nvme1n1\n<span class=\"hljs-comment\"># \/dev\/nvme1n1: data          &lt;- empty, safe to format<\/span>\n\n<span class=\"hljs-comment\"># Create a filesystem (xfs is the default on Amazon Linux and RHEL)<\/span>\nsudo mkfs -t xfs \/dev\/nvme1n1\n<span class=\"hljs-comment\"># or: sudo mkfs -t ext4 \/dev\/nvme1n1<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Create the mount point, mount the volume once, and read its UUID:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">sudo mkdir -p \/data\nsudo mount \/dev\/nvme1n1 \/data\n\nsudo blkid \/dev\/nvme1n1\n<span class=\"hljs-comment\"># \/dev\/nvme1n1: UUID=\"1b2c3d4e-5f60-4a7b-8c9d-0e1f2a3b4c5d\" BLOCK_SIZE=\"512\" TYPE=\"xfs\"<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Back up <code>\/etc\/fstab<\/code> as shown above, then add the entry. Using <code>tee -a<\/code> appends the line and avoids the common mistake of overwriting the file with <code>&gt;<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">sudo cp \/etc\/fstab \/etc\/fstab.bak\n<span class=\"hljs-keyword\">echo<\/span> <span class=\"hljs-string\">'UUID=1b2c3d4e-5f60-4a7b-8c9d-0e1f2a3b4c5d  \/data  xfs  defaults,nofail  0  2'<\/span> | sudo tee -a \/etc\/fstab<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Test the fstab entry properly before rebooting<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><code>sudo mount -a<\/code> on its own doesn&#039;t prove anything if the volume is already mounted, because it skips filesystems that are already mounted. Unmount the volume first so that <code>mount -a<\/code> actually tests the new line:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Unmount the volume: <code>sudo umount \/data<\/code><\/li>\n\n\n<li>Tell systemd to reread fstab: <code>sudo systemctl daemon-reload<\/code>. Without this, newer <code>mount<\/code> versions warn that systemd still uses the old version of the file.<\/li>\n\n\n<li>Check the syntax and the devices: <code>sudo findmnt --verify<\/code>. It reports unknown UUIDs, missing mount points and bad filesystem types.<\/li>\n\n\n<li>Mount everything from fstab: <code>sudo mount -a<\/code>. No output means success.<\/li>\n\n\n<li>Confirm the mount: <code>df -hT \/data<\/code><\/li>\n\n\n<li>Reboot (<code>sudo reboot<\/code>), reconnect and run <code>df -hT \/data<\/code> again.<\/li>\n<\/ol>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">df -hT \/data\n<span class=\"hljs-comment\"># Filesystem     Type  Size  Used Avail Use% Mounted on<\/span>\n<span class=\"hljs-comment\"># \/dev\/nvme1n1   xfs    20G  175M   20G   1% \/data<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Corrections to the original steps<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The example above uses <code>\/dev\/xvdf<\/code> as the device. That name only exists on older Xen-based instance types. On Nitro instances the volume is <code>\/dev\/nvme1n1<\/code> or similar, and NVMe names are assigned in the order devices are detected, so they can change between boots or when volumes are added. An fstab line that points at the wrong name will either fail or mount the wrong disk. Use the UUID instead:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\"># Original (fragile)<\/span>\n\/dev\/xvdf       \/newvolume   ext4    defaults,nofail        <span class=\"hljs-number\">0<\/span>       <span class=\"hljs-number\">0<\/span>\n\n<span class=\"hljs-comment\"># Corrected (stable across reboots and instance types)<\/span>\nUUID=<span class=\"hljs-number\">1<\/span>b2c3d4e<span class=\"hljs-number\">-5<\/span>f60<span class=\"hljs-number\">-4<\/span>a7b<span class=\"hljs-number\">-8<\/span>c9d<span class=\"hljs-number\">-0e1<\/span>f2a3b4c5d  \/newvolume  ext4  defaults,nofail  <span class=\"hljs-number\">0<\/span>  <span class=\"hljs-number\">2<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Setting the last field to <code>2<\/code> lets ext4 volumes get a filesystem check at boot, after the root filesystem. For xfs the check does nothing, so <code>0<\/code> and <code>2<\/code> behave the same. The original also leaves out the steps that make the entry work: formatting the volume, creating the mount point directory and finding the UUID. These are covered in the procedure section.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Troubleshooting<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Symptom<\/th><th>Likely cause<\/th><th>Fix<\/th><\/tr><\/thead><tbody><tr><td>Instance doesn&#039;t come back after reboot, or the console log shows emergency mode<\/td><td>Bad fstab line without <code>nofail<\/code>, or a typo in the UUID<\/td><td>Use the EC2 Serial Console to fix <code>\/etc\/fstab<\/code>. Alternatively, stop the instance, attach its root volume to a rescue instance, edit the file and reattach it.<\/td><\/tr><tr><td><code>mount: wrong fs type, bad option, bad superblock<\/code><\/td><td>Volume was never formatted, or the type field doesn&#039;t match<\/td><td>Run <code>sudo file -s \/dev\/nvme1n1<\/code> and set the type field to match<\/td><\/tr><tr><td><code>mount point \/data does not exist<\/code><\/td><td>Directory not created<\/td><td><code>sudo mkdir -p \/data<\/code><\/td><\/tr><tr><td>xfs volume from a snapshot won&#039;t mount: duplicate UUID<\/td><td>Snapshot of a disk that is already mounted on the same instance<\/td><td>Mount once with <code>-o nouuid<\/code>, or give it a new UUID with <code>sudo xfs_admin -U generate \/dev\/nvme2n1<\/code> while it is unmounted<\/td><\/tr><tr><td>Volume is empty after a reboot<\/td><td>Data was written to <code>\/data<\/code> before it was mounted, so it landed on the root disk<\/td><td>Check with <code>findmnt \/data<\/code> before writing data, and keep the mount point directory empty<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note:<\/strong> When you mount the root volume of an instance on a rescue instance built from the same AMI, xfs may refuse because of a duplicate UUID. Use <code>sudo mount -o nouuid \/dev\/nvme1n1p1 \/mnt<\/code> there.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Best practices<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Always reference the volume by <code>UUID=<\/code> (or <code>LABEL=<\/code>), never by <code>\/dev\/xvdf<\/code> or <code>\/dev\/nvme1n1<\/code>.<\/li>\n\n\n<li>Always include <code>nofail<\/code> for non-root EBS volumes so that a detached or failed volume doesn&#039;t block boot.<\/li>\n\n\n<li>Run <code>findmnt --verify<\/code> after every edit to fstab, and keep the backup copy until the reboot test passes.<\/li>\n\n\n<li>Set ownership after mounting, for example <code>sudo chown ec2-user:ec2-user \/data<\/code>. Permissions belong to the mounted filesystem, not to the empty directory underneath it.<\/li>\n\n\n<li>After increasing the volume size in AWS, grow the filesystem online with <code>sudo xfs_growfs \/data<\/code> or <code>sudo resize2fs \/dev\/nvme1n1<\/code>. The fstab entry doesn&#039;t need to change because the UUID stays the same.<\/li>\n\n\n<li>Turn on EBS encryption when you create the volume. It is transparent to the OS and needs no fstab changes.<\/li>\n\n\n<li>For fleets or Auto Scaling groups, script these steps in user data or an AMI instead of editing each instance by hand.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Frequently asked questions<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Does the fstab entry still work after stopping and starting the instance?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. Stop\/start is just a reboot as far as fstab is concerned, as long as the volume stays attached. Because the entry uses the UUID, it works even if the instance moves to a Nitro type and the device name changes.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">What does the nofail option do in \/etc\/fstab?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">It tells systemd to continue booting if the device is missing or fails to mount. Without it, a detached EBS volume or a wrong UUID can drop the instance into emergency mode and leave it unreachable over SSH.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Will the UUID change if I take a snapshot or resize the volume?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Resizing doesn&#039;t change the filesystem UUID. A volume created from a snapshot has the same UUID as the original, which can conflict if both are attached to the same instance. Only running mkfs again, or changing the UUID on purpose, generates a new one.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How do I find which NVMe device matches my EBS volume ID?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Run <code>ls -l \/dev\/disk\/by-id\/<\/code>. EBS NVMe devices appear as <code>nvme-Amazon_Elastic_Block_Store_vol...<\/code> links that include the volume ID. On Amazon Linux, <code>sudo ebsnvme-id \/dev\/nvme1n1<\/code> also prints the volume ID and the requested device name.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Should I use xfs or ext4 for an EBS data volume?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Both work well. xfs is the default on Amazon Linux and RHEL and can be grown online but not shrunk. ext4 is the Ubuntu default and supports offline shrinking. Pick the one your team already knows how to manage.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Related tutorials<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.devopsschool.com\/blog\/category\/cloud-computing\/aws\/\">More AWS tutorials<\/a><\/li>\n\n\n<li><a href=\"https:\/\/www.devopsschool.com\/blog\/category\/operating-systems\/linux\/\">More Linux tutorials<\/a><\/li>\n\n\n<li><a href=\"https:\/\/www.devopsschool.com\/blog\/how-to-login-to-linux-server-using-putty\/\">How to Login to Linux Server using Putty?<\/a><\/li>\n\n\n<li><a href=\"https:\/\/www.devopsschool.com\/blog\/aws-tutorials-auto-scaling-group\/\">AWS Tutorials: Auto Scaling Group<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>To make an extra Amazon EBS volume mount automatically after an EC2 Linux instance reboots, add an entry for it to \/etc\/fstab. Refer to the volume by&#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[5633,4957],"tags":[3400,3354,26310],"class_list":["post-30009","post","type-post","status-publish","format-standard","hentry","category-aws","category-linux","tag-amazon-ebs","tag-amazon-ec2","tag-linux-disk-management"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/30009","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=30009"}],"version-history":[{"count":2,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/30009\/revisions"}],"predecessor-version":[{"id":80672,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/30009\/revisions\/80672"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=30009"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=30009"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=30009"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}