Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detach root volume of ec2 instance

I am using a spot instance to do some work and to preserve the data, I am remounting a previously existing volume as the root volume of my current instance. So the root volume that the instance started with is no longer in use and I wanted to remove it to save costs.

I have unmounted the previous root volume and tried detaching it from the cli with and without the --force param and both ends in failure with this error :

An error occurred (IncorrectState) when calling the DetachVolume operation: Unable to detach root volume 

I realize that this would be because aws mounts the initial root in xv/s da1 and aws prevents me from detaching it.

Are there any steps that I can follow to detach the unmounted root volume ?

like image 490
nnrales Avatar asked Oct 28 '25 12:10

nnrales


1 Answers

No, there isn't. Detaching the root volume requires that the instance be stopped, and spot instances can't be stopped.

to preserve the data, I am remounting a previously existing volume as the root volume of my current instance.

That's not really the correct thing to be doing. Spot instances are inherently ephemeral, and reusing the root volume is not an intended action.

Using Elastic File System, if it is available in your region, is ideal for this. An EFS filesystem mounts into your hierarchy wherever you need it, someplace like /srv/data for example, and these can also be mounted simultaneously to multiple instances.

S3 can also be used, though your code has to be written with this in mind.

Alternately, save your work on an EBS volume that isn't the root volume if you want to move volumes around.

like image 98
Michael - sqlbot Avatar answered Oct 30 '25 05:10

Michael - sqlbot



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!