4. Create and Manage Volumes¶
Volumes are block storage devices that you attach to instances to enable persistent storage. You can attach a volume to a running instance, or detach a volume and attach it to another instance at any time. You can also create a snapshot from a volume or delete it. Only administrative users can create volume types.
Refer to the following directions for various tasks involving volumes (and/or to the Training Handout):
-
Using Volumes
-
First-time use of a volume:
- A new volume may not have yet a filesystem (e.g., if you chose "no source; empty volume" when you created the volume). In this case, you need to format the volume before you can use it. Important: to find the device under which a volume is attached to, go to the Instances tab in the dashboard and open the manage attachments dialog of your volume (otherwise try
sudo parted -l
from within the VM). The following commands are examples for an instance running an Ubuntu operating system (the exact command syntax is dependent on the instances' operating system and the type of filesystem you require). We also assume that the volume is attached via the path/dev/vdb
. To set the filesystem, use:$ sudo mkfs.ext4 /dev/vdb
- Once the volume has a file system, mount it using:
$ sudo mount /dev/vdb /mnt
- To get non-root access to the file system, you may need to change the user (on an Ubuntu image, the default username is "ubuntu")
$ sudo chown ubuntu:ubuntu -R /mnt
- You can check whether the volume has mounted using the
lsblk
command.
- A new volume may not have yet a filesystem (e.g., if you chose "no source; empty volume" when you created the volume). In this case, you need to format the volume before you can use it. Important: to find the device under which a volume is attached to, go to the Instances tab in the dashboard and open the manage attachments dialog of your volume (otherwise try
-
Subsequent use:
- Once a volume has a file system and the user rights have been set, you generally only need to mount the volume when the VM starts:
$ sudo mount /dev/vdb /mnt
- Once a volume has a file system and the user rights have been set, you generally only need to mount the volume when the VM starts:
-
When finished with a volume:
- Before detaching a volume, unmount it from the VM using:
$ sudo umount /mnt
- Before detaching a volume, unmount it from the VM using:
-
Other uses:
- If you want the filesystem to be auto-mounted whenever the VM boots consider changing the "/etc/fstab" file (or equivalent for your operating system), which specifies devices and mount points and whether to mount them automatically, via the directions in this How-to article on the topic.
-
-
Detach a volume from an instance
- Note: Volumes must be unmounted from within the instance before being detached. If this is not done, the consequence is that the instance could freeze as soon as it tries to do any operation on the mounted (but detached) volume.
-
- Note: Volumes must be detached from an instance before they can be deleted.