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:
Later I format the partition:
[ec2-user ~]$ sudo mkfs.ext4 -E nodiscard /dev/xvdf
Created the directory:
mkdir /mnt/mydisk
The mount it:
sudo mount -o discard /dev/xvdf /mnt/mydisk
Also I added it to the fstab:
/dev/xvdf /mnt/mydisk ext4 defaults,nofail,discard 0 2
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