Block Volume provides network storage to use with your Oracle Cloud compute instances. After you create, attach, and mount a volume to your instance, you can use it just as you would a physical hard drive on your computer. A volume can be attached to a single instance at a time, but you can detach it from one instance and attach it to another instance, keeping your data intact.
In this blog, we will cover the steps to attach Block Volume to an existing OCI compute instance.
Prerequisites:
- An Oracle Cloud free trial or paid account
- OCI Virtual Cloud Network (VCN)
- OCI compute instance located in a VCN’s private subnet or public subnet with API RSA private key
Step #1: Create a Block Volume
1. Open the navigation menu and click “Storage”. Under “Block Storage”, click “Block Volumes”

2. Click “Create Block Volume”.

3. In the “Create block volume” dialog window, enter the volume name, and select compartment and availability domain. Under the “volume size and performance” section, select the “custom” option and specify the block volume size. Leave all other options as default and click “Create Block Volume”


Once you create volume, new block volume information will be as shown below

Step #2: Attach Volume to OCI Compute Instance
1. Enable Block Volume Management Cloud Agent: Open the navigation menu and click Compute. Under Compute, click Instances. Click your compute instance name to view its details. Navigate to the “Oracle Cloud Agent” tab page and enable the “Block Volume Management” plugin

2. Open the navigation menu and click “Storage”. Under “Block Storage”, click “Block Volumes”. Click your block volume name to view its details. Under the “Resources” section, click “Attach Instances”, then click “Attach to Instance”

3. In the “Attach to instance” dialog window, select “Attachment type” – ISCSI (default), “Access Type” – Read/Write (default). Under the “Instance” section, select compute instance tick option “Use Oracle Cloud Agent to automatically connect to ISCSI-attached volumes”, then click “Attach”

Note: block volume will be automatically attached to compute instance, so there is no need to run ISCSI Commands

1. SSH to your compute instance (you can use cloud shell to access the instance). Run “lsblk” Linux command to get the list of volumes/devices. In this example, the device path is “/dev/sdb”

2. Create a new device partition using “fdisk” Linux command as shown below


3. Format a new device partition using “mkfs” Linux command as shown below

4. Mount a new partition using the “mount” Linux command as shown below.

5. Permanently mount the device by adding the below entry to “/etc/fstab” file

Now block volume is permanently available in OCI compute instance for read/write access!