/usr/share/diskimage-builder/lib/ramdisk-functions is in python-diskimage-builder 1.0.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 | # Copyright 2012 Hewlett-Packard Development Company, L.P.
# Copyright (c) 2012 NTT DOCOMO, INC.
#
# All Rights Reserved.
#
# 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.
function fullpath() {
local f=$1
if [ "${f#/}" = "$f" ]; then
echo `pwd`/"$f"
else
echo "$f"
fi
}
function create_ramdisk_base () {
echo "Creating base system"
mkdir -p "${TMP_MOUNT_PATH}/"{bin,lib/modules,etc/udev}
ln -s bin "$TMP_MOUNT_PATH/sbin"
# cjk adding for discovery support
mkdir -p "${TMP_MOUNT_PATH}/"{lib/udev/rules.d,var/{lib/dhcp,run}}
case "$DISTRO_NAME" in
fedora|rhel|rhel7|opensuse)
mkdir -p "$TMP_MOUNT_PATH/usr"
ln -s ../lib "$TMP_MOUNT_PATH/usr/lib"
if [[ "`uname -m`" =~ x86_64|ppc64 ]]; then
ln -s lib "$TMP_MOUNT_PATH/lib64"
fi
;;
esac
if [ -e $LIB_UDEV/rules.d/50-firmware.rules ]; then
cp -a "$LIB_UDEV/rules.d/50-firmware.rules" "$TMP_MOUNT_PATH/lib/udev/rules.d"
fi
cp -a "$LIB_UDEV/rules.d/80-drivers.rules" "$TMP_MOUNT_PATH/lib/udev/rules.d"
if [ -a $LIB_UDEV/firmware ]; then
cp -a "$LIB_UDEV/firmware" "$TMP_MOUNT_PATH/lib/udev"
fi
# cjk adding dhclient for hwdiscovery support
# dhclient scripts on some distros appear in different places, copy any we find
for FILE in /sbin/dhclient-script /usr/sbin/dhclient-script /etc/sysconfig/network-scripts/* /etc/rc.d/init.d/functions /etc/init.d/functions ; do
if [ -f $FILE ] ; then
mkdir -p $(dirname $TMP_MOUNT_PATH/$FILE)
cp $FILE $TMP_MOUNT_PATH/$FILE
fi
done
# /var/lib/dhclient is a directory on Fedora
if [ -d "/var/lib/dhclient" ] ; then
mkdir -p "$TMP_MOUNT_PATH/var/lib/dhclient"
fi
mkdir -p "$TMP_MOUNT_PATH/etc/modprobe.d"
echo "blacklist evbug" > "$TMP_MOUNT_PATH/etc/modprobe.d/blacklist.conf"
# cjk adding for hwdiscovery support
touch "$TMP_MOUNT_PATH/etc/fstab"
mkdir -p "$TMP_MOUNT_PATH/etc/udev"
cat >"$TMP_MOUNT_PATH/etc/udev/udev.conf" <<EOF
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() {
set +e
ldd_out=`ldd "$1"`
local ret_code=$?
set -e
if [ $ret_code -ne 0 ]; then
return
fi
local IFS="
"
# Patterns of output of ldd
#
# 1. name to real path
# libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f095e784000)
# 2. only path
# /lib64/ld-linux-x86-64.so.2 (0x00007f095ef79000)
# 3. path to path
# /lib64/ld-linux-x86-64.so.2 => /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 (0x00007facff857000)
# 4. name to empty (vdso)
# linux-vdso.so.1 => (0x00007fff0c5ff000)
# or, in some setups:
# linux-vdso.so.1 (0x00007fff0c5ff000)
for i in `echo "$ldd_out" | sed -e 's/^\t*//'`; do
local ref=$( echo "$i" | awk -F '[ ]' '{print $1}')
local real=$( echo "$i" | awk -F '[ ]' '$2 == "=>" {print $3}
$2 != "=>" {print $1}')
if [ -z "$real" ] || [[ "$real" != /* ]]; then
continue
fi
if [ "$ref" = "${ref#/}" ]; then
ref=/lib/$ref
fi
dest=/lib/`basename "$real"`
cp -Ln "$real" "$TMP_MOUNT_PATH/$dest"
# Create a symbolic link if the shared library is referred
# by the different name
if [ "$ref" != "$dest" ]; then
local link_path=$TMP_MOUNT_PATH/$ref
if ! [ -e "$link_path" -o -L "$link_path" ]; then
mkdir -p $(dirname "$link_path")
ln -s "$dest" "$link_path"
fi
fi
done
}
function populate_lib () {
echo "Populating /lib"
# 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 \
$(cat /etc/dib_binary_deps) ; do
# Don't take the ip command from busybox, its missing some features
if busybox_list | grep -v "^ip$" | grep "^$i\$" >/dev/null; then
continue
fi
path=`which $i 2>/dev/null` || path=$i
if ! [ -x "$path" ]; then
echo "$i is not found in PATH" 2>&1
exit 1
fi
cp -L "$path" "$TMP_MOUNT_PATH/bin/"
copy_required_libs "$path"
done
if [ -f /dib-signed-kernel-version ] ; then
. /dib-signed-kernel-version
fi
if [ -n "${DIB_SIGNED_KERNEL_VERSION:-}" ]; then
# Secure kernel module directory does not have efi.signed suffix to
# kernel version.
if echo $KERNEL_VERSION | grep -q 'efi.signed'; then
KERNEL_VERSION=`echo "$KERNEL_VERSION" |sed "s/\.efi\.signed//g"`
fi
fi
cp -a "$MODULE_DIR" "$TMP_MOUNT_PATH/lib/modules/$KERNEL_VERSION"
echo "Removing kernel framebuffer drivers to enforce text mode consoles..."
find $TMP_MOUNT_PATH/lib/modules/$KERNEL_VERSION/kernel/drivers/video -name '*fb.ko' -exec rm -v {} +
if [ -d $FIRMWARE_DIR ]; then
cp -a "$FIRMWARE_DIR" "$TMP_MOUNT_PATH/lib/firmware"
fi
}
function busybox_list () {
# busybox supports --list option since version 1.18
"$BUSYBOX" --list 2> /dev/null && return
# for busybox under 1.18 we parse command list from --help output
scrlet='{ if (go) { print } } /Currently defined functions:/ { go=1 }'
"$BUSYBOX" --help | awk "$scrlet" | tr ',' '\n' | xargs -n1 echo
}
function populate_busybox () {
echo "Creating symlinks for busybox binaries"
for i in $( busybox_list ); do
if [ -f "$TMP_MOUNT_PATH/bin/$i" ]; then
echo "skip $i"
continue
fi
ln -s busybox "$TMP_MOUNT_PATH/bin/$i"
done
}
function populate_init () {
echo "Installing init"
cp "$INIT" "$TMP_MOUNT_PATH/init"
chmod +x $TMP_MOUNT_PATH/init
for F in "$FUNCTIONS_D"/* ; do
cp "$F" "$TMP_MOUNT_PATH"
done
# Append /init with any element fragments that are present
TARGET_DIR="/tmp/in_target.d/"
for _ELEMENT in $(ls $TARGET_DIR/init.d/) ; do
_FILE="${TARGET_DIR}/init.d/${_ELEMENT}"
if [ -a $_FILE ]; then
cat >>$TMP_MOUNT_PATH/init <<EOF
# init fragment from ${_ELEMENT}
EOF
cat <$_FILE >>$TMP_MOUNT_PATH/init
fi
done
# Add our final steps to /init
cat <${INIT}-end >>$TMP_MOUNT_PATH/init
}
function finalise_image () {
echo "Finalising image"
(cd "$TMP_MOUNT_PATH"; find . | cpio -o -H newc | gzip > "$TMP_IMAGE_PATH" )
}
function populate_udev () {
echo "Installing udev rules"
TARGET_DIR="/tmp/in_target.d/"
for _ELEMENT in $(ls $TARGET_DIR/udev.d/) ; do
_FILE="${TARGET_DIR}/udev.d/${_ELEMENT}"
if [ -a $_FILE ]; then
cp ${_FILE} $TMP_MOUNT_PATH/lib/udev/rules.d/
fi
done
}
function find_kernel_version () {
_TMP=$(ls /boot/vmlinu* | sort | tail -1)
if [ "$_TMP" == "" ]; then
echo "Unable to find a suitable kernel" >>/dev/stderr
exit 1
fi
echo ${_TMP##/boot/vmlinu[zx]-}
}
|