0

I'm having trouble mounting a newly created volume (general purpose SSD - gp2) of 100GB in an EC2 instance. I attach a newly created volume to an AWS instance through the AWS console. Now i search for the volume in the command line using

lsblk

which returns the following information

xvdf 202:80 0 100G 0 disk

Now when I try to mount the volume onto a directory

sudo mount /dev/xvdf /data

I get the following error

mount: /data: wrong fs type, bad option, bad superblock on /dev/xvdf, missing codepage or helper program, or other error.

Using the solution mentioned here, when I do

sudo mount /dev/xvdf1 /data -t ext4

However, I'm able to mount but when I try to create a folder mkdir temp, I get the following error

mkdir: cannot create directory ‘temp1’: Permission denied

rambalachandran
  • 2,091
  • 2
  • 19
  • 34

3 Answers3

3

The inability to create files and folders are related to bad permissions. Doing the two following steps worked for me.

  1. Creating a linux file system with mkfs preferably ext4. However this can result in data loss, so please backup data before trying this on a volume with existing data.

    sudo mkfs -t ext4 /dev/xvdf

  2. In order to solve the permissions problem change ownership of the mounted location (/data) to the login username that is used to ssh into the machine. This is typically ubuntu for most linux machines in EC2. Execute the following command after mount.

    sudo chown -R ubuntu:ubuntu /data

This solves the mount and permission issues and I'm able to mount, unmount and create files multiple times across different machines within the same sub-region.

rambalachandran
  • 2,091
  • 2
  • 19
  • 34
1

You are missing a step to create file system, it should work like this - run as root user.

mkfs.ext4  /dev/xvdf
mount /dev/xvdf /data
echo '/dev/xvdf /data ext4    defaults        0 0' >> /etc/fstab

You don't need to set any permission on /data.

Mohammad Ghonaim
  • 385
  • 2
  • 10
0

Based on the answer The reason you are getting error is due to ownership of directories.and creation of the filesystem on newly created volume.How i solve this was

  1. lsblk to view available disk spaces and their mount poins
  2. sudo file -s /dev/xvdf file -s command to get information about a device, such as its file system type. data tells there is no fs
  3. sudo mkfs -t xfs /dev/xvdf this is imp to create filesystem on available volume
  4. sudo mkdir /data # to create mount point
  5. sudo mount /dev/xvdf /data to mount your volume

Review the file permissions of your new volume mount to make sure that your users and applications can write to the volume

*The mount point is not automatically preserved after rebooting your instance. To automatically mount this EBS volume after reboot, you need to fstab configuration file

Refer for further clarity here

Jatin Mehrotra
  • 9,286
  • 4
  • 28
  • 67