Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 19 additions & 22 deletions oracle-linux-image-tools/bin/build-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,12 @@ load_env() {
[[ "${SETUP_SWAP,,}" =~ ^(yes)|(no)$ ]] || error "SETUP_SWAP must be yes or no"
readonly SETUP_SWAP

[[ "${X2APIC,,}" =~ ^(on)|(off)$ ]] || error "X2APIC must be on or off"
readonly X2APIC="${X2APIC,,}"

[[ "${SERIAL_CONSOLE,,}" =~ ^(yes)|(no)$ ]] || error "SERIAL_CONSOLE must be yes or no"
readonly SERIAL_CONSOLE

# Source image scripts
if [[ -r "${DISTR_DIR}/${DISTR}/${IMAGE_SCRIPTS}" ]]; then
source "${DISTR_DIR}/${DISTR}/${IMAGE_SCRIPTS}"
Expand Down Expand Up @@ -326,13 +332,14 @@ stage_kickstart() {
# Generate Packer config file
# Globals:
# DISK_SIZE_MB MEM_SIZE CPU_NUM
# HOST_IP HOST_PORT
# ISO_URL ISO_SHA1_CHECKSUM
# KS_FILE
# SERIAL_CONSOLE
# SHUTDOWN_CMD
# SSH_PASSWORD SSH_KEY_FILE
# VM_NAME
# WORKSPACE PACKER_FILES BIN_DIR PROVISION_SCRIPT
# X2APIC
# Arguments:
# None
# Returns:
Expand All @@ -343,7 +350,13 @@ packer_conf() {

local q='"'
# KS_CONFIG is expanded in BOOT_COMMAND
local KS_CONFIG="http://${HOST_IP}:${HOST_PORT}/${KS_FILE}"
local KS_CONFIG="http://{{ .HTTPIP }}:{{ .HTTPPort }}/${KS_FILE}"
local CONSOLE=""
local modifyvm_console=""
if [[ "${SERIAL_CONSOLE,,}" = "yes" ]]; then
CONSOLE=" console=tty0 console=ttyS0"
modifyvm_console='["modifyvm", "{{.Name}}", "--uart1", "0x3f8", 4, "--uartmode1", "file", "'"${WORKSPACE}/${VM_NAME}"'/serial-console.txt"],'
fi
local boot_command=$(eval echo "\"${BOOT_COMMAND}\"")

cat > "${WORKSPACE}/${VM_NAME}.json" <<-EOF
Expand All @@ -368,6 +381,7 @@ packer_conf() {
${SSH_KEY_FILE:+${q}ssh_private_key_file${q}: ${q}$SSH_KEY_FILE${q},}
"ssh_port": 22,
"ssh_wait_timeout": "30m",
"http_directory": "${WORKSPACE}",
"boot_wait": "20s",
"boot_command":
[
Expand All @@ -376,6 +390,8 @@ packer_conf() {
"shutdown_command": "$SHUTDOWN_CMD",
"vboxmanage":
[
${modifyvm_console}
["modifyvm", "{{.Name}}", "--x2apic", "${X2APIC}"],
["modifyvm", "{{.Name}}", "--memory", ${MEM_SIZE}],
["modifyvm", "{{.Name}}", "--cpus", ${CPU_NUM}]
]
Expand All @@ -400,7 +416,6 @@ packer_conf() {
#######################################
# Run packer
# Globals:
# HOST_PORT
# VM_NAME
# WORKSPACE
# Arguments:
Expand All @@ -411,32 +426,14 @@ packer_conf() {
run_packer() {
echo_header "Run Packer"

local py_ver=$(python -c 'import sys; print(sys.version_info[0])')
local module packer_status server_pid

echo_message "Spawn HTTP server"
if [[ ${py_ver} = 2 ]]; then
module=SimpleHTTPServer
elif [[ ${py_ver} = 3 ]]; then
module=http.server
else
error "Cannot determine python version"
fi

cd ${WORKSPACE}
python -m ${module} ${HOST_PORT} &
server_pid=$!

echo_message "Invoke Packer"
local packer_status
local errexit="$(shopt -po errexit)"
set +e
/usr/bin/packer build -on-error=ask ${VM_NAME}.json
packer_status=$?
eval "${errexit}"

echo_message "Stop HTTP server"
kill ${server_pid}

[[ ${packer_status} -ne 0 ]] && error "Packer didn't complete successfully"

[[ -r "${WORKSPACE}/${VM_NAME}/${VM_NAME}.ova" ]] ||
Expand Down
1 change: 1 addition & 0 deletions oracle-linux-image-tools/cloud/none/image-scripts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ cloud::image_package() {
vboxmanage convertfromraw System.img --format VMDK "${vmdk}" --variant Stream
rm System.img
tar cvf "${VM_NAME}.ova" "${VM_NAME}.ovf" "${vmdk}"
rm "${vmdk}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ cloud::install_agent()
{
echo_message "Install guest agent"
local additions="/mnt/VBoxLinuxAdditions.run"
yum install -y ${YUM_VERBOSE} make gcc bzip2
yum install -y ${YUM_VERBOSE} make gcc bzip2 tar

if [[ "${KERNEL,,}" = "uek" ]]; then
yum install -y ${YUM_VERBOSE} kernel-uek-devel
Expand Down
2 changes: 1 addition & 1 deletion oracle-linux-image-tools/distr/ol7-slim/env.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ROOT_FS="xfs"

# Boot command
# Variables MUST be escaped as they are evaluated at build time.
BOOT_COMMAND='<up><tab> text ks=${KS_CONFIG} setup_swap=${SETUP_SWAP} <enter>'
BOOT_COMMAND='<up><tab>${CONSOLE} text ks=${KS_CONFIG} setup_swap=${SETUP_SWAP} <enter>'

# Kernel: uek, rhck or modrhck
KERNEL="uek"
Expand Down
8 changes: 8 additions & 0 deletions oracle-linux-image-tools/distr/ol7-slim/ol7-ks.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,14 @@ EOF
# make sure firstboot doesn't start
echo "RUN_FIRSTBOOT=NO" > /etc/sysconfig/firstboot

# Ensure we don't reboot with the serial console enabled
sed -i \
-e 's/ console=ttyS0//' \
-e 's/^GRUB_TERMINAL.*/GRUB_TERMINAL_OUTPUT="console"'/ \
-e '/^GRUB_SERIAL_COMMAND/d' \
/etc/default/grub
grub2-mkconfig -o /boot/grub2/grub.cfg

# Install latest kernel, that way it will be available at first boot and
# allow proper cleanup
KERNEL=uek
Expand Down
16 changes: 8 additions & 8 deletions oracle-linux-image-tools/env.properties
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,6 @@ CLOUD="none"
# Lock root account after provisioning? (Default: yes)
# LOCK_ROOT=

# Kickstart file needs to be provided via a http. We spawn a basic web server
# during the build.
# This is the default host IP as seen on the VirtualBox NAT interface.
# HOST_IP="10.0.2.2"
# The server will listen on this port
# HOST_PORT=8000


#
# Override examples
#
Expand All @@ -66,6 +58,14 @@ CLOUD="none"
# Allocated disk size for the image, default is distribution / cloud specific
# DISK_SIZE_GB=

# If you experience issues when building in a nested virtualization environment,
# you can disable X2APIC in VirtualBox for the build: on/off (default: on)
# X2APIC=

# Capture serial console in serial-console.txt during Kickstart. (Yes, No,
# default: no) -- Useful for debugging Kickstart issues.
# SERIAL_CONSOLE=

# OVM Image version (Default: 1.0)
# IMAGE_VERSION=

Expand Down
13 changes: 6 additions & 7 deletions oracle-linux-image-tools/env.properties.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ CLOUD="none"
# Build number
BUILD_NUMBER=0

# Kickstart file needs to be provided via a http. We spawn a basic web server
# during the build.
# This is the default host IP as seen on the VirtualBox NAT interface.
HOST_IP="10.0.2.2"
# The server will listen on this port
HOST_PORT=8000

# Number of CPUs for the build VM
CPU_NUM=4
# Memory allocated to the build VM
Expand All @@ -33,3 +26,9 @@ SSH_KEY_FILE=

# Lock root account after provisioning?
LOCK_ROOT="yes"

# Use X2APIC in VirtualBox for the build? (on, off)
X2APIC="on"

# Capture serial console in serial-console.txt during Kickstart? (yes, no)
SERIAL_CONSOLE="no"