06 ‐ Detaching Boot & Block Volume from existing Instance and attaching them to a newly created instance - SanjeevOCI/Ocidocs GitHub Wiki

Steps to Detach and Reattach Boot & Block Volumes to Another Instance

1. Detach the Block Volume from the exiting Instance

Note:- Before detaching the Block volume, Please follow the below steps to ensure that the block volume data can be validated in the new instance

        1) Add a test file in the mounted folder /u01

        2) Take a count of the files in /u01 folder --> du -sh /u01
  1. Navigate to Burger Menu --> Compute --> Instances --> Select "computecompartment" in Compartment section --> Select the Instance --> Click on "Attached Block Volumes" to see the Block Volume attached to the existing Instance

Block_Volume_2

  1. Navigate to the three dots --> iSCSI commands & information and Copy the Disconnect command.

View iSCSI Commands

iSCSI Disconnect Command

  1. Login to the Existing Instance through Putty and unmount the Block Volume drive

Block volume drive before unmounting

Block volume drive after unmounting

As per "df -h command", /u01 folder is no longer available. As per "lsblk" command, the Logical Volume is there, but it is not pointing to any folder. It has been unmounted.

  1. Execute the copied iSCSI DISCONNECT commands in the server

Detach_Volume_4

Detach_Volume_5

  1. Remove the volume from the instance's etc/fstab

Block_Volume_16

  1. Navigate to the three dots in "Attached Block Volumes" --> Detach the Block Volume

Detach_Volume_1

Detach_Volume_2

  1. Block Volume is now removed

Detach_Volume_6


2. Delete the Compute Instance

  1. Navigate to Burger Menu --> Compute --> Instances --> Select "computecompartment" in Compartment section --> Select the Instance --> Click on "Terminate" to delete the existing instance.

  2. Deselect "Permanently delete the attached boot volume" --> Click on "terminate Instance"

Detach_Volume_7


3. Create the New Compute Instance

  1. Follow the Compute Instance creation steps to create a new Instance with the mentioned requirements (Example - New Shape) --> https://github.com/SanjeevOCI/Ocidocs/wiki/Creating-a-Compute-Instance

Detach_Volume_8


4. Stop the New Compute Instance

Detach_Volume_14

Detach_Volume_15


5. Replace the Boot Volume in the New Instance

  1. In the New Instance, Click on Boot Volume --> It will display the Boot Volume of the New Instance --> Click on "Replace Boot Volume"

Boot Volume of New Instance

  1. Select the Boot Volume of the deleted instance --> Click on "Save" --> The Old Boot Volume will get attached to the New Instance

Detach_Volume_10

Detach_Volume_19


6. Start the New Compute Instance

Detach_Volume_20


7. Attach the Block Volume

  1. Navigate to Burger Menu --> Storage --> Block Volumes --> Select the Block Volume to be attached --> Select "Attached Instance" option On the left side --> Click on "Attach to Instance" --> Select New Instance Name and click "Attach" --> Block volume is now attached to the Instance

Attach Block Volume to Instance_1

Attaching_Block_Volume_12062024

Detach_Volume_22

Detach_Volume_23

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

8. Login to the New Instance through Putty

  1. Login to the server through putty using opc and make appropriate changes for root login

Post_Attachment_Server_Login_1

Post_Attachment_Server_Login_2

  1. Run lsblk command to check the existing volumes in the server.

Post_Attachment_Server_Login_3


9. Reflecting the Block Volume in the server

  1. Navigate to the three dots in "Attached Block Volumes" --> iSCSI commands & information and Copy the connect command.

Post_Attachment_Server_Login_5

Post_Attachment_Server_Login_6

  1. Execute the copied commands in the server.

Post_Attachment_Block_Volume_1

Running the "lsblk" command shows that the Block volume is now preserved.


10. Mount the logical volume on the directory /u01

  1. Run the below command to mount the logical volume

mount -t ext4 /dev/mapper/vg_u01-lv_u01 /u01

  1. Run "df -h" command to confirm that the logical volume is mounted.

Post_Attachment_Block_Volume_4


11. Mount the volume permanently in /etc/fstab

  1. Add the line below in /etc/fstab & Run the command "mount -a" to mount this volume permanently

/dev/mapper/vg_u01-lv_u01 /u01 ext4 defaults,_netdev,nofail 0 2

mount volume permanently in etc fstab

Post_Attachment_Block_Volume_5

Check for the files created in previous instance to confirm all files in block volume have been copied to the new instance.

# This completes the steps to Detach and Reattach Boot & Block Volumes to Another Instance