Oracle Linux platform images on OCI ship with oci-utils. It is a set of commands that do common instance tasks for you, such as reading metadata, running the iSCSI commands for a new block volume, adding a secondary IP to the OS, and growing the root filesystem after a boot volume resize. Most engineers only find these commands after typing the long manual versions many times. This sheet lists the ones worth remembering.
Tip
Options change between oci-utils releases. Before you script against a command, run
rpm -q oci-utilsandman oci-<command>on the instance.
Setup and authentication
oci-utils is preinstalled on Oracle Linux platform images. It comes from the oci_included repository, which is enabled by default on those images. The package is not available for other distributions.
rpm -q oci-utils
sudo dnf update oci-utils # yum on Oracle Linux 7
sudo systemctl enable --now ocid.service
sudo systemctl status ocid.service
The ocid daemon watches iSCSI and VNIC changes. It can attach or configure new devices automatically, and it caches the instance metadata and public IP.
Commands that call the OCI API need credentials. These include oci-iscsi-config create, oci-iscsi-config attach -O, oci-network-config attach-vnic and oci-public-ip --instance-id. You can provide credentials in one of three ways:
| Method | How |
|---|---|
| Instance principal | Put the instance in a dynamic group and grant the policy it needs, for example manage volume-family or use virtual-network-family |
| SDK config file | Run oci setup config for root, or point oci-utils at another user's config in /etc/oci-utils.conf.d |
| None | Local-only commands such as oci-metadata, oci-growfs and oci-iscsi-config attach -I |
Instance identity and metadata
| Task | Command |
|---|---|
| All metadata, human-readable | oci-metadata |
| All metadata as JSON | oci-metadata -j |
| One key | oci-metadata -g state |
| Value only, for scripts | oci-metadata -g displayName --value-only |
| Shell export line | oci-metadata -g region --export |
| Instance OCID | oci-instanceid |
| Compartment OCID | oci-compartmentid |
| Public IP | oci-public-ip -g |
Use these in scripts:
REGION=$(oci-metadata -g region --value-only)
INSTANCE_ID=$(oci-instanceid)
COMPARTMENT_ID=$(oci-compartmentid)
echo "$INSTANCE_ID in $COMPARTMENT_ID ($REGION)"
# Shortens instance/metadata/ssh_authorized_keys to ssh_authorized_keys
oci-metadata -g ssh_authorized_keys --trim
oci-metadata -u can update custom metadata keys, either for this instance or for another one with -i <instance OCID>. It needs API credentials. Updating metadata is rare enough that you should test it on a non-production instance first.
oci-public-ip asks the OCI API first and falls back to a STUN server. On an instance without internet access or credentials, it may return nothing. In that case, check the VNIC in the Console or run oci compute instance list-vnics.
iSCSI block volumes
The manual iSCSI attach needs three iscsiadm commands per volume. oci-iscsi-config runs them for you.
| Task | Command |
|---|---|
| Devices that need attention | sudo oci-iscsi-config |
| Show attached iSCSI devices | sudo oci-iscsi-config show |
| Show all volumes, including unattached | sudo oci-iscsi-config show --all |
| Show all volumes in all compartments | sudo oci-iscsi-config show -C all --details |
| Log in to an attachment made in the Console | sudo oci-iscsi-config attach -I <IQN> |
| Attach an existing volume by OCID (API) | sudo oci-iscsi-config attach -O <volume OCID> |
| Create a 100 GB volume and attach it | sudo oci-iscsi-config create -S 100 -v app-data-01 --attach-volume |
| Log out of a volume | sudo oci-iscsi-config detach -I <IQN> |
| Attach everything available and sync | sudo oci-iscsi-config sync --apply |
The usual flow after someone attaches a volume as iSCSI in the Console:
sudo oci-iscsi-config show # the new IQN shows as not connected
sudo oci-iscsi-config attach -I iqn.2015-12.com.oracleiaas:0f1e...
lsblk # new /dev/sdX appears
For a volume you'll mount at boot, put the UUID in /etc/fstab and add _netdev,nofail. That way a missing iSCSI session can't drop the instance into emergency mode.
Caution
oci-iscsi-config destroy -O <OCID>deletes the block volume in OCI. The delete can't be undone. It asks for confirmation unless you pass-y, so never putdestroy -yin a script without a backup check first. Also,detach -fforces a logout even when the filesystem can't be unmounted, which can lose data that hasn't been written yet. Stop the application and unmount the filesystem first.
VNICs and secondary IPs
When you add a secondary private IP or a secondary VNIC to an instance, the guest OS doesn't configure it automatically. oci-network-config sets up the OS side for you, including the policy routing that secondary VNICs need. All subcommands need root.
| Task | Command |
|---|---|
| Show VNICs and OS configuration | sudo oci-network-config show --details |
| List VNICs attached to the instance | sudo oci-network-config show-vnics |
| Configure all VNICs and IPs that OCI knows about | sudo oci-network-config configure |
| Remove OS configuration for secondary VNICs | sudo oci-network-config unconfigure |
| Create and attach a secondary VNIC (API) | sudo oci-network-config attach-vnic --subnet <subnet OCID> -n app-vnic2 |
| Detach a secondary VNIC (API) | sudo oci-network-config detach-vnic -O <VNIC OCID> |
| Add a secondary IPv4 to a VNIC (API) | sudo oci-network-config add-secondary-addr -I 10.0.1.50 -O <VNIC OCID> |
| Remove a secondary IP (API) | sudo oci-network-config remove-secondary-addr -I 10.0.1.50 |
-I means different things in different subcommands. In show, configure and unconfigure it is --include. In the attach, detach and address subcommands it is --ip-address. To avoid mistakes, use the long options in scripts.
detach-vnic also deletes the secondary IPs on that VNIC, and you can't detach the primary VNIC. If a secondary IP was added in the Console and still doesn't answer, run sudo oci-network-config configure and then check ip addr and ip rule.
Grow the root filesystem
After you expand the boot volume in OCI and rescan the device, run:
lsblk # confirm the disk shows the new size
sudo /usr/libexec/oci-growfs -y # grows the partition, LVM and filesystem
df -h /
oci-growfs supports XFS and ext4. It lives in /usr/libexec, so it isn't in PATH by default. If the disk still shows the old size, the rescan hasn't happened yet. Run the rescan commands the Console shows after the resize, then run oci-growfs again.
Other useful commands
| Command | Use |
|---|---|
sudo oci-notify config <topic OCID> | Save a Notifications topic for this instance |
sudo oci-notify message -t 'disk 90% on db01' -f /tmp/df.txt | Send a message, or a file in chunks, to that topic |
oci-volume-data -k <volume OCID or IQN> -p display-name | Read one field about a volume |
oci-network-inspector -C <compartment OCID> | Summarise VCNs, subnets and security lists |
oci-notify is handy in cron jobs on hosts without a mail relay. Prefix the title with the host role so the alert makes sense on a phone screen.
Common errors
| Symptom | Cause | Fix |
|---|---|---|
create, attach -O or attach-vnic fails with an auth error | No SDK config or instance principal policy | Add the instance to a dynamic group with the right policy, or run oci setup config for root |
show lists volumes from other instances | You used --all or -C all | Drop those flags to see only this instance |
New volume not visible after attach -I | Wrong IQN, or the attachment type is paravirtualized | Paravirtualized volumes need no iSCSI login. Check lsblk |
| Secondary IP pingable from the instance but not from the subnet | NSG or security list | Fix the rules in OCI. oci-network-config only configures the OS |
oci-growfs: command not found | It isn't in PATH | Run /usr/libexec/oci-growfs |
Prevent it next time
- Enable
ocid.servicein your golden image so new iSCSI volumes and VNICs are configured automatically. - Use
oci-metadata --value-onlyin scripts instead of hard-coding OCIDs, regions or names. - Keep
oci-utilsupdated with the rest of the OS. Patches often add subcommands or rename options, so pin scripts to long option names. - Don't give automation
destroyordetach-vnicpermissions unless it needs them. Instance principal policies should cover only what the host must do.
Get the weekly HubDatAI email
One email a week with everything new: posts, learning sessions and videos. Free, no spam, unsubscribe in one click. What you get