From 5aca301693462f2682e27407e301681871f329b1 Mon Sep 17 00:00:00 2001 From: Ben Nemec Date: Fri, 26 Sep 2014 00:09:00 -0500 Subject: [PATCH] Refactor ramdisk element to allow alternate implementations In preparation for enabling Dracut-based ramdisks, this change factors out functionality that is common to both busybox and Dracut ramdisks. Said functionality is moved to a ramdisk-base element which is added as a dependency of the ramdisk element. ramdisk now only contains the functionality specific to building busybox-based ramdisks. bp tripleo-juno-dracut-ramdisks Change-Id: Iad2907c8be491c88727d87ed5e5a720e5beb66c3 --- elements/ramdisk-base/README.md | 1 + .../cleanup.d/99-extract-ramdisk-files | 0 .../01-inject-ramdisk-build-files | 0 .../extra-data.d/scripts/d/init-func | 2 +- .../ramdisk-base/extra-data.d/scripts/init | 28 ++++ .../extra-data.d/scripts/init-end | 1 - .../ramdisk-base/init.d/20-init-variables | 34 +++++ .../init.d/40-check-network-ready | 6 + elements/ramdisk/element-deps | 1 + elements/ramdisk/extra-data.d/scripts/init | 122 ------------------ elements/ramdisk/init.d/10-start-base-system | 57 ++++++++ .../{02-start-network => 30-start-network} | 8 -- .../install.d/52-ramdisk-install-busybox | 6 + 13 files changed, 134 insertions(+), 132 deletions(-) create mode 100644 elements/ramdisk-base/README.md rename elements/{ramdisk => ramdisk-base}/cleanup.d/99-extract-ramdisk-files (100%) rename elements/{ramdisk => ramdisk-base}/extra-data.d/01-inject-ramdisk-build-files (100%) rename elements/{ramdisk => ramdisk-base}/extra-data.d/scripts/d/init-func (99%) create mode 100755 elements/ramdisk-base/extra-data.d/scripts/init rename elements/{ramdisk => ramdisk-base}/extra-data.d/scripts/init-end (99%) create mode 100644 elements/ramdisk-base/init.d/20-init-variables create mode 100644 elements/ramdisk-base/init.d/40-check-network-ready delete mode 100755 elements/ramdisk/extra-data.d/scripts/init create mode 100644 elements/ramdisk/init.d/10-start-base-system rename elements/ramdisk/init.d/{02-start-network => 30-start-network} (90%) create mode 100755 elements/ramdisk/install.d/52-ramdisk-install-busybox diff --git a/elements/ramdisk-base/README.md b/elements/ramdisk-base/README.md new file mode 100644 index 00000000..722886ca --- /dev/null +++ b/elements/ramdisk-base/README.md @@ -0,0 +1 @@ +Shared functionality required by all of the different ramdisk elements. diff --git a/elements/ramdisk/cleanup.d/99-extract-ramdisk-files b/elements/ramdisk-base/cleanup.d/99-extract-ramdisk-files similarity index 100% rename from elements/ramdisk/cleanup.d/99-extract-ramdisk-files rename to elements/ramdisk-base/cleanup.d/99-extract-ramdisk-files diff --git a/elements/ramdisk/extra-data.d/01-inject-ramdisk-build-files b/elements/ramdisk-base/extra-data.d/01-inject-ramdisk-build-files similarity index 100% rename from elements/ramdisk/extra-data.d/01-inject-ramdisk-build-files rename to elements/ramdisk-base/extra-data.d/01-inject-ramdisk-build-files diff --git a/elements/ramdisk/extra-data.d/scripts/d/init-func b/elements/ramdisk-base/extra-data.d/scripts/d/init-func similarity index 99% rename from elements/ramdisk/extra-data.d/scripts/d/init-func rename to elements/ramdisk-base/extra-data.d/scripts/d/init-func index 6cb636f7..f68a54a5 100755 --- a/elements/ramdisk/extra-data.d/scripts/d/init-func +++ b/elements/ramdisk-base/extra-data.d/scripts/d/init-func @@ -1,4 +1,4 @@ -# Copyright (c) 2012 NTT DOCOMO, INC. +# Copyright (c) 2012 NTT DOCOMO, INC. # Copyright 2012 Hewlett-Packard Development Company, L.P. # # Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/elements/ramdisk-base/extra-data.d/scripts/init b/elements/ramdisk-base/extra-data.d/scripts/init new file mode 100755 index 00000000..f5ca79a5 --- /dev/null +++ b/elements/ramdisk-base/extra-data.d/scripts/init @@ -0,0 +1,28 @@ +#!/bin/bash + +# Copyright (c) 2012 NTT DOCOMO, INC. +# Copyright 2012 Hewlett-Packard Development Company, L.P. +# +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +# NOTE(bnemec): We don't want this script to exit on failures because if init +# dies then we get a kernel panic on ramdisk boot. +# dib-lint: disable=sete setu setpipefail + +echo "init" + +source /init-func + +PATH=/sbin:/bin:/usr/bin:/usr/sbin +export PATH diff --git a/elements/ramdisk/extra-data.d/scripts/init-end b/elements/ramdisk-base/extra-data.d/scripts/init-end similarity index 99% rename from elements/ramdisk/extra-data.d/scripts/init-end rename to elements/ramdisk-base/extra-data.d/scripts/init-end index 3180f1fc..a83a68eb 100644 --- a/elements/ramdisk/extra-data.d/scripts/init-end +++ b/elements/ramdisk-base/extra-data.d/scripts/init-end @@ -1,7 +1,6 @@ # Final init steps - echo "rebooting" reboot -f diff --git a/elements/ramdisk-base/init.d/20-init-variables b/elements/ramdisk-base/init.d/20-init-variables new file mode 100644 index 00000000..dee7c7a9 --- /dev/null +++ b/elements/ramdisk-base/init.d/20-init-variables @@ -0,0 +1,34 @@ +FIRST_ERR_MSG= + +# To identify that the node has booted from virtual media, a kernel +# command-line argument boot_method=vmedia is added in the iso bootloader +# configuration file (like isolinux.cfg for isolinux). +VMEDIA_BOOT_TAG="vmedia" +BOOT_METHOD=$(get_kernel_parameter boot_method) + +if [ "$BOOT_METHOD" = "$VMEDIA_BOOT_TAG" ]; then + + # If the node booted from virtual media cdrom, the arguments for the + # installation are provided in virtual media floppy. Find out + # the virtual media device, mount it and get the information. + configure_vmedia_dir +fi + +readonly _BOOTIF_=$(get_kernel_parameter BOOTIF) +readonly _IP_=$(get_kernel_parameter ip) +readonly BOOT_MAC_ADDRESS=$(echo "$_BOOTIF_" | sed -e "s/-/:/g" | \ + sed -e "s/^01://g" | tr 'a-f' 'A-F') +readonly BOOT_SERVER=$(echo "$_IP_" | cut -d':' -f2) + +# IP address, netmask, gateway can be set a later point of time if +# IP address is assigned by dhcp (for non-pxe boots). +BOOT_IP_ADDRESS=$(echo "$_IP_" | cut -d':' -f1) +BOOT_NETMASK=$(echo "$_IP_" | cut -d':' -f4) +BOOT_GATEWAY=$(echo "$_IP_" | cut -d':' -f3) + +readonly DISK=$(get_kernel_parameter disk) + +readonly DEPLOYMENT_ID=$(get_kernel_parameter deployment_id) +readonly DEPLOYMENT_KEY=$(get_kernel_parameter deployment_key) +readonly ISCSI_TARGET_IQN=$(get_kernel_parameter iscsi_target_iqn) +TROUBLESHOOT=$(get_kernel_parameter troubleshoot) diff --git a/elements/ramdisk-base/init.d/40-check-network-ready b/elements/ramdisk-base/init.d/40-check-network-ready new file mode 100644 index 00000000..1236ce38 --- /dev/null +++ b/elements/ramdisk-base/init.d/40-check-network-ready @@ -0,0 +1,6 @@ +if [ -n "$BOOT_SERVER" ]; then + echo "pinging to boot server $BOOT_SERVER" + wait_for 6 5 ping -c 5 -q "$BOOT_SERVER" > /dev/null +fi + +echo "network ready" \ No newline at end of file diff --git a/elements/ramdisk/element-deps b/elements/ramdisk/element-deps index ef25eec6..4fdba769 100644 --- a/elements/ramdisk/element-deps +++ b/elements/ramdisk/element-deps @@ -1 +1,2 @@ pkg-map +ramdisk-base diff --git a/elements/ramdisk/extra-data.d/scripts/init b/elements/ramdisk/extra-data.d/scripts/init deleted file mode 100755 index e35f0137..00000000 --- a/elements/ramdisk/extra-data.d/scripts/init +++ /dev/null @@ -1,122 +0,0 @@ -#!/bin/bash - -# Copyright (c) 2012 NTT DOCOMO, INC. -# Copyright 2012 Hewlett-Packard Development Company, L.P. -# -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -# NOTE(bnemec): We don't want this script to exit on failures because if init -# dies then we get a kernel panic on ramdisk boot. -# dib-lint: disable=sete setu setpipefail - -echo "init" - -source /init-func - -PATH=/sbin:/bin:/usr/bin:/usr/sbin -export PATH - -mkdir -p /proc /sys /dev /boot /etc /mnt /lib/modules - -mount -t proc proc /proc - -FIRST_ERR_MSG= - -mount -t sysfs none /sys - -UDEVD= -if [ -x "/bin/systemd-udevd" ]; then - UDEVD="systemd-udevd" -else - UDEVD="udevd" -fi - -# udev versions 176 and newer require a different on-disk setup -UDEVD_VERSION=$(udevadm --version) - -if [ "$UDEVD_VERSION" != "" -a $UDEVD_VERSION -gt 175 ]; then - echo "Using new-style udevd setup" - mount -t devtmpfs none /dev - mkdir -p /run - mount -t tmpfs -o "nosuid,size=20%,mode=0755" tmpfs /run - mkdir -p /run/{lock,udev} -else - echo "Using old-style udevd setup" - mount -t tmpfs none /dev - ln -sf /proc/self/fd /dev/fd - mknod /dev/null c 1 3 - mknod /dev/zero c 1 5 - mknod /dev/random c 1 8 - mknod /dev/urandom c 1 9 - mknod /dev/tty0 c 4 0 - mknod /dev/tty1 c 4 1 - mknod /dev/tty2 c 4 2 - mknod /dev/tty3 c 4 3 - mknod /dev/tty4 c 4 4 - mknod /dev/tty5 c 4 5 - mknod /dev/tty6 c 4 6 - mknod /dev/tty7 c 4 7 - mknod /dev/tty8 c 4 8 - mknod /dev/tty9 c 4 9 - mknod /dev/tty c 5 0 - mknod -m 0600 /dev/console c 5 1 - mknod -m 0666 /dev/ptmx c 5 2 - mkdir -p /dev/.udev/data -fi - -echo "starting syslogd" - -echo '*.* /initlog' > /etc/syslog.conf -syslogd -klogd - -echo "starting udevd" -$UDEVD --daemon --resolve-names=never - -echo "load modules" -load_modules_by_udev - -# To identify that the node has booted from virtual media, a kernel -# command-line argument boot_method=vmedia is added in the iso bootloader -# configuration file (like isolinux.cfg for isolinux). -VMEDIA_BOOT_TAG="vmedia" -BOOT_METHOD=$(get_kernel_parameter boot_method) - -if [ "$BOOT_METHOD" = "$VMEDIA_BOOT_TAG" ]; then - - # If the node booted from virtual media cdrom, the arguments for the - # installation are provided in virtual media floppy. Find out - # the virtual media device, mount it and get the information. - configure_vmedia_dir -fi - -readonly _BOOTIF_=$(get_kernel_parameter BOOTIF) -readonly _IP_=$(get_kernel_parameter ip) -readonly BOOT_MAC_ADDRESS=$(echo "$_BOOTIF_" | sed -e "s/-/:/g" | \ - sed -e "s/^01://g" | tr 'a-f' 'A-F') -readonly BOOT_SERVER=$(echo "$_IP_" | cut -d':' -f2) - -# IP address, netmask, gateway can be set a later point of time if -# IP address is assigned by dhcp (for non-pxe boots). -BOOT_IP_ADDRESS=$(echo "$_IP_" | cut -d':' -f1) -BOOT_NETMASK=$(echo "$_IP_" | cut -d':' -f4) -BOOT_GATEWAY=$(echo "$_IP_" | cut -d':' -f3) - -readonly DISK=$(get_kernel_parameter disk) - -readonly DEPLOYMENT_ID=$(get_kernel_parameter deployment_id) -readonly DEPLOYMENT_KEY=$(get_kernel_parameter deployment_key) -readonly ISCSI_TARGET_IQN=$(get_kernel_parameter iscsi_target_iqn) -TROUBLESHOOT=$(get_kernel_parameter troubleshoot) - diff --git a/elements/ramdisk/init.d/10-start-base-system b/elements/ramdisk/init.d/10-start-base-system new file mode 100644 index 00000000..2fbffe1c --- /dev/null +++ b/elements/ramdisk/init.d/10-start-base-system @@ -0,0 +1,57 @@ +mkdir -p /proc /sys /dev /boot /etc /mnt /lib/modules + +mount -t proc proc /proc + +mount -t sysfs none /sys + +UDEVD= +if [ -x "/bin/systemd-udevd" ]; then + UDEVD="systemd-udevd" +else + UDEVD="udevd" +fi + +# udev versions 176 and newer require a different on-disk setup +UDEVD_VERSION=$(udevadm --version) + +if [ "$UDEVD_VERSION" != "" -a $UDEVD_VERSION -gt 175 ]; then + echo "Using new-style udevd setup" + mount -t devtmpfs none /dev + mkdir -p /run + mount -t tmpfs -o "nosuid,size=20%,mode=0755" tmpfs /run + mkdir -p /run/{lock,udev} +else + echo "Using old-style udevd setup" + mount -t tmpfs none /dev + ln -sf /proc/self/fd /dev/fd + mknod /dev/null c 1 3 + mknod /dev/zero c 1 5 + mknod /dev/random c 1 8 + mknod /dev/urandom c 1 9 + mknod /dev/tty0 c 4 0 + mknod /dev/tty1 c 4 1 + mknod /dev/tty2 c 4 2 + mknod /dev/tty3 c 4 3 + mknod /dev/tty4 c 4 4 + mknod /dev/tty5 c 4 5 + mknod /dev/tty6 c 4 6 + mknod /dev/tty7 c 4 7 + mknod /dev/tty8 c 4 8 + mknod /dev/tty9 c 4 9 + mknod /dev/tty c 5 0 + mknod -m 0600 /dev/console c 5 1 + mknod -m 0666 /dev/ptmx c 5 2 + mkdir -p /dev/.udev/data +fi + +echo "starting syslogd" + +echo '*.* /initlog' > /etc/syslog.conf +syslogd +klogd + +echo "starting udevd" +$UDEVD --daemon --resolve-names=never + +echo "load modules" +load_modules_by_udev diff --git a/elements/ramdisk/init.d/02-start-network b/elements/ramdisk/init.d/30-start-network similarity index 90% rename from elements/ramdisk/init.d/02-start-network rename to elements/ramdisk/init.d/30-start-network index 94b352ae..d7210ac1 100644 --- a/elements/ramdisk/init.d/02-start-network +++ b/elements/ramdisk/init.d/30-start-network @@ -50,11 +50,3 @@ else echo " netmask = $BOOT_NETMASK" echo " gateway = $BOOT_GATEWAY" fi - -if [ -n "$BOOT_SERVER" ]; then - echo "pinging to boot server $BOOT_SERVER" - wait_for 6 1 ping -c 5 -q "$BOOT_SERVER" > /dev/null -fi - -echo "network ready" - diff --git a/elements/ramdisk/install.d/52-ramdisk-install-busybox b/elements/ramdisk/install.d/52-ramdisk-install-busybox new file mode 100755 index 00000000..f50b56c2 --- /dev/null +++ b/elements/ramdisk/install.d/52-ramdisk-install-busybox @@ -0,0 +1,6 @@ +#!/bin/bash + +set -eu +set -o pipefail + +install-packages busybox