Quickstart: Create and attach a volume
Create an empty volume, attach it to a Linux virtual machine, format and mount it in the operating system, and delete it again.
In this quickstart, you create an empty volume, attach it to a Linux instance, put a file system on it, and delete it again. The quickstart has 15 steps in four parts.
Before you begin
- You need the Owner or Contributor role, or a custom role with Manage access to Block & Object Storage, on the subscription or on the project.
- You need a running Linux instance in the project that you can sign in to over SSH. To create one, see Quickstart: Create a Linux virtual machine.
- The subscription's quota and the project's allocation need room for one more volume and 10 GB of volume storage.
Create and attach the volume
In the console, go to StorageVolumes.
Select Create volume.
In Volume name, enter a name such as data-01.
In Size (GB), enter 10.
Under Type, select a volume type. The list shows only the types that the region offers, with their price per GB-month.
Under Source, keep Empty volume.
In Attach to instance (optional), select your instance.
Select Create volume.
The console opens the new volume's page. When the volume is attached, its status is In use, and Device shows the device path that the cloud reported for it, such as /dev/vdb.
Format and mount the volume
Sign in to the instance over SSH. See Connect to a virtual machine.
List the block devices, and find the new disk. It has the size that you chose and no mount point.
lsblkCreate a file system on the new disk.
sudo mkfs.ext4 /dev/<device>Replace <device> with the disk's name from the lsblk output, such as vdb.
Caution
Creating a file system erases the disk. Check that <device> is the new, empty disk and not the OS disk or another data disk.
Create a mount point, and mount the disk on it.
sudo mkdir -p /mnt/data
sudo mount /dev/<device> /mnt/dataNote
This mount isn't kept when the instance restarts. To mount the volume at every boot, add an entry for it to /etc/fstab.
Verify
Check that the file system is mounted and has the expected size.
df -h /mnt/dataYou can now store data in /mnt/data. The data stays on the volume when you detach it or when the instance stops.
Clean up resources
A volume is billed for its size for as long as it exists, attached or not. Deleting it stops its billing.
On the instance, unmount the volume.
sudo umount /mnt/dataIn the console, on the volume's page, select Detach, and wait until the status is Available.
Select Delete, and select Delete again to confirm.