LAB 13 ‐ Create Block volume with Backup - gautam-amitesh/OCI GitHub Wiki

Block Volume in OCI

In OCI a Block Volume is a high-performance, network-attached storage service that provides persistent block-level storage for compute instances. Think of it as virtual eqivalent of a physical hard drive that is attached to the computer to store and access data, even if the computer becomes inaccessible we can access the data stored in hard drive using another computer. Block volumes allow us to dynamically scale storage capacity from 50 GB up to 32 TB per volume according to our needs and we can attach up to 32 block volumes to a single instance. In linux we mount a block volume to a local directory in linux which is called mount point and then OS treats that volume exactly like any other directory.

Creating Block Volume

Navigation menu > Storage > Block Volumes
  1. On the Block volumes page click Create block volume

  2. On the new page type volume Name

  3. From the Create in compartment dropdown select the storage compartment

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

  5. 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

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

    • 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.

  6. In the Backup policies section select storage compartment in Select backup policy compartment dropdown and in Select backup policy dropdown generally we choose Gold option which is considered the best option for protection against data loss but according to the type of data and purpose preferred option can change like in case of testing we should generally choose Bronze option.

    • Gold: Daily incremental backups at midnight

    • Silver: Weekly incremental backups at midnight sunday

    • Bronze: Monthly incremental backups at midnight on the 1st of the month.

  7. 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 traditional 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.

  8. In the Volume encryption section we prefer to choose Encrypt using oracle-managed keys but we can also choose another option Encrypt using customer-managed keys according to client's requirement.

  9. Finally click on Create block volume

Attach Block Volume to an Instance in OCI

Navigation menu > Storage > Block volumes
  1. On the Block volumes page in the right side of Applied filters click on compartment selection dropdown and select the storage compartment in which you created block volume.

  2. Now click on the block volume name

  3. On the new page click on Attached instances

  4. Click on Attach to instance

  5. Select Attachment type

    • iSCSI: Difficult to setup but provides maximum performance and compatible with Bare Metal & Virtual Machines
    • Paravirtualized: Easy to setup and provides good performance but only compatible with Virtual Machines
  6. Select Access type

  7. Select Instance

    • Choose compute compartment name from the dropdown
    • Choose instance name
  8. Click Attach and it will ask you to run the block volume's iscsi commands.

Attach Block Volume to an Instance via PuTTY

  1. Open PuTTY 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
  1. 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

  2. To attach a new block volume to an instance copy iSCSI attach command and paste into terminal and hit enter

  3. 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

  1. Create a new partition

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

      sudo su root
      fdisk /dev/sdb
      
    • Type n and hit enter to create new partition then it will ask few values leave all to default and just hit enter finaly you will see a message Created a new partition ... then type w and hit 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
    
    • Here 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.