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
-
On the Block volumes page click
Create block volume -
On the new page type volume
Name -
From the
Create in compartmentdropdown select the storage compartment -
From the
Availability domaindropdown select the same AD in which your compute instance resides -
In the Volume size and performance section there are two options
DefaultandCustomto customize the block volume selectCustomwhich takes two inputsVolume size (in GB)andVPUs 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 theVPUs typedropdown or enablePerformance based auto-tunewhich dynamically adjust the volume performance between VPUs specified for default and maximum.
-
-
In the Backup policies section select storage compartment in
Select backup policy compartmentdropdown and inSelect backup policydropdown generally we chooseGoldoption 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 chooseBronzeoption.-
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.
-
In the Cross ad/region replication section you can enable it and you can select region, AD, type
Volume replica name, and selectencryptionfrom the sub sectionCross region replica encryptionbut 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. -
In the Volume encryption section we prefer to choose
Encrypt using oracle-managed keysbut we can also choose another optionEncrypt using customer-managed keysaccording to client's requirement. -
Finally click on
Create block volume
Attach Block Volume to an Instance in OCI
Navigation menu > Storage > Block volumes
-
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.
-
Now click on the block volume name
-
On the new page click on
Attached instances -
Click on
Attach to instance -
Select Attachment type
iSCSI: Difficult to setup but provides maximum performance and compatible with Bare Metal & Virtual MachinesParavirtualized: Easy to setup and provides good performance but only compatible with Virtual Machines
-
Select Access type
-
Select Instance
- Choose compute compartment name from the dropdown
- Choose instance name
-
Click
Attachand it will ask you to run the block volume's iscsi commands.
Attach Block Volume to an Instance via PuTTY
- 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
-
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
-
To attach a new block volume to an instance copy iSCSI attach command and paste into terminal and hit enter
-
Verify attachment using
lsblkcommand and also rundf -hto check if it's mounted and you will see it's not mounted
Mounting Block Volumes for Immediate Use
-
Create a new partition
-
Format the disk with
fdisk /dev/sdbcommand, and typemfor helpsudo su root fdisk /dev/sdb -
Type
nand 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 typewand hit enter
-
-
Create a Physical Volume (PV)
-
Create PV using
pvcreate /dev/sdb1pvcreate /dev/sdb1 -
Verify using
pvdisplay /dev/sdb1pvdisplay /dev/sdb1
-
-
Create a Volume Group (VG)
-
Create VG using
vgcreate vg_u01 /dev/sdb1vgcreate vg_u01 /dev/sdb1 -
Verify VG creation using
vgdisplay vg_u01which also display number of Physical Extent (PE)vgdisplay vg_u01
-
-
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.
-
Format this LV using a file system
mkfs.ext4 /dev/mapper/vg_u01-lv_u01 -
Create a directory and mount the ext4 file system LV
mkdir /u01 lsblkmount -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 2after the last line offstabfile and to write & quit type:wq
/dev/mapper/vg_u01-lv_u01 /u01 ext4 defaults,_netdev,nofail 0 2
:wq
- Use
mount -acommand (ormount --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 usedf -hcommand and see if the BV is automatically mounted or not.