You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

144 lines
5.0 KiB

#!/bin/bash
# called by dracut
check() {
return 0
}
# called by dracut
depends() {
echo udev-rules
return 0
}
# called by dracut
install() {
inst_multiple mount mknod mkdir sleep chroot chown \
Allow running on a cross-compiled rootfs For the shell scripts, new environment variables were introduced. dracutsysrootdir is the root directory, file existence checks use it. DRACUT_LDCONFIG can override ldconfig with a different one that works on the sysroot with foreign binaries. DRACUT_LDD can override ldd with a different one that works with foreign binaries. DRACUT_TESTBIN can override /bin/sh. A cross-compiled sysroot may use symlinks that are valid only when running on the target so a real file must be provided that exist in the sysroot. DRACUT_INSTALL now supports debugging dracut-install in itself when run by dracut but without debugging the dracut scripts. E.g. DRACUT_INSTALL="valgrind dracut-install or DRACUT_INSTALL="dracut-install --debug". DRACUT_COMPRESS_BZIP2, DRACUT_COMPRESS_LBZIP2, DRACUT_COMPRESS_LZMA, DRACUT_COMPRESS_XZ, DRACUT_COMPRESS_GZIP, DRACUT_COMPRESS_PIGZ, DRACUT_COMPRESS_LZOP, DRACUT_COMPRESS_ZSTD, DRACUT_COMPRESS_LZ4, DRACUT_COMPRESS_CAT: All of the compression utilities may be overridden, to support the native binaries in non-standard places. DRACUT_ARCH overrides "uname -m". SYSTEMD_VERSION overrides "systemd --version". The dracut-install utility was overhauled to support sysroot via a new option -r and fixes for clang-analyze. It supports cross-compiler-ldd from https://gist.github.com/jerome-pouiller/c403786c1394f53f44a3b61214489e6f DRACUT_INSTALL_PATH was introduced so dracut-install can work with a different PATH. In a cross-compiled environment (e.g. Yocto), PATH points to natively built binaries that are not in the host's /bin, /usr/bin, etc. dracut-install still needs plain /bin and /usr/bin that are relative to the cross-compiled sysroot. The hashmap pool allocate_tile/deallocate_tile code was removed because clang-analyze showed errors in it. hashmap_copy was removed because it wasn't used and clang-analyze showed errors in it. DRACUT_INSTALL_LOG_TARGET and DRACUT_INSTALL_LOG_LEVEL were introduced so dracut-install can use different settings from DRACUT_LOG_TARGET and DRACUT_LOG_LEVEL. Signed-off-by: Böszörményi Zoltán <zboszor@pr.hu>
5 years ago
sed ls flock cp mv dmesg rm ln rmmod mkfifo umount readlink setsid \
modprobe
inst_multiple -o findmnt less kmod dracut-getargs
inst_binary "${dracutsysrootdir}${dracutbasedir}/dracut-util" "/usr/bin/dracut-util"
ln -s dracut-util "${initdir}/usr/bin/dracut-getarg"
ln -s dracut-util "${initdir}/usr/bin/dracut-getargs"
if [ ! -e "${initdir}/bin/sh" ]; then
inst_multiple bash
(ln -s bash "${initdir}/bin/sh" || :)
fi
# add common users in /etc/passwd, it will be used by nfs/ssh currently
# use password for hostonly images to facilitate secure sulogin in emergency console
[[ $hostonly ]] && pwshadow='x'
grep '^root:' "$initdir/etc/passwd" 2>/dev/null || echo "root:$pwshadow:0:0::/root:/bin/sh" >> "$initdir/etc/passwd"
grep '^nobody:' "$dracutsysrootdir"/etc/passwd >> "$initdir/etc/passwd"
[[ $hostonly ]] && grep '^root:' "$dracutsysrootdir"/etc/shadow >> "$initdir/etc/shadow"
# install our scripts and hooks
inst_script "$moddir/init.sh" "/init"
inst_script "$moddir/initqueue.sh" "/sbin/initqueue"
inst_script "$moddir/loginit.sh" "/sbin/loginit"
inst_script "$moddir/rdsosreport.sh" "/sbin/rdsosreport"
[ -e "${initdir}/lib" ] || mkdir -m 0755 -p "${initdir}"/lib
mkdir -m 0755 -p "${initdir}"/lib/dracut
mkdir -m 0755 -p "${initdir}"/lib/dracut/hooks
mkdir -p "${initdir}"/tmp
inst_simple "$moddir/dracut-lib.sh" "/lib/dracut-lib.sh"
mkdir -p "${initdir}"/var
if ! dracut_module_included "systemd"; then
inst_multiple switch_root || dfatal "Failed to install switch_root"
inst_hook cmdline 10 "$moddir/parse-root-opts.sh"
inst_multiple -o $systemdutildir/systemd-timestamp
fi
if [[ $realinitpath ]]; then
for i in $realinitpath; do
echo "rd.distroinit=$i"
done > "${initdir}/etc/cmdline.d/distroinit.conf"
fi
ln -fs /proc/self/mounts "$initdir/etc/mtab"
if [[ $ro_mnt = yes ]]; then
echo ro >> "${initdir}/etc/cmdline.d/base.conf"
fi
[ -e "${initdir}/usr/lib" ] || mkdir -m 0755 -p ${initdir}/usr/lib
local VERSION=""
local PRETTY_NAME=""
# Derive an os-release file from the host, if it exists
if [[ -e $dracutsysrootdir/etc/os-release ]]; then
. "$dracutsysrootdir"/etc/os-release
grep -hE -ve '^VERSION=' -ve '^PRETTY_NAME' "$dracutsysrootdir"/etc/os-release >"${initdir}"/usr/lib/initrd-release
[[ -n ${VERSION} ]] && VERSION+=" "
[[ -n ${PRETTY_NAME} ]] && PRETTY_NAME+=" "
else
# Fall back to synthesizing one, since dracut is presently used
# on non-systemd systems as well.
{
echo NAME=dracut
echo ID=dracut
echo VERSION_ID=\"$DRACUT_VERSION\"
echo ANSI_COLOR='"0;34"'
} >${initdir}/usr/lib/initrd-release
fi
VERSION+="dracut-$DRACUT_VERSION"
PRETTY_NAME+="dracut-$DRACUT_VERSION (Initramfs)"
{
echo VERSION=\"$VERSION\"
echo PRETTY_NAME=\"$PRETTY_NAME\"
# This addition is relatively new, intended to allow software
# to easily detect the dracut version if need be without
# having it mixed in with the real underlying OS version.
echo DRACUT_VERSION=\"${DRACUT_VERSION}\"
} >> "$initdir"/usr/lib/initrd-release
echo "dracut-$DRACUT_VERSION" > "$initdir/lib/dracut/dracut-$DRACUT_VERSION"
ln -sf ../usr/lib/initrd-release $initdir/etc/initrd-release
ln -sf initrd-release $initdir/usr/lib/os-release
ln -sf initrd-release $initdir/etc/os-release
## save host_devs which we need bring up
if [[ $hostonly_cmdline == "yes" ]]; then
if [[ -n "${host_devs[*]}" ]]; then
dracut_need_initqueue
fi
if [[ -f $initdir/lib/dracut/need-initqueue ]] || ! dracut_module_included "systemd"; then
(
if dracut_module_included "systemd"; then
DRACUT_SYSTEMD=1
fi
PREFIX="$initdir"
. "$moddir/dracut-lib.sh"
for _dev in "${host_devs[@]}"; do
for _dev2 in "${root_devs[@]}"; do
[[ "$_dev" == "$_dev2" ]] && continue 2
done
# We only actually wait for real devs - swap is only needed
# for resume and udev rules generated when parsing resume=
# argument take care of the waiting for us
for _dev2 in "${swap_devs[@]}"; do
[[ "$_dev" == "$_dev2" ]] && continue 2
done
_pdev=$(get_persistent_dev $_dev)
case "$_pdev" in
/dev/?*) wait_for_dev $_pdev;;
*) ;;
esac
done
)
fi
fi
}