0
votes

Creating a file into a volume in order to reuse it in different instances but it does not working.

Creating a simple file in the volume in the first instance.

I was testing something pretty easy on Amazon Web Services (AWS). I was using or testing Elastic Block Store (EBS) and my test was about create a simple volume and attached it to an instance. In this volume I created a single file. Later I stopped the instance and then detached the volume.

Attaching/Formatting/Mounting

Using the AWS Console create a new volume and later attach it to the instance. It is not to complex process. I did these steps:

  1. Later I format the partition:

    [ec2-user ~]$ sudo mkfs.ext4 -E nodiscard /dev/xvdf

  2. Created the directory:

    mkdir /mnt/mydisk

  3. The mount it:

    sudo mount -o discard /dev/xvdf /mnt/mydisk

  4. Also I added it to the fstab:

    /dev/xvdf /mnt/mydisk ext4 defaults,nofail,discard 0 2

  5. I create a simple file in mydisk device:

    echo "saving data" > mydisk.log

Finally I stopped the instance and detached the volume.

Creating a new instance and attach/mount the volume

I created a new instance and attached the volume to it but the file is not there (see above steps 2 and 3). So I don't know what is the problem. I think that the file should be there.

What do I think

I think when you create an EBS you can reuse it in other instances. But in my case that is not possible or I am doing something wrong. Also if you have any idea or option will be amazing.

Extra Info

  • I am using a free tier t2.small.
  • The OS is AWS Linux AMI.
  • The EBS storage is general purpose, 1 GB, 100/3000 I/O
1
It would be easier to help if you included relevant information like the OS you're using, how you're detaching/attaching/mounting the volume, etc. As the answer notes, this is a known operation and most people have no problem with it.Karen B
@KarenB thank you for your feedback, let me know if you need more information.Robert

1 Answers

0
votes

Yes, this is a valid, supported, "people do it all the time" operation.

You missed a step somewhere in the process, or perhaps you weren't looking in the correct place on the new instance.

If the instance was stopped when you detached the volume, that removes the only possible "obvious" thing that can go wrong, which would be that you detached the volume in an inconsistent state because it was still mounted by the operating system on the original instance -- but this is impossible if the original instance was stopped when you detached the volume.