Volumes
Volumes are one or more drives you can attach to an instance.
Create Volume
A volume can be created using ops volume create <vol_name>
.
You can specify the volume size with the flag -s
. The values should respect the next examples format.
If you have a directory in your filesystem which you want to access in the unikernel you can use the flag -d
. Ops will create the volume and copy the directory files to the volume filesystem.
Combining the previous flags a command with the next format.
Someone who needs to create a volume to host 9.6 GigaBytes of assets can use the volume create command the next way.
You can check the existing ops volumes with ops volume list
.
Volume Content listing (on-prem)
To display the tree
output of local (on-prem) volume, use ops volume tree <volume_name:volume_uuid>
To display a ls
style listing of files in a local (on-prem) volume, use ops volume ls <volume_name:volume_uuid> [<path>]
Volume Content copy (on-prem)
To recursively copy the content of a local (on-prem) volume, use ops volume cp <volume_name:volume_uuid> <src>... <dest>
Volume info from raw files (on-prem)
To get some volume information about label
/uuid
from a raw volume file, use ops volume info <volume_file_path>
Setup Mount Path
Mounting a volume in an instance requires an image to know beforehand which volumes it should expect and the directories where the volumes will be mounted. The unikernel recognizes the volume by its name/label, UUID, or virtual id. The virtual id may be used when you wish to have the same volume name or mount a different volume with a different volume name to the same mount point. The virtual id syntax is currently supported on GCP, Azure and AWS.
You can specify mounts details using the command flag or the configuration file.
Using configuration file, you have to set the Mounts
property.
And, then you can use the configuration file on creating the image.
If you want to test quickly you can also use the mounts
command flag instead.
The mounts must be specified on creating an image. All commands that require to build an image accept the mounts details.
Attach
If your image was created with the mounts details specified and you would like to attach a volume to a running instance use next command.
Locally you can attach volumes at instance boot using --mounts with ops run
, ops pkg load
, or ops instance create
.
If you wish to dynamically attach and detach volumes locally you'll need to create the instance with QMP support enabled:
You should note that this opens a local mgmt port that uses the instance id's last 4 digits as the port. (This is only for local hotplug.)
Detach
You can detach a volume from one instance using ops detach <instance_name> <volume_name>
Read Only
You can set a volume as read-only in your manifest like this:
or if you are passing via the cli flags:
If you wish to make the root/base volume readonly you can do so by passing the manifest config like so:
Note: Read-only in this context applies to the actual volume mount not user filesystem access as Nanos doesn't have the notion of users.
Cloud Providers
All mounting volumes requirements applies to the cloud providers.
Ops uses cloud providers APIs to execute volumes operations on their infrastructure.
The commands format is the same, we just need to add the target cloud provider flag.
You can create arbitrarily large empty volumes on providers such as AWS by specifying the requested size. AWS will re-size the volume to whatever you set it as.
Sometimes it might be helpful to know when a volume is attached and detached at run-time as AWS supports attaching/detaching volumes at run-time.
You can look at the pseudo-file of /proc/mounts
to determine whether or not the volume is available. For instance:
Using this config file:
and this program:
Hot-Plugging Support
OPS supports hot-plugging volumes on GCP, AWS, Azure, and onprem allowing you to, at runtime, attach and detach volumes and mount/unmount filesystems.
Today there is no support for hot-plugging virtfs shares, however, since it is a share one can simply change the contents on the host.
Accessing host filesystem from nanos guest using 9p
When running onprem
, Ops
contains logic to detect whether a mount directive is for a host directory (as opposed to a pre-made volume), and set up the configuration so that:
Qemu properly exports the directory as a virtfs share, and
the guest can mount that share as a 9P filesystem.
You can run multiple virt-fs shares locally.
sample go http server
build
my_server
binary
create host folder to be shared with guest
config.json
ops config file
run
ops
withconfig.json
file
or run
ops
without usingconfig.json
file
modify content on the host and check that guest has the updates available
One can use virtual identifiers on virt-fs shares, to for instance build images on a different host and use them elsewhere:
imgcreate.json:
However, at instance creation time you still need to provide the host mount point using a different configuration:
Read more in our 9p tutorial
Wrap-up
Mounting volumes require us to create an image with the mounts details, launch an instance using the image and attaching a volume. Locally, you are able to mount a volume with 2 commands.
As mentioned above you can mount multiple volumes with the config.json or pass multiple mounts flags like so:
See an example in our tutorial.
Last updated