05 ‐ Creating and attaching Block Volume - SanjeevOCI/Ocidocs GitHub Wiki

Steps to create a Block Volume & attach to a OCI Compute Instance

1. Creating a Block Volume

  1. Navigate to Burger Menu --> Storage --> Block Volumes --> Create Block Volume

Block_Volume_Creation_1

Block_Volume_Creation_2

  1. Enter the details - Block Volume Name, Compartment Name, Availability zone etc and click on "Create Block Volume". Note :- Please ensure to create the Block volume in the same Compartment and Availability zone as the compute instance, so that it can be added to it.

Block_Volume_Creation_3

Block_Volume_Creation_4

Block_Volume_Creation_5

Block_Volume_Creation_6

  1. New Block Volume has been created

Block_Volume_Creation_7


2. Attaching a Block Volume to a Compute Instance

  1. Click on the newly created Block Volume --> Select "Attached Instance" option On the left side --> Click on "Attach to Instance" --> Select Instance Name and click "Attach" --> Block volume is now attached to the Instance

Block volume creation successful_1 Block volume creation successful_2 Block volume creation successful_3

  1. Navigate to Burger Menu --> Compute --> Instances --> Click on the Instance where the Block Volume was attached --> Go to "Attached Block Volumes" --> The added Block volume can be seen

Block volume creation successful_4


3. Reflecting the Block Volume in the server

  1. After the Block Volume had been attached, Login to the server through Putty, in order to update the new volume in the server.

  2. Run lsblk command to check the existing volumes in the server.

Exsiting volumes in the Server

  1. Go to three dots --> iSCSI commands & information and Copy the connect command.

Attach Block Volume to Instance_5

Attach Block Volume to Instance_6

  1. Execute the copied commands in the server

Attach Block Volume to Instance_7

After this when we check, we see one new volume is created

Attach Block Volume to Instance_8

Run “df –h” command to check if this volume is showing or not.

Attach Block Volume to Instance_9

As the volume is still not showing, we need to mount this volume to be ready to be used.


4. Create a new partition

  1. Formatting the Disk

Run “fdisk /dev/sdb” command , and type m for help

fdisk /dev/sdb

  1. Type “n” to create a new partition.

Attach Block Volume to Instance_New Partition


4. Create a Physical Volume

  1. Run "pvcreate /dev/sdb1" to create the physical volume

pvcreate /dev/sdb1

  1. Run "pvdisplay /dev/sdb1" to display the physical volume created

pvdisplay /dev/sdb1

Create and Dispaly Physical Volume


5. Create a Volume Group

  1. Run "vgcreate vg_u01 /dev/sdb1" to create the volume group
vgcreate vg_u01 /dev/sdb1
  1. Run “vgdisplay vg_u01” to display the volume group created and to see the Number of Physical Extent.

vgdisplay vg_u01

Create and Display Volume Group


6. Create a logical volume and map it to our volume group

  1. Run the below commands to create the logical volume

lvcreate -l 12799 -n lv_u01 vg_u01

ls -l /dev/mapper/vg_u01-lv_u01

  1. Logical volume is now created inside our volume group

Create a logical volume and map it to our volume group


7. Format this logical volume using a file system

mkfs.ext4 /dev/mapper/vg_u01-lv_u01

Format Logical Volume


8. Create a Directory to mount the logical volume

  1. Run the below commands to mount the logical volume

mkdir /u01

mount -t ext4 /dev/mapper/vg_u01-lv_u01 /u01

  1. Now we are able to see that the logical volume is mounted.

Create directory and mount the logical volume


9. Mount the volume permanently in /etc/fstab or else it will get removed after the server reboots.

  1. Add the line below in /etc/fstab

/dev/mapper/vg_u01-lv_u01 /u01 ext4 defaults,_netdev,nofail 0 2

mount volume permanently in etc fstab

  1. Run the command "systemctl daemon-reload" to mount this volume premanently

systemctl daemon-reload

Run mount command