initrd.scripts: move more functions to initrd.d/

master
Fabio Erculiani 12 years ago
parent 90983b4fd2
commit e4742ab0b5

@ -0,0 +1,42 @@
#!/bin/sh
is_livecd() {
[ "${CDROOT}" = "1" ] && return 0
return 1
}
is_nfs() {
[ "${REAL_ROOT}" = "/dev/nfs" ] && return 0
return 1
}
is_aufs() {
[ "${USE_AUFS}" = "1" ] && return 0
return 1
}
good_msg() {
[ -n "${QUIET}" ] && [ -z "${DEBUG}" ] && return 0
msg_string=$1
msg_string="${msg_string:-...}"
[ "$2" != 1 ] && \
echo -e "${GOOD}>>${NORMAL}${BOLD} ${msg_string} ${NORMAL}"
}
warn_msg() {
msg_string=$1
msg_string="${msg_string:-...}"
[ "$2" != 1 ] && \
echo -e "${WARN}**${NORMAL}${BOLD} ${msg_string} ${NORMAL}"
}
bad_msg() {
msg_string=$1
msg_string="${msg_string:-...}"
if [ "$2" != 1 ]; then
# TODO(lxnay): fix circular dep with 00-splash.sh
splashcmd verbose
echo -e "${BAD}!!${NORMAL}${BOLD} ${msg_string} ${NORMAL}"
fi
}

@ -0,0 +1,44 @@
#!/bin/sh
. /etc/initrd.d/00-common.sh
is_udev() {
[ -x "${UDEVD}" ] && [ -z "${USE_MDEV}" ] && return 0
return 1
}
is_mdev() {
if [ ! -x "${UDEVD}" ] || [ -n "${USE_MDEV}" ]; then
return 0
fi
return 1
}
devmgr_init() {
if is_udev; then
good_msg "Activating udev"
echo "${UDEVD}" > /proc/sys/kernel/hotplug
echo "" > /sys/kernel/uevent_helper
"${UDEVD}" --daemon --resolve-names=never && \
udevadm trigger --action=add && \
udevadm settle || bad_msg "udevd failed to run"
elif is_mdev; then
good_msg "Activating mdev"
# Serialize hotplug events
touch /dev/mdev.seq
echo "${MDEVD}" > /proc/sys/kernel/hotplug
# Ensure that device nodes are properly configured
"${MDEVD}" -s || bad_msg "mdev -s failed"
else
bad_msg "Cannot find either udev or mdev"
fi
}
# Terminate the device manager, this happens right before pivot_root
devmgr_terminate() {
if is_udev; then
udevadm settle
udevadm control --exit || bad_msg "Unable to terminate udevd"
fi
# mdev doesn't require anything, it seems
}

@ -1,9 +1,13 @@
#!/bin/sh #!/bin/sh
. /etc/initrd.d/00-common.sh
. /etc/initrd.d/00-devmgr.sh
splash() { splash() {
return 0 return 0
} }
# this redefines splash()
[ -e "${INITRD_SPLASH}" ] && . "${INITRD_SPLASH}" [ -e "${INITRD_SPLASH}" ] && . "${INITRD_SPLASH}"
is_fbsplash() { is_fbsplash() {
@ -29,6 +33,14 @@ is_plymouth_started() {
return 1 return 1
} }
splash_init() {
if is_udev; then
# if udev, we can load the splash earlier
# In the plymouth case, udev will load KMS automatically
splashcmd init
fi
}
splashcmd() { splashcmd() {
# plymouth support # plymouth support
local cmd="${1}" local cmd="${1}"
@ -37,32 +49,32 @@ splashcmd() {
case "${cmd}" in case "${cmd}" in
init) init)
is_fbsplash && splash init is_fbsplash && splash init
is_plymouth && plymouth_init is_plymouth && _plymouth_init
;; ;;
verbose) verbose)
is_fbsplash && splash verbose is_fbsplash && splash verbose
plymouth_hide _plymouth_hide
;; ;;
quiet) quiet)
# no fbsplash support # no fbsplash support
plymouth_show _plymouth_show
;; ;;
set_msg) set_msg)
is_fbsplash && splash set_msg "${1}" is_fbsplash && splash set_msg "${1}"
plymouth_message "${1}" _plymouth_message "${1}"
;; ;;
hasroot) hasroot)
# no fbsplash support # no fbsplash support
plymouth_newroot "${1}" _plymouth_newroot "${1}"
;; ;;
esac esac
} }
plymouth_init() { _plymouth_init() {
good_msg "Enabling Plymouth" good_msg "Enabling Plymouth"
mkdir -p /run/plymouth || return 1 mkdir -p /run/plymouth || return 1
@ -83,34 +95,25 @@ plymouth_init() {
consoledev=${consoledev:-tty0} consoledev=${consoledev:-tty0}
"${PLYMOUTHD_BIN}" --attach-to-session --pid-file /run/plymouth/pid \ "${PLYMOUTHD_BIN}" --attach-to-session --pid-file /run/plymouth/pid \
|| { || {
bad_msg "Plymouth load error"; PLYMOUTH_FAILURE=1;
PLYMOUTH_FAILURE=1
return 1; return 1;
} }
plymouth_show _plymouth_show
good_msg "Plymouth enabled" good_msg "Plymouth enabled"
} }
plymouth_hide() { _plymouth_hide() {
is_plymouth_started && "${PLYMOUTH_BIN}" --hide-splash is_plymouth_started && "${PLYMOUTH_BIN}" --hide-splash
} }
plymouth_show() { _plymouth_show() {
is_plymouth_started && "${PLYMOUTH_BIN}" --show-splash is_plymouth_started && "${PLYMOUTH_BIN}" --show-splash
} }
plymouth_message() { _plymouth_message() {
is_plymouth_started && "${PLYMOUTH_BIN}" --update="${1}" is_plymouth_started && "${PLYMOUTH_BIN}" --update="${1}"
} }
plymouth_newroot() { _plymouth_newroot() {
is_plymouth_started && "${PLYMOUTH_BIN}" --newroot="${1}" is_plymouth_started && "${PLYMOUTH_BIN}" --newroot="${1}"
} }
splash_init() {
if is_udev; then
# if udev, we can load the splash earlier
# In the plymouth case, udev will load KMS automatically
splashcmd init
fi
}

@ -2,6 +2,8 @@
. /etc/initrd.defaults . /etc/initrd.defaults
. /etc/initrd.d/00-splash.sh . /etc/initrd.d/00-splash.sh
. /etc/initrd.d/00-devmgr.sh
. /etc/initrd.d/00-common.sh
call_func_timeout() { call_func_timeout() {
@ -93,22 +95,7 @@ modules_init() {
uppercase() { uppercase() {
# needs tr on busybox # needs tr on busybox
echo $1 | tr 'a-z' 'A-Z' echo ${1} | tr 'a-z' 'A-Z'
}
is_livecd() {
[ "${CDROOT}" = "1" ] && return 0
return 1
}
is_nfs() {
[ "${REAL_ROOT}" = "/dev/nfs" ] && return 0
return 1
}
is_aufs() {
[ "${USE_AUFS}" = "1" ] && return 0
return 1
} }
setup_real_root() { setup_real_root() {
@ -433,48 +420,6 @@ fs_type_in_use() {
cut -d " " -f 3 < /proc/mounts | fgrep -q "${fs_type}" cut -d " " -f 3 < /proc/mounts | fgrep -q "${fs_type}"
} }
is_udev() {
[ -x "${UDEVD}" ] && [ -z "${USE_MDEV}" ] && return 0
return 1
}
is_mdev() {
if [ ! -x "${UDEVD}" ] || [ -n "${USE_MDEV}" ]
then
return 0
fi
return 1
}
devmgr_init() {
if is_udev; then
good_msg 'Activating udev'
echo "${UDEVD}" > /proc/sys/kernel/hotplug
echo "" > /sys/kernel/uevent_helper
"${UDEVD}" --daemon --resolve-names=never && \
udevadm trigger --action=add && \
udevadm settle || bad_msg "udevd failed to run"
elif is_mdev; then
good_msg 'Activating mdev'
# Serialize hotplug events
touch /dev/mdev.seq
echo "${MDEVD}" > /proc/sys/kernel/hotplug
# Ensure that device nodes are properly configured
"${MDEVD}" -s || bad_msg "mdev -s failed"
else
bad_msg "Cannot find either udev or mdev"
fi
}
# Terminate the device manager, this happens right before pivot_root
devmgr_terminate() {
if is_udev; then
udevadm settle
udevadm control --exit || bad_msg "Unable to terminate udevd"
fi
# mdev doesn't require anything, it seems
}
mount_devfs () { mount_devfs () {
# Use devtmpfs if enabled in kernel, # Use devtmpfs if enabled in kernel,
# else tmpfs. Always run mdev just in case # else tmpfs. Always run mdev just in case
@ -511,34 +456,6 @@ test_success() {
} }
# msg functions arguments
# $1 string
# $2 hide flag
good_msg() {
[ -n "${QUIET}" ] && [ -z "${DEBUG}" ] && return 0
msg_string=$1
msg_string="${msg_string:-...}"
[ "$2" != 1 ] && echo -e "${GOOD}>>${NORMAL}${BOLD} ${msg_string} ${NORMAL}"
}
bad_msg() {
msg_string=$1
msg_string="${msg_string:-...}"
if [ "$2" != 1 ]
then
splashcmd verbose
echo -e "${BAD}!!${NORMAL}${BOLD} ${msg_string} ${NORMAL}"
fi
}
warn_msg() {
msg_string=$1
msg_string="${msg_string:-...}"
[ "$2" != 1 ] && echo -e "${WARN}**${NORMAL}${BOLD} ${msg_string} ${NORMAL}"
}
# Courtesy of dracut. Licensed under GPL-2. # Courtesy of dracut. Licensed under GPL-2.
# Taken from: dracut/modules.d/90crypt/crypt-lib.sh # Taken from: dracut/modules.d/90crypt/crypt-lib.sh
# ask_for_password # ask_for_password

Loading…
Cancel
Save