From cd27dff29ae658b4f92bfd9476fc8bfb6d86749e Mon Sep 17 00:00:00 2001 From: Lucas Alvares Gomes Date: Tue, 28 May 2013 15:43:46 +0100 Subject: [PATCH] Add fedora support for ramdisk-image-create. This patch allows the creation of ramdisks from a fedora system. Change-Id: Ic3b393af45ae1b85d015d2ceb5601ea723457da6 --- elements/deploy/root.d/50-redhat-prepare-fs | 15 +++++ lib/common-functions | 2 +- lib/ramdisk-functions | 30 +++++++++- scripts/init | 62 +++++++++++++-------- 4 files changed, 82 insertions(+), 27 deletions(-) create mode 100755 elements/deploy/root.d/50-redhat-prepare-fs diff --git a/elements/deploy/root.d/50-redhat-prepare-fs b/elements/deploy/root.d/50-redhat-prepare-fs new file mode 100755 index 00000000..317d4fe4 --- /dev/null +++ b/elements/deploy/root.d/50-redhat-prepare-fs @@ -0,0 +1,15 @@ +#!/bin/bash + +set -e + +[ -n "$TARGET_ROOT" ] + +DISTRO=`lsb_release -si` || true + +if [[ "Fedora RedHatEnterpriseServer" =~ "$DISTRO" ]]; then + mkdir -p "$TARGET_ROOT/usr" + ln -s ../lib "$TARGET_ROOT/usr/lib" + if [ "`uname -m`" = "x86_64" ]; then + ln -s lib "$TARGET_ROOT/lib64" + fi +fi diff --git a/lib/common-functions b/lib/common-functions index 7cf6df02..31234892 100644 --- a/lib/common-functions +++ b/lib/common-functions @@ -52,7 +52,7 @@ function save_image () { function generate_hooks () { mkdir -p $TMP_HOOKS_PATH - for _ELEMENT in $IMAGE_ELEMENT ; do + for _ELEMENT in $IMAGE_ELEMENT $RAMDISK_ELEMENT ; do for dir in $(echo $ELEMENTS_PATH | tr ":" " ") ; do [ -d $dir/$_ELEMENT ] || continue cp -t $TMP_HOOKS_PATH -a $dir/$_ELEMENT/* ; diff --git a/lib/ramdisk-functions b/lib/ramdisk-functions index 7010c65b..67225cb1 100644 --- a/lib/ramdisk-functions +++ b/lib/ramdisk-functions @@ -68,11 +68,14 @@ function create_base () { # cjk adding for discovery support mkdir -p "$TMP_MOUNT_PATH/var/lib/dhcp" mkdir -p "$TMP_MOUNT_PATH/var/run" - mkdir -p "$TMP_MOUNT_PATH/lib/udev/rules.d" cp -a "$LIB_UDEV/rules.d/50-firmware.rules" "$TMP_MOUNT_PATH/lib/udev/rules.d" cp -a "$LIB_UDEV/rules.d/80-drivers.rules" "$TMP_MOUNT_PATH/lib/udev/rules.d" - cp -a "$LIB_UDEV/firmware" "$TMP_MOUNT_PATH/lib/udev" + + if [ -a $LIB_UDEV/firmware ]; then + cp -a "$LIB_UDEV/firmware" "$TMP_MOUNT_PATH/lib/udev" + fi + # cjk adding for hwdiscovery support cp "/sbin/dhclient-script" "$TMP_MOUNT_PATH/sbin" @@ -89,6 +92,9 @@ udev_root="/dev" udev_rules="/lib/udev/rules.d" udev_log="no" EOF + + generate_hooks + TARGET_ROOT=$TMP_MOUNT_PATH run_d root } function copy_required_libs() { @@ -140,7 +146,25 @@ function copy_required_libs() { function populate_lib () { echo "Populating /lib" - for i in "$BUSYBOX" "$LIB_UDEV/firmware" bash lsmod modprobe udevd udevadm wget reboot shutdown $BINARY_DEPS ; do + # find udevd + UDEVD= + for f in /sbin/udevd /lib/udev/udevd /lib/systemd/systemd-udevd \ + /usr/lib/systemd/systemd-udevd \ + /usr/lib/udev/udevd; do + if [ -x "$f" ]; then + UDEVD="$f" + break + fi + done + + UDEV_FIRMWARE= + if [ -a $LIB_UDEV/firmware ]; then + UDEV_FIRMWARE="$LIB_UDEV/firmware" + fi + + for i in "$BUSYBOX" bash lsmod modprobe udevadm \ + wget reboot shutdown $UDEVD $UDEV_FIRMWARE \ + $BINARY_DEPS ; do if "$BUSYBOX" --list | grep "^$i\$" >/dev/null; then continue fi diff --git a/scripts/init b/scripts/init index fb6c2da2..f383c110 100644 --- a/scripts/init +++ b/scripts/init @@ -1,6 +1,6 @@ #!/bin/bash -# Copyright (c) 2012 NTT DOCOMO, INC. +# Copyright (c) 2012 NTT DOCOMO, INC. # Copyright 2012 Hewlett-Packard Development Company, L.P. # # All Rights Reserved. @@ -49,27 +49,43 @@ readonly DEPLOYMENT_KEY=$(get_kernel_parameter deployment_key) readonly ISCSI_TARGET_IQN=$(get_kernel_parameter iscsi_target_iqn) mount -t sysfs none /sys -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 -mkdir -p /dev/.udev/data + +UDEVD= +if [ -x "/bin/systemd-udevd" ]; then + UDEVD="systemd-udevd" +else + UDEVD="udevd" +fi + +if [ "$UDEVD" = "systemd-udevd" ]; then + # devtmpfs is required since udev 176 + mount -t devtmpfs none /dev + mkdir -p /run + mount -t tmpfs -o "nosuid,size=20%,mode=0755" tmpfs /run + mkdir -p /run/lock +else + 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 + mkdir -p /dev/.udev/data +fi echo "starting syslogd" @@ -78,7 +94,7 @@ syslogd klogd echo "starting udevd" -udevd --daemon --resolve-names=never +$UDEVD --daemon --resolve-names=never echo "load modules" load_modules_by_udev