05 ‐ Creating and attaching Block Volume - SanjeevOCI/Ocidocs GitHub Wiki
Steps to create a Block Volume & attach to a OCI Compute Instance
1. Creating a Block Volume
- Navigate to Burger Menu --> Storage --> Block Volumes --> Create Block Volume
- Enter the details - Block Volume Name, Compartment Name, Availability zone etc and click on "Create Block Volume". Note :- Please ensure to create the Block volume in the same Compartment and Availability zone as the compute instance, so that it can be added to it.
- New Block Volume has been created
2. Attaching a Block Volume to a Compute Instance
- Click on the newly created Block Volume --> Select "Attached Instance" option On the left side --> Click on "Attach to Instance" --> Select Instance Name and click "Attach" --> Block volume is now attached to the Instance
- Navigate to Burger Menu --> Compute --> Instances --> Click on the Instance where the Block Volume was attached --> Go to "Attached Block Volumes" --> The added Block volume can be seen
3. Reflecting the Block Volume in the server
-
After the Block Volume had been attached, Login to the server through Putty, in order to update the new volume in the server.
-
Run lsblk command to check the existing volumes in the server.
- Go to three dots --> iSCSI commands & information and Copy the connect command.
- Execute the copied commands in the server
After this when we check, we see one new volume is created
Run “df –h” command to check if this volume is showing or not.
As the volume is still not showing, we need to mount this volume to be ready to be used.
4. Create a new partition
- Formatting the Disk
Run “fdisk /dev/sdb” command , and type m for help
fdisk /dev/sdb
- Type “n” to create a new partition.
4. Create a Physical Volume
- Run "pvcreate /dev/sdb1" to create the physical volume
pvcreate /dev/sdb1
- Run "pvdisplay /dev/sdb1" to display the physical volume created
pvdisplay /dev/sdb1
5. Create a Volume Group
- Run "vgcreate vg_u01 /dev/sdb1" to create the 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
6. Create a logical volume and map it to our volume group
- Run the below commands to create the logical volume
lvcreate -l 12799 -n lv_u01 vg_u01
ls -l /dev/mapper/vg_u01-lv_u01
- Logical volume is now created inside our volume group
7. Format this logical volume using a file system
mkfs.ext4 /dev/mapper/vg_u01-lv_u01
8. Create a Directory to mount the logical volume
- Run the below commands to mount the logical volume
mkdir /u01
mount -t ext4 /dev/mapper/vg_u01-lv_u01 /u01
- Now we are able to see that the logical volume is mounted.
9. Mount the volume permanently in /etc/fstab or else it will get removed after the server reboots.
- Add the line below in /etc/fstab
/dev/mapper/vg_u01-lv_u01 /u01 ext4 defaults,_netdev,nofail 0 2
- Run the command "systemctl daemon-reload" to mount this volume premanently
systemctl daemon-reload