LAB 14 ‐ Create Block volume with Backup - DevWithNehaCloud/Oracle-Cloud-Infrastructure-wiki GitHub Wiki
OCI Block Volume with Backup (Short Concept)
In Oracle Cloud Infrastructure (OCI), a Block Volume is like a virtual hard disk that you attach to a compute instance.
You store data on the block volume (just like a disk). You can take backups of this volume. Backups are stored in OCI Object Storage and can be used to:
- Restore lost data
- Create new volumes
- Disaster recovery
👉 Example: If your server crashes, you can restore the volume from backup and attach it to a new instance.
Boot Volume vs Block Volume (OCI) – Short Difference
-
Boot Volume: Used to boot the instance. It contains the OS (like Linux/Windows) and is automatically created when you launch an instance.
-
Block Volume: Used for additional storage. You can attach/detach it anytime to store data, applications, backups, etc.
In one line:
Boot volume = OS disk (mandatory),
Block volume = extra storage (optional)
Simple understanding: Boot volume is like the OS drive, while block volume is like an extra/extended hard disk.
LVM Storage Flow (OCI Block Volume to Mounted Path)
+--------------------------------------------------------------+
| OCI Block Volume (Virtual Disk) |
| Persistent storage attached to instance (OCI) |
+--------------------------------------------------------------+
↓
+--------------------------------------------------------------+
| Raw Disk (/dev/sdb, /dev/xvdb) |
| Unformatted disk attached to instance (no filesystem yet) |
+--------------------------------------------------------------+
↓
+--------------------------------------------------------------+
| Physical Volume (PV) /dev/sdb |
| Disk initialized for LVM (LVM metadata added) |
| Can be combined with other disks |
+--------------------------------------------------------------+
↓
+--------------------------------------------------------------+
| Volume Group (VG_data) |
| Storage pool created from one or more PVs |
| Provides flexible space allocation |
| (Extendable by adding more disks anytime) |
+--------------------------------------------------------------+
↓
+--------------------------------------------------------------+
| Logical Volume (LV_data) |
| Virtual partition from VG |
| Acts like real disk (/dev/VG_data/LV_data) |
| Supports dynamic resize (extend/shrink) |
+--------------------------------------------------------------+
↓
+---------------------------------------------------------------------+
| File System (ext4 / xfs / btrfs) |
| Organizes data into files (within directory structure) |
| OS can read/write data properly |
+---------------------------------------------------------------------+
↓
+--------------------------------------------------------------+
| Mounted Path (/data) |
| Directory where storage is attached |
| Makes storage usable for applications/users |
| (Configured via mount / /etc/fstab) |
+--------------------------------------------------------------+
Raw Disk → Just attached disk, no structure
**PV →**Disk prepared for LVM
VG → Storage pool (combine multiple disks)
LV → Actual usable partition (flexible)
File System→ Makes data readable (files/folders)
Mount → Final usable path for apps
These are three file systems that manage data on disk. Here is a comparison between them:
| File System | Best For | Special Feature |
|---|---|---|
| ext4 | General use | Stable & simple |
| xfs | Large data | High performance |
| btrfs | Advanced features | Snapshot, compression |
Steps to create Block volume with Backup
1.Navigate to the Burger Menu, select Storage, then go to Block Volumes.
- Select the compartment hub-compute-and-storage and click on Create Block Volume
- Enter all the required fields like Block Volume name, Select the Compartment, Select the Availability Domain(AD must be the same as the instance).
- Select the option custom and enter the volume size.
- Select the compartment hub-compute-and-storage and select backup policy as gold.
- select volume encryption as "Encrypt using oracle-managed keys" and click on create block volume.
- Once the block volume is created, go to the Block Volume details page. On the right side, click Attached Instances.
- Select the compartment hub-compute-and-storage and then click on Attach to Instance.
- Select the Attachment Type as iSCSI and the Access Type as Read/Write.
- Select the instance(bastion-server) from the specific compartment(hub-compute-and-storage) where you want to attach the block volume then click Attach.
Block Volume Attachment via PuTTY
- Now, Will login into putty and check the block volume
- Run the command lsblk to check the existing volumes on the server.
lsblk
- To attach a new volume, open the specific attached Block Volume in the OCI Console. Click on the three‑dot menu and select iSCSI Commands & Information.
- Copy the Attach Command by manually selecting all the three lines and press ctrl+c and execute it on the server (putty).
- After completing this step, run the lsblk command again to verify that the new volume is created. we can check , one new volume is created
lsblk
- We can run df –h command to check if this volume is showing or not
df -h
It is still not showing, so now we have to mount this volume to be ready to be used.
Mounting Block Volumes on the Server
- To Create a new partition and format the disk, run the command fdisk /dev/sdb and type m for help
fdisk /dev/sdb
lsblk
Type n to create a new partition, select the default options, and type w to save the changes.
and run the lsblk command to verify if new partition is added
- Now run the command to Create a Physical Volume
pvcreate /dev/sdb1
- And run the command to display the physical volume created
pvdisplay /dev/sdb1
- Now run the command to Create a volume group
vgcreate vg_u01 /dev/sdb1
- And run the command to display the volume group created
vgdisplay vg_u01
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).
- Now Create a logical volume and map it to our volume group. To check this run the command
lvcreate -l 12799 -n lv_u01 vg_u01
- To verify if Logical volume is created inside our volume group run the command
ls -l /dev/mapper/vg_u01-lv_u01
- Run the command to format the logical volume using a file system
mkfs.ext4 /dev/mapper/vg_u01-lv_u01
- Create a Directory and mount the logical volume “mkdir /u01” and mount ext4 file system
mkdir /u01
mount -t ext4 /dev/mapper/vg_u01-lv_u01 /u01
Now we can see the logical volume is mounted.
- To mount this volume permanently run the command vi /etc/fstab or else after server reboot this volume will be removed.
vi /etc/fstab
the fstab file will be open in vi editor add this line in the very last of file by pressing esc i “/dev/mapper/vg_u01-lv_u01 /u01 ext4 defaults,_netdev,nofail 0 2” and then save the file by pressing esc:wq
/dev/mapper/vg_u01-lv_u01 /u01 ext4 defaults,_netdev,nofail 0 2
to check the content of the file, if you want type the command cat /etc/fstab
run mount –a command, if no error then volume is mounted successfully. Then run the command df -h
mount -a
df -h
Steps to reboot server
-
Now go to compute and click on instances select the compartment where you have created the instance.
-
Click on the instance you want to reboot. In the right corner, select the Actions option, and from the drop‑down menu click on Reboot.
Once the reboot is completed run the command df -h and check.
df -h
iSCSI vs Paravirtualized (OCI Block Volume Attachment) – Short Difference
- iSCSI:
Network-based attachment. Instance connects to volume using iSCSI protocol (manual setup sometimes needed, slightly more overhead).
- Paravirtualized:
Direct virtual attachment. Faster, simpler, and recommended (no manual iSCSI commands needed).
In one line: iSCSI = network-based attachment, Paravirtualized = direct & faster attachment.
| Feature | iSCSI Attachment | Paravirtualized Attachment |
|---|---|---|
| Type | Network-based | Direct virtual attachment |
| Setup | Manual (iSCSI commands needed) | Automatic / simple |
| Performance | Slightly lower | Better / faster |
| Complexity | More complex | Less complex |
| Use Case | Special/custom requirements | Default, standard use in companies |
| Recommendation | Rarely used | Mostly used (recommended) |