Tuesday, May 16, 2023

Setting a Persistent Hostname in Oracle Cloud (Oracle Linux )

When deploying virtual machines in Oracle Cloud Infrastructure (OCI), the cloud metadata service often manages hostname configuration. This can overwrite any manual hostname changes made on the instance after a reboot.

In this blog post, we'll walk through setting a custom hostname on an OCI instance running Oracle Linux 8.7 and ensuring it persists across reboots

Manually set the hostname of your OCI instance and configure it so that your changes aren't lost during reboots or restarts.

Step 1: Set the Static Hostname

Use the hostnamectl command to define your new hostname:

[root@omoicsso ~]# hostnamectl set-hostname omoicsso.oasiserp.com

You can verify the change by running:

[root@omoicsso ~]# hostnamectl

   Static hostname: omoicsso.oasiserp.com

         Icon name: computer-vm

           Chassis: vm

        Machine ID: e0251ef691f54fe7b98d3354af266d31

           Boot ID: 333e7d37ec2b45d6942b50a9bf180b11

    Virtualization: kvm

  Operating System: Oracle Linux Server 8.7

       CPE OS Name: cpe:/o:oracle:linux:8:7:server

            Kernel: Linux 5.15.0-100.96.32.el8uek.x86_64

      Architecture: x86-64

[root@omoicsso ~]#

At this point, the hostname has been changed — but it may not be persistent across reboots due to OCI's metadata-based management.

Step 2: Configure Hostname Persistence

OCI instances come with a special configuration file: /etc/oci-hostname.conf.

Edit or verify the following setting:

[root@omoicsso ~]# cat /etc/oci-hostname.conf

# This configuration file controls the hostname persistence behavior for Oracle Linux

# compute instance on Oracle Cloud Infrastructure (formerly Baremetal Cloud Services)

# Set PRESERVE_HOSTINFO to one of the following values

#   0 -- default behavior to update hostname, /etc/hosts and /etc/resolv.conf to

#        reflect the hostname set during instance creation from the metadata service

#   1 -- preserve user configured hostname across reboots; update /etc/hosts and

#           /etc/resolv.conf from the metadata service

#   2 -- preserve user configured hostname across instance reboots; no custom

#        changes to /etc/hosts and /etc/resolv.conf from the metadata service,

#        but dhclient will still overwrite /etc/resolv.conf

#   3 -- preserve hostname and /etc/hosts entries across instance reboots;

#        update /etc/resolv.conf from instance metadata service

PRESERVE_HOSTINFO=2

What Does This Do?

  • PRESERVE_HOSTINFO=2 tells the system to preserve your manually configured hostname even after a reboot.

  • It prevents the OCI metadata service from overwriting your hostname, while still allowing it to update /etc/resolv.conf.

Final Check

After setting PRESERVE_HOSTINFO=2, your instance will retain the hostname even after a reboot.

You can test by rebooting:


[root@omoicsso ~]# reboot

[root@omoicsso ~]# hostnamectl

Static hostname: omoicsso.oasiserp.com

Conclusion

Oracle Linux on OCI provides flexibility in hostname configuration — but only when you know where to look. Setting PRESERVE_HOSTINFO=2 ensures that your manual hostname configuration stays intact, avoiding surprises after restarts.

This is particularly useful in environments where:

  • Hostnames are used for licensing, monitoring, or DNS registration.

  • Manual management of infrastructure is part of your architecture.



Thursday, May 11, 2023

How to Create and Manage LVM  Oracle Linux 8 on OCI

In enterprise Linux environments, Logical Volume Manager (LVM) provides flexibility in managing disk space by allowing dynamic resizing and better abstraction of physical storage devices.

In this post, we'll walk through adding a new disk, creating a volume group (VG), and then creating a logical volume (LV) on an Oracle Linux 8 server, specifically in an OCI (Oracle Cloud Infrastructure) environment.

Senerio

We want to:

  1. Initialize a new disk (/dev/sdb) for use with LVM.

  2. Create a new volume group vg_data.

  3. Create a logical volume lv_data with 350 GB of space.

Step 1: Create a Physical Volume (PV)

Before we can use a new disk with LVM, it must be initialized as a Physical Volume.

 [root@omoicsso opc]# pvcreate /dev/sdb

  Physical volume "/dev/sdb" successfully created.

/dev/Sdb is the hardware partition created in the OCI console as the block volume and assigned to the Linux server. It is raw storage from the OCI

[root@omoicsso opc]# pvs

  PV         VG        Fmt  Attr PSize   PFree

  /dev/sda3  ocivolume lvm2 a--   45.47g      0

  /dev/sdb             lvm2 ---  400.00g 400.00g

PVS lists all the physical volumes that are associated with this server 

Step 2: Create a Volume Group (VG)

Next, we group one or more physical volumes into a Volume Group:

[root@omoicsso opc]# vgcreate vg_data /dev/sdb

  Volume group "vg_data" successfully created

We had created the   volume group in the physical volume as vg_data -- it can be any name 

[root@omoicsso opc]# vgdisplay

  --- Volume group ---

  VG Name               vg_data

  System ID

  Format                lvm2

  Metadata Areas        1

  Metadata Sequence No  1

  VG Access             read/write

  VG Status             resizable

  MAX LV                0

  Cur LV                0

  Open LV               0

  Max PV                0

  Cur PV                1

  Act PV                1

  VG Size               <400.00 GiB

  PE Size               4.00 MiB

  Total PE              102399

  Alloc PE / Size       0 / 0

  Free  PE / Size       102399 / <400.00 GiB

  VG UUID               iWc996-XIO2-M3WL-oFxr-1LtR-ndXf-KxM0bL


  --- Volume group ---

  VG Name               ocivolume

  System ID

  Format                lvm2

  Metadata Areas        1

  Metadata Sequence No  23

  VG Access             read/write

  VG Status             resizable

  MAX LV                0

  Cur LV                2

  Open LV               2

  Max PV                0

  Cur PV                1

  Act PV                1

  VG Size               45.47 GiB

  PE Size               4.00 MiB

  Total PE              11641

  Alloc PE / Size       11641 / 45.47 GiB

  Free  PE / Size       0 / 0

  VG UUID               Hu90og-5IAx-0g5d-Q272-rmZL-L5fw-Z4R7lw

Here we have two volume groups,, so two groups have been displayed 

Step 3: Create a Logical Volume (LV)

Now, we need to created  a Logical Volume of 350 GB from vg_data:

[root@omoicsso opc]#  lvcreate -n lv_data -L 350G vg_data

  Logical volume "lv_data" created.

Once the volume group is created with the required size, you can format the logical volume using your preferred file system, such as XFS or ext4, and then mount it on the Linux system.

[root@omoicsso opc]# lvdisplay

  --- Logical volume ---

  LV Path                /dev/vg_data/lv_data

  LV Name                lv_data

  VG Name                vg_data

  LV UUID                mkJZtP-E5k6-vsmN-4lNf-9Qcg-DrIl-U5bKhe

  LV Write Access        read/write

  LV Creation host, time omoicsso, 2023-05-11 11:57:00 +0000

  LV Status              available

  # open                 0

  LV Size                350.00 GiB

  Current LE             89600

  Segments               1

  Allocation             inherit

  Read ahead sectors     auto

  - currently set to     4096

  Block device           252:2


  --- Logical volume ---

  LV Path                /dev/ocivolume/oled

  LV Name                oled

  VG Name                ocivolume

  LV UUID                nLXc2g-VyUO-dcUo-u1R1-HFOA-znRZ-PYAeBu

  LV Write Access        read/write

  LV Creation host, time localhost.localdomain, 2023-01-17 19:39:46 +0000

  LV Status              available

  # open                 1

  LV Size                10.00 GiB

  Current LE             2560

  Segments               1

  Allocation             inherit

  Read ahead sectors     auto

  - currently set to     4096

  Block device           252:1


  --- Logical volume ---

  LV Path                /dev/ocivolume/root

  LV Name                root

  VG Name                ocivolume

  LV UUID                0MG24k-y6uq-CJo6-75bH-Qfak-Glvd-U2E9YK

  LV Write Access        read/write

  LV Creation host, time localhost.localdomain, 2023-01-17 19:39:47 +0000

  LV Status              available

  # open                 1

  LV Size                35.47 GiB

  Current LE             9081

  Segments               1

  Allocation             inherit

  Read ahead sectors     auto

  - currently set to     4096

  Block device           252:0


We have three LVs, so the lvdisplay command displays all the LV in the server 


[root@omoicsso opc]#

At this point:

  • /dev/sdb is being used as an LVM physical volume.

  • You've grouped it into a volume group called vg_data.

  • A 350 GB logical volume (lv_data) is ready for formatting and mounting.


Create the file system 

mkfs.xfs /dev/vg_data/lv_data

Create A directory and Mount the lv 

mkdir /data
mount /dev/vg_data/lv_data /data

And optionally, add it to /etc/fstab for persistent mounting.

 Conclusion

Using LVM makes your Linux server storage much more flexible, especially in cloud environments like OCI where disks can be resized or replaced frequently. You can simplify expansion, backups, and migration by structuring your storage into volume groups and logical volumes.

Stay tuned for future posts on resizing volumes and taking LVM snapshots!