Reputation: 10953
Creating a file into a volume in order to reuse it in different instances but it does not working.
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.
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.
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.
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.
Upvotes: 0
Views: 278
Reputation: 179364
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.
Upvotes: 0