Customizing Ephemeral Drive Mounting and Configuration via Cloud-Init
Ephemeral drives provide temporary storage for active workloads during a VM’s runtime. The mounting behavior of ephemeral drives can be customized at the time of VM creation by passing a cloud-init configuration file. This guide covers different ways to handle ephemeral drives using cloud-init, including mounting to custom locations, changing the filesystem format, or disabling the mount entirely. For more details on ephemeral storage, see this article.
Mounting ephemeral drive to a custom location
By default, ephemeral drives are mounted under /ephemeral
. To mount them elsewhere follow these steps:
-
Navigate to the Deploy a new virtual machine page in the Hyperstack console.
-
Set up your VM with the desired specifications, then scroll to the bottom of the page and click Configure Additional Settings.
-
In the Cloud-init Script section, select YAML syntax format. Then, paste the following
cloud-init
configuration, replacing/your/custom/path
to any directory path where you'd like to mount the ephemeral drive (e.g./var/opt
):#cloud-config
mounts:
- [ephemeral0, /your/custom/path] -
Deploy your VM and the ephemeral drive will be mounted to the custom directory during creation.
Changing filesystem format and mount location
To format the ephemeral drive with a different filesystem (e.g., xfs
) and mount it to a custom location (e.g., /data
), follow the steps outlined here but modify the configuration file as follows:
#cloud-config
disk_setup:
ephemeral0:
table_type: "gpt"
layout: true
overwrite: True
fs_setup:
- label: ephemeral0
filesystem: xfs
device: "ephemeral0"
partition: "auto"
overwrite: True
mounts:
- [ephemeral0, /data, xfs]
This mounts the ephemeral drive under /data and uses the xfs filesystem.
Choosing not to mount the ephemeral drive
To prevent the ephemeral drive from being mounted, follow the steps outlined in Hyperstack here but modify the configuration file as follows:
#cloud-config
mounts:
- [ephemeral0, null]
Using the API to manage ephemeral mounting
-
Save your cloud-init configuration content, as defined in the examples above, in a file (e.g.,
user-data.txt
). You can also use a bash script, as shown in the example below.cat << EOF > user_data.txt
#cloud-config
disk_setup:
ephemeral0:
table_type: "gpt"
layout: true
overwrite: True
fs_setup:
- label: ephemeral0
filesystem: xfs
device: "ephemeral0"
partition: "auto"
overwrite: True
mounts:
- [ephemeral0, /data, xfs]
EOF -
Use the file in the
user_data
field of the Create Virtual Machine API request. You can refer to the API documentation for details on how to automate VM creation with this configuration. See an example API call below.# First convert the user data to a single line JSON string
user_data_content=$(jq -Rs '.' < user_data.txt)
# Then use the API to create a VM with the user data
curl --location 'https://infrahub-api.nexgencloud.com/v1/core/virtual-machines' \
--header 'Content-Type: application/json' \
--header "api_key: $HYPERSTACK_API_KEY" \
--data '{
"name": "ephemeral-mount-example",
"environment_name": "default-CANADA-1",
"image_name": "Ubuntu Server 22.04 LTS R550 CUDA 12.4 with Docker",
"flavor_name": "n3-A100x1",
"key_name": "default-CANADA-1-key",
"count": 1,
"assign_floating_ip": true,
"user_data": '"$user_data_content"'
}' -
Check the mount location and filesystem format of the ephemeral drive on the VM after creation.
lsblk -f
Below is an example of the expected output (output may vary slightly based on the configuration):
NAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINTS
[.. truncated ..]
vdb
└─vdb1
xfs ephemeral0 aefb82e5-f27c-4b33-9d58-b65eb32ffd35 744.4G 1% /data