5. Creating and attaching Block Volume - Ayushi-srivastav/OCI GitHub Wiki

Step 1 : Create Block volumes in OCI

  1. Browse the Block Volume

Click on the Burger Menu in left side, select storage than go to the Block volumes

image

  1. Click on create Block Volume

image

  1. Fill all the required fields to create Block volume

    (a) Enter Block Volume name

    (b) Select compartment

    (c) select Availability domain (AD must be same as instance)

    (d) enter volume size

image

image

(e) choose backup policy

image

(f) select cross region replication

(g) select volume encryption

and click on create block volume

image

Now, Block volume is created

image

Step 2 : Attach Block volumes in OCI

  1. Scroll down on the created block volume page. On the right side, you'll see an option for attached instances.

    Click on that, then click on Attach to Instance

image

  1. Select Attachment type &

    access type

image

  1. Select the instance within the specific compartment

    where you want to attach the block volume

Than, click on the attach

image

Step 3 : Attach Block Volume via Putty

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

image

  1. To attach new volume,open that particular attached BV in OCI

Go to three dots

select iSCSI commands & information

image

Copy the connect command

image

Run these commands in the server

image

After this

again Run lsblk command to check whether new volume is created or not

lsblk

we can check , one new volume is created

image

We can run df –h command to check if this volume is showing or not

df -h

image

It is still not showing so now we have to mount this volume to be ready to be used.

Step 4 : Mounting Block Volumes for Immediate Use

  1. Create a new partition

Format the Disk

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

fdisk /dev/sdb

image

image

Type “n” to create a new partition

select default and type "w"

image

image

  1. Create a Physical Volume
pvcreate /dev/sdb1

image

To display the physical volume created,

pvdisplay /dev/sdb1

image

  1. Create a Volume Group
vgcreate vg_u01 /dev/sdb1

image

Run “vgdisplay vg_u01” to display the volume group created and to see the Number of Physical Extent

vgdisplay vg_u01

image

  1. Create a logical volume and map it to our volume group
lvcreate -l 12799 -n lv_u01 vg_u01

image

The number 12799 represents the extent size in the volume group vg_u01. Each extent is typically 4MB, so this would create a logical volume of approximately 51.2GB (12799 extents * 4MB per extent).

to check the size of created lv run lsblk

lsblk

image

ls -l /dev/mapper/vg_u01-lv_u01

image

Logical volume is created inside our volume group.

  1. Format this logical volume using a file system
mkfs.ext4 /dev/mapper/vg_u01-lv_u01

image

Create a Directory and mount the logical volume “mkdir /u01”

and mount ext4 file system

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

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

image

image

image

image

Now we can see the logical volume is mounted.

  1. Mount this volume permanently in /etc/fstab or else after server reboot this volume will be removed.
vi /etc/fstab

image

add in last line of fstab file “/dev/mapper/vg_u01-lv_u01 /u01 ext4 defaults,_netdev,nofail 0 2”

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

and

:wq!

image

run mount –a command

mount -a

image

df -h

image

in last, reboot the server and again run df -h and check

df -h