Volumes provide persistent block storage that can be attached to instances for storing data independently of the instance lifecycle. This makes them ideal for scenarios where you need to maintain critical data even after instances are deleted or replaced. Volumes can be reused and mounted across multiple instances, providing flexibility and durability for your storage needs.In this guide, we will cover how to create a volume, attach it to an instance, and verify that it is mounted via the Shadeform API. This process involves creating a volume first, launching an instance with the volume attached, and confirming the volume on the instance.Currently, volumes can only be attached to instances in the same cloud provider and region. Multi-cloud volumes are an upcoming feature.
Step 3: Create an Instance with the Volume Attached
To attach the volume, pass its id in the volume_ids field while creating the instance using the /instances/create endpoint.
“volume_ids” must be an array of size one. This is because we only allow attaching one volume to one instance right now. Attaching multiple volumes to a single instance is a feature we will add in the future.
# Create an instance with the volume attachedcurl --location 'https://api.shadeform.ai/v1/instances/create' \--header 'x-api-key: <api-key>' \--header 'Content-Type: application/json' \--data '{ "cloud": "digitalocean", "region": "tor1", "shade_instance_type": "H100_sxm5", "shade_cloud": true, "name": "the-super-cool-digitalocean-server-volume", "volume_ids": ["b1f2c5d3-29ab-4e7b-9f7e-2c35a1e34d4e"] # be sure to include this line}'
Example ResponseThe response will include the id for the instance and a cloud_assigned_id. Save this for further operations.
Once the instance is active, SSH into it to verify that the volume has been mounted. Learn how to SSH into a Shadeform instance using this guide.After connecting, run the following command:
# List all block devices attached to the instancelsblk
Your output should look something similar to this:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTSloop0 7:0 0 63.9M 1 loop /snap/core20/2318loop1 7:1 0 87M 1 loop /snap/lxd/28373loop2 7:2 0 38.8M 1 loop /snap/snapd/21759loop3 7:3 0 44.3M 1 loop /snap/snapd/23258loop4 7:4 0 63.7M 1 loop /snap/core20/2434vda 252:0 0 128G 0 disk├─vda1 252:1 0 127.9G 0 part /├─vda14 252:14 0 4M 0 part└─vda15 252:15 0 106M 0 part /boot/efivdb 252:16 0 50G 0 disk # this is the volume I mountednvme0n1 259:0 0 894.3G 0 disk
This command will display all block devices attached to the instance. You should see your volume listed as a new device, such as vdb, sbd, or similar.
After verifying the volume is attached, you can mount it to a file system. Find your volume from the lsblk command (my volume is called vdb in this example) and mount it to a directory using the following commands:
Before you can delete a volume, you must delete the instance it is attached to.Delete the InstanceUse the /instances/delete endpoint to remove the instance.
# Delete the instancecurl --location 'https://api.shadeform.ai/v1/instances/<instance-id>/delete' \--header 'x-api-key: <api-key>'
Replace <instance-id> with the id of your instance.Delete the VolumeOnce the instance has been deleted, you can safely delete the volume using the /volumes/delete endpoint.
# Delete the volumecurl --location 'https://api.shadeform.ai/v1/volumes/<volume-id>/delete' \--header 'x-api-key: <api-key>'
You have successfully created a volume, attached it to an instance, verified the attachment, and learned how to clean up resources. For more details, check out the Shadeform API reference.