5. Creating and attaching Block Volume - Ayushi-srivastav/OCI GitHub Wiki
Step 1 : Create Block volumes in OCI
- Browse the Block Volume
Click on the Burger Menu in left side, select storage than go to the Block volumes
- Click on create Block Volume
-
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
(e) choose backup policy
(f) select cross region replication
(g) select volume encryption
and click on create block volume
Now, Block volume is created
Step 2 : Attach Block volumes in OCI
-
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
-
Select Attachment type &
access type
-
Select the instance within the specific compartment
where you want to attach the block volume
Than, click on the attach
Step 3 : Attach Block Volume via Putty
- Run lsblk command to check the existing volumes in the server
lsblk
- To attach new volume,open that particular attached BV in OCI
Go to three dots
select iSCSI commands & information
Copy the connect command
Run these commands in the server
After this
again Run lsblk command to check whether new volume is created or not
lsblk
we can check , one new volume is created
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.
Step 4 : Mounting Block Volumes for Immediate Use
- Create a new partition
Format the Disk
Run fdisk /dev/sdb command , and type m for help
fdisk /dev/sdb
Type “n” to create a new partition
select default and type "w"
- Create a Physical Volume
pvcreate /dev/sdb1
To display the physical volume created,
pvdisplay /dev/sdb1
- Create a Volume Group
vgcreate vg_u01 /dev/sdb1
Run “vgdisplay vg_u01” to display the volume group created and to see the Number of Physical Extent
vgdisplay vg_u01
- Create a logical volume and map it to our volume group
lvcreate -l 12799 -n lv_u01 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).
to check the size of created lv run lsblk
lsblk
ls -l /dev/mapper/vg_u01-lv_u01
Logical volume is created inside our volume group.
- Format this 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
“mount –t ext4 /dev/mapper/vg_u01-lv_u01 /u01
mkdir /u01
mount -t ext4 /dev/mapper/vg_u01-lv_u01 /u01
Now we can see the logical volume is mounted.
- Mount this volume permanently in /etc/fstab or else after server reboot this volume will be removed.
vi /etc/fstab
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!
run mount –a command
mount -a
df -h
in last, reboot the server and again run df -h and check
df -h