LAB 13 ‐ Create Block volume with Backup. - guptasanjeev-52/oci_docs GitHub Wiki

BLOCK VOLUME...

Block volume is a virtual hard disk (Storage) that you can attach to a compute instance (virtual machine) to store your Data.

Just like we connect an EXTERNAL HARD DRIVE to the computer to STORE FILES, in OCI you can attach a BLOCK VOLUME to a COMPUTE INSTANCE to store data, applications, databases and Backups (ROM OF THE COMPUTER).

1.) It stores files and Data.

2.) It can be ATTACHED or DETACHED from a compute instance.

3.) Data remains safe even if the compute instance is stopped or Restarted.

4.) You can increase its size whenever needed.

5.) One Instance can use Many Block Volumes but one block volume cannot be used by many Instances.

CREATING BLOCK VOLUME...

Firstly log in to the OCI and Click on The Burger Menu...

STORAGE >>>  BLOCK VOLUMES.

1.) On the Block volumes page click Create block volume...

2.) Page is opened Give a Name and Select the compartment...

3.) From the Availability domain dropdown select the same AD in which your compute instance resides...

4.) In the Volume size and performance section there are two options Default and Custom to customize the block volume select Custom which takes two inputs Volume size (in GB) and VPUs type.

Default..

Custom..

Volume size (in GB): ranges from 50 GB to 32 TB and volume performance varies with volume size

6.) Target volume performance: Represented in VPU (Volume Performance Unit) select a preferred option from the VPUs type dropdown or enable Performance based auto-tune which dynamically adjust the volume performance between VPUs specified for default and maximum.

7.) Choose backup policy...

GOLD POLICY ::- HIGHLY CHOOSED/APPLICABLE.

SILVER POLICY ::-

BRONZE POLICY ::-

8.) In the Cross ad/region replication section you can enable it and you can select region, AD, type Volume replica name, and select encryption from the sub section Cross region replica encryption but to access this replica you must have an instance in same region/AD. Instead of relying on tradition backups you can create up-to-date standby replicas for disaster recovery, geographical migrations, or business expansion but only if you are subscribed to multi-region then only you can replicate over other region.

9.) Finally click on Create block volume...

CREATED SUCCESSFULLY...


Attach Block Volume to an Instance in OCI...

BURGER MENU >>> STORAGE >>>  BLOCK VOLUMES

1.) Select the Right Compartment in which you have Created the Block Volume...

2.) Click on the block volume Name...

3.) Click on the ATTACHED INSTSANCES..

4.) Selecting the Attachment type...

5.) Selecting the Access type...

6.) Select the INSTANCE..

7.) Click Attach and it will ask you to run the block volume's ISCSI Command...


Attach Block Volume to an Instance via PuTTY

1.) Firstly , Open the PuTTY CONFIGURATION and check existing volumes in the server using lsblk (list block devices) this displays detailed information about all available storage devices...

lsblk

sda is a disk inside which there are three partitions sda1, sda2, and sda3

2.) To attach or detach run iSCSI commands in PuTTY terminal and to view iSCSI commands locate the instance in the list of Attached instances for a volume and click on three dots actions menu in the right and click on iSCSI IPv4 commands & information...

3.) To Attach a new block volume to an instance copy iSCSI attach command and paste into terminal....

4.) Verify attachment using lsblk command and also run df -h to check if it's mounted and you will see it's not mounted..


Mounting Block Volumes for Immediate Use...

        +---------------------------+
        |     Raw Block Device      |
        |   (/dev/sdb, /dev/nvme1)  |
        +-------------+-------------+
                      |
                      v
        +---------------------------+
        |     PV – Physical Volume  |
        |  (LVM metadata + PEs)     |
        +-------------+-------------+
                      |
                      v
        +---------------------------+
        |     VG – Volume Group     |
        |  (Storage pool of PVs)    |
        +-------------+-------------+
                      |
                      v
        +---------------------------+
        |     LV – Logical Volume   |
        | (Flexible virtual disk)   |
        +-------------+-------------+
                      |
                      v
        +---------------------------+
        |   Filesystem (ext4/xfs)   |
        | (Organizes files/dirs)    |
        +-------------+-------------+
                      |
                      v
        +---------------------------+
        |        Mount Point        |
        |   (/data, /mnt/backup)    |
        +---------------------------+

1.) Create a new partition

Format the disk with fdisk /dev/sdb command, and type m for help

sudo -i
fdisk /dev/sdb

*) Type n to create new partition then it will ask few values leave all to default and just click enter finaly you will see a message Created a new partition ... then type w and click enter...

2.) Create a Physical Volume (PV)

** Create PV using pvcreate /dev/sdb1**

pvcreate /dev/sdb1

Verify using pvdisplay /dev/sdb1

pvdisplay /dev/sdb1

3.) Create a Volume Group (VG)

** Create VG using vgcreate vg_u01 /dev/sdb1**

vgcreate vg_u01 /dev/sdb1

Verify VG creation using vgdisplay vg_u01 which also display number of Physical Extent (PE)

vgdisplay vg_u01

4.) Create a Logical Volume (LV) and map it to our Volume Group (VG)

lvcreate -l 12799 -n lv_u01 vg_u01

** -l 12799: Specifies the size of the logical volume in Logical Extents (LE)** -n lv_u01: The name flag

Here the number 12799 represent the number of Physical Extent (PE) in vg_u01. Each extent is typically 4MB, so this coluld create a LV of approximately 49.99GB (12799 extents * 4MB per extent). To check the size of created LV run lsblk

ls -l /dev/mapper/vg_u01-lv_u01

Logical volume is created inside our volume group.

5.) Format this LV using a file system...

mkfs.ext4 /dev/mapper/vg_u01-lv_u01

6.) Create a directory and mount the ext4 file system LV...

mkdir /u01
lsblk
mount -t ext4 /dev/mapper/vg_u01-lv_u01 /u01
df -h

Now , we can see the LV is mounted at newly created mount point /u01...


Mounting Block Volumes Permanently...

It is important to permanently mount a volume in /etc/fstab or else after server reebot the temporarily mounted volume will be unmounted

vi /etc/fstab

Here add /dev/mapper/vg_u01-lv_u01 /u01 ext4 defaults,_netdev,nofail 0 2 after the last line of fstab file and to write & quit type :wq

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

Use mount -a command (or mount --all) to mount all filesystems defined in the system's filesystem table (/etc/fstab) that are not already mounted. To verify reboot the server and use df -h command and see if the BV is automatically mounted or not.

THANKYOU!