|
| 1 | +#!/usr/bin/env bash |
| 2 | +# |
| 3 | +# Packer provisioning script for OVM on OL9 |
| 4 | +# |
| 5 | +# Copyright (c) 2023, Oracle and/or its affiliates. |
| 6 | +# Licensed under the Universal Permissive License v 1.0 as shown at |
| 7 | +# https://oss.oracle.com/licenses/upl |
| 8 | +# |
| 9 | +# Description: OVM on OL9 specific provisioning. This module provides 2 |
| 10 | +# functions, both are optional. |
| 11 | +# cloud_distr::provision: provision the instance |
| 12 | +# cloud_distr::cleanup: instance cleanup before shutdown |
| 13 | +# |
| 14 | +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
| 15 | +# |
| 16 | + |
| 17 | +####################################### |
| 18 | +# Configure serial ports |
| 19 | +# Globals: |
| 20 | +# None |
| 21 | +# Arguments: |
| 22 | +# None |
| 23 | +# Returns: |
| 24 | +# None |
| 25 | +####################################### |
| 26 | +cloud_distr::serial_cfg() { |
| 27 | + cat > /usr/lib/systemd/system/serial_console.service <<-EOF |
| 28 | +# This file is part of systemd. |
| 29 | +# |
| 30 | +# systemd is free software; you can redistribute it and/or modify it |
| 31 | +# under the terms of the GNU Lesser General Public License as published by |
| 32 | +# the Free Software Foundation; either version 2.1 of the License, or |
| 33 | +# (at your option) any later version. |
| 34 | +
|
| 35 | +[Unit] |
| 36 | +Description=Serial Getty on serial_console |
| 37 | +Documentation=man:agetty(8) man:systemd-getty-generator(8) |
| 38 | +Documentation=http://0pointer.de/blog/projects/serial-console.html |
| 39 | +BindsTo=dev-serial_console.device |
| 40 | +After=dev-%i.device systemd-user-sessions.service plymouth-quit-wait.service |
| 41 | +After=rc-local.service |
| 42 | +
|
| 43 | +# If additional gettys are spawned during boot then we should make |
| 44 | +# sure that this is synchronized before getty.target, even though |
| 45 | +# getty.target didn't actually pull it in. |
| 46 | +Before=getty.target |
| 47 | +IgnoreOnIsolate=yes |
| 48 | +Conflicts=serial-getty@ttyS0.service serial-getty@hvc0.service |
| 49 | +ConditionPathIsSymbolicLink=/dev/serial_console |
| 50 | +
|
| 51 | +[Service] |
| 52 | +ExecStart=-/sbin/agetty --keep-baud 115200,38400,9600 serial_console $TERM |
| 53 | +Type=idle |
| 54 | +Restart=always |
| 55 | +UtmpIdentifier=serial_console |
| 56 | +TTYPath=/dev/serial_console |
| 57 | +TTYReset=yes |
| 58 | +TTYVHangup=yes |
| 59 | +KillMode=process |
| 60 | +IgnoreSIGPIPE=no |
| 61 | +SendSIGHUP=yes |
| 62 | +
|
| 63 | +[Install] |
| 64 | +WantedBy=getty.target |
| 65 | +EOF |
| 66 | + |
| 67 | + echo "KERNEL==\"ttyS0\", DEVPATH==\"/devices/pnp0/*\", SYMLINK+=\"serial_console\"" > /etc/udev/rules.d/50-udev.rules |
| 68 | + echo "KERNEL==\"hvc0\", DEVPATH==\"/devices/virtual/*\", SYMLINK+=\"serial_console\"" >> /etc/udev/rules.d/50-udev.rules |
| 69 | + systemctl enable serial_console.service |
| 70 | +} |
| 71 | + |
| 72 | +####################################### |
| 73 | +# Configure additional kernel |
| 74 | +# This will install RHCK if UEK is already there or the opposite |
| 75 | +# Assumes that we have a single kernel installed |
| 76 | +# Globals: |
| 77 | +# DRACUT_CMD, KERNEL, KERNEL_MODULES, UEK_RELEASE |
| 78 | +# Arguments: |
| 79 | +# None |
| 80 | +# Returns: |
| 81 | +# None |
| 82 | +####################################### |
| 83 | +cloud_distr::additional_kernel() { |
| 84 | + local kernel kernel_version |
| 85 | + |
| 86 | + # Select kernel to install |
| 87 | + # shellcheck disable=SC2153 |
| 88 | + if [[ "${KERNEL,,}" = "uek" ]]; then |
| 89 | + kernel="kernel" |
| 90 | + else |
| 91 | + if [[ ${KERNEL_MODULES,,} == "yes" ]]; then |
| 92 | + kernel="kernel-uek" |
| 93 | + else |
| 94 | + kernel="kernel-uek-core" |
| 95 | + fi |
| 96 | + dnf config-manager --set-enabled "ol9_UEKR7" |
| 97 | + fi |
| 98 | + |
| 99 | + echo_message "Adding kernel: ${kernel}" |
| 100 | + dnf install -y ${kernel} |
| 101 | + kernel_version=$(rpm -q ${kernel} --qf "%{VERSION}-%{RELEASE}.%{ARCH}") |
| 102 | + echo_message "Installed kernel: ${kernel_version}" |
| 103 | + |
| 104 | + # Regenerate initrd |
| 105 | + ${DRACUT_CMD} -f "/boot/initramfs-${kernel_version}.img" "${kernel_version}" |
| 106 | + |
| 107 | + # Ensure grub is properly setup |
| 108 | + grub2-mkconfig -o /boot/grub2/grub.cfg |
| 109 | +} |
| 110 | + |
| 111 | +####################################### |
| 112 | +# Provisioning module |
| 113 | +# Globals: |
| 114 | +# EXTRA_KERNEL |
| 115 | +# Arguments: |
| 116 | +# None |
| 117 | +# Returns: |
| 118 | +# None |
| 119 | +####################################### |
| 120 | +cloud_distr::provision() |
| 121 | +{ |
| 122 | + cloud_distr::serial_cfg |
| 123 | + if [[ "${EXTRA_KERNEL,,}" = "yes" ]]; then |
| 124 | + cloud_distr::additional_kernel |
| 125 | + fi |
| 126 | +} |
| 127 | + |
| 128 | +####################################### |
| 129 | +# Cleanup module |
| 130 | +# Globals: |
| 131 | +# None |
| 132 | +# Arguments: |
| 133 | +# None |
| 134 | +# Returns: |
| 135 | +# None |
| 136 | +####################################### |
| 137 | +cloud_distr::cleanup() |
| 138 | +{ |
| 139 | + : |
| 140 | +} |
0 commit comments